-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
executable file
路164 lines (161 loc) 路 3.9 KB
/
Copy pathclient_test.go
File metadata and controls
executable file
路164 lines (161 loc) 路 3.9 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package paramstore
import (
"context"
"log/slog"
"os"
"strings"
"testing"
)
var (
// test logger.
logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
if a.Key == slog.TimeKey {
a.Value = slog.StringValue(a.Value.Time().Format("2006-01-02 15:04:05"))
}
return a
},
}))
)
func Test_New(t *testing.T) {
tests := map[string]struct {
options []Option
want *Client
err string
}{
"default": {
want: &Client{
awsRegion: "ap-southeast-2",
batchSize: 10,
withDecryption: false,
logger: slog.Default(),
},
},
"with log level (debug)": {
options: []Option{WithLogLevel(slog.LevelDebug)},
want: &Client{
awsRegion: "ap-southeast-2",
batchSize: 10,
withDecryption: false,
logger: slog.Default(),
logLevel: -4,
},
},
"with log level (info)": {
options: []Option{WithLogLevel(slog.LevelInfo)},
want: &Client{
awsRegion: "ap-southeast-2",
batchSize: 10,
withDecryption: false,
logger: slog.Default(),
logLevel: 0,
},
},
"with log level (warn)": {
options: []Option{WithLogLevel(slog.LevelWarn)},
want: &Client{
awsRegion: "ap-southeast-2",
batchSize: 10,
withDecryption: false,
logger: slog.Default(),
logLevel: 4,
},
},
"with log level (error)": {
options: []Option{WithLogLevel(slog.LevelError)},
want: &Client{
awsRegion: "ap-southeast-2",
batchSize: 10,
withDecryption: false,
logger: slog.Default(),
logLevel: 8,
},
},
"with logger": {
options: []Option{WithLogger(logger)},
want: &Client{
awsRegion: "ap-southeast-2",
batchSize: 10,
withDecryption: false,
logger: logger,
},
},
"with aws region": {
options: []Option{WithAWSRegion("us-east-1")},
want: &Client{
awsRegion: "us-east-1",
batchSize: 10,
withDecryption: false,
logger: slog.Default(),
},
},
"with batch size (n > min && n < max)": {
options: []Option{WithBatchSize(5)},
want: &Client{
awsRegion: "ap-southeast-2",
batchSize: 5,
withDecryption: false,
logger: slog.Default(),
},
},
"with batch size (n < min)": {
options: []Option{WithBatchSize(0)},
want: &Client{
awsRegion: "ap-southeast-2",
batchSize: 5,
withDecryption: false,
logger: slog.Default(),
},
err: "batchSize must be greater than 0",
},
"with batch size (n > max)": {
options: []Option{WithBatchSize(11)},
want: &Client{
awsRegion: "ap-southeast-2",
batchSize: 5,
withDecryption: false,
logger: slog.Default(),
},
err: "batchSize must be less than or equal to 10",
},
"with decryption": {
options: []Option{WithDecryption(true)},
want: &Client{
awsRegion: "ap-southeast-2",
batchSize: 10,
withDecryption: true,
logger: slog.Default(),
},
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
got, err := New(context.Background(), tt.options...)
if tt.err != "" && err != nil {
if !strings.Contains(err.Error(), tt.err) {
t.Errorf("New() returned an unexpected error; want=%v, got=%v", tt.err, err)
}
return
}
if err != nil {
t.Errorf("New() returned an error; error=%v", err)
return
}
switch {
case
got.logLevel != tt.want.logLevel,
(got.logger != slog.Default() && tt.want.logger != slog.Default()) && got.logger != tt.want.logger,
got.awsRegion != tt.want.awsRegion,
got.withDecryption != tt.want.withDecryption,
got.batchSize != tt.want.batchSize:
t.Errorf(
"New() returned unexpected configuration; want=%+v, got=%+v\n",
tt.want,
got,
)
return
}
})
}
}