-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathstrings_test.go
More file actions
68 lines (64 loc) · 1.41 KB
/
strings_test.go
File metadata and controls
68 lines (64 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package utils
import (
"testing"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
)
func TestTruncate(t *testing.T) {
type args struct {
s *string
maxLen int
}
tests := []struct {
name string
args args
want string
}{
{"nil string", args{nil, 3}, ""},
{"empty string", args{utils.Ptr(""), 10}, ""},
{"length below maxlength", args{utils.Ptr("foo"), 10}, "foo"},
{"exactly maxlength", args{utils.Ptr("foo"), 3}, "foo"},
{"above maxlength", args{utils.Ptr("foobarbaz"), 3}, "foo…"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Truncate(tt.args.s, tt.args.maxLen); got != tt.want {
t.Errorf("Truncate() = %v, want %v", got, tt.want)
}
})
}
}
func TestJoinStringMap(t *testing.T) {
tests := []struct {
name string
input map[string]string
want string
}{
{
name: "nil map",
input: nil,
want: "",
},
{
name: "empty map",
input: map[string]string{},
want: "",
},
{
name: "single element",
input: map[string]string{"key1": "value1"},
want: "key1=value1",
},
{
name: "multiple elements",
input: map[string]string{"key1": "value1", "key2": "value2"},
want: "key1=value1, key2=value2",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := JoinStringMap(tt.input, "=", ", "); got != tt.want {
t.Errorf("JoinStringMap() = %v, want %v", got, tt.want)
}
})
}
}