Skip to content

Commit 9f8b1f5

Browse files
committed
add nolint and utils test
1 parent e8bbd09 commit 9f8b1f5

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

internal/pkg/utils/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ func UserAgentConfigOption(cliVersion string) sdkConfig.ConfigurationOption {
132132

133133
// ConvertStringMapToInterfaceMap converts a map[string]string to a pointer to map[string]interface{}.
134134
// Returns nil if the input map is empty.
135+
//
136+
//nolint:gocritic
135137
func ConvertStringMapToInterfaceMap(m *map[string]string) *map[string]interface{} {
136-
//nolint:gocritic
137138
if m == nil || len(*m) == 0 {
138139
return nil
139140
}

internal/pkg/utils/utils_test.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,102 @@ func TestUserAgentConfigOption(t *testing.T) {
149149
})
150150
}
151151
}
152+
153+
func TestConvertStringMapToInterfaceMap(t *testing.T) {
154+
tests := []struct {
155+
name string
156+
input *map[string]string
157+
expected *map[string]interface{}
158+
}{
159+
{
160+
name: "nil input",
161+
input: nil,
162+
expected: nil,
163+
},
164+
{
165+
name: "empty map",
166+
input: &map[string]string{},
167+
expected: nil,
168+
},
169+
{
170+
name: "single key-value pair",
171+
input: &map[string]string{
172+
"key1": "value1",
173+
},
174+
expected: &map[string]interface{}{
175+
"key1": "value1",
176+
},
177+
},
178+
{
179+
name: "multiple key-value pairs",
180+
input: &map[string]string{
181+
"key1": "value1",
182+
"key2": "value2",
183+
"key3": "value3",
184+
},
185+
expected: &map[string]interface{}{
186+
"key1": "value1",
187+
"key2": "value2",
188+
"key3": "value3",
189+
},
190+
},
191+
{
192+
name: "special characters in values",
193+
input: &map[string]string{
194+
"key1": "value with spaces",
195+
"key2": "value,with,commas",
196+
"key3": "value\nwith\nnewlines",
197+
},
198+
expected: &map[string]interface{}{
199+
"key1": "value with spaces",
200+
"key2": "value,with,commas",
201+
"key3": "value\nwith\nnewlines",
202+
},
203+
},
204+
{
205+
name: "empty values",
206+
input: &map[string]string{
207+
"key1": "",
208+
"key2": "value2",
209+
},
210+
expected: &map[string]interface{}{
211+
"key1": "",
212+
"key2": "value2",
213+
},
214+
},
215+
}
216+
217+
for _, tt := range tests {
218+
t.Run(tt.name, func(t *testing.T) {
219+
result := ConvertStringMapToInterfaceMap(tt.input)
220+
221+
// Check if both are nil
222+
if result == nil && tt.expected == nil {
223+
return
224+
}
225+
226+
// Check if one is nil and other isn't
227+
if (result == nil && tt.expected != nil) || (result != nil && tt.expected == nil) {
228+
t.Errorf("ConvertStringMapToInterfaceMap() = %v, want %v", result, tt.expected)
229+
return
230+
}
231+
232+
// Compare maps
233+
if len(*result) != len(*tt.expected) {
234+
t.Errorf("ConvertStringMapToInterfaceMap() map length = %d, want %d", len(*result), len(*tt.expected))
235+
return
236+
}
237+
238+
for k, v := range *result {
239+
expectedVal, ok := (*tt.expected)[k]
240+
if !ok {
241+
t.Errorf("ConvertStringMapToInterfaceMap() unexpected key %s in result", k)
242+
continue
243+
}
244+
if v != expectedVal {
245+
t.Errorf("ConvertStringMapToInterfaceMap() value for key %s = %v, want %v", k, v, expectedVal)
246+
}
247+
}
248+
})
249+
}
250+
}

0 commit comments

Comments
 (0)