MCPcopy
hub / github.com/minio/minio-go / TestStringSetUnmarshalJSON

Function TestStringSetUnmarshalJSON

pkg/set/stringset_test.go:283–305  ·  view source on GitHub ↗

StringSet.UnmarshalJSON() is called with series of cases for valid and erroneous inputs and the result is validated.

(t *testing.T)

Source from the content-addressed store, hash-verified

281
282// StringSet.UnmarshalJSON() is called with series of cases for valid and erroneous inputs and the result is validated.
283func TestStringSetUnmarshalJSON(t *testing.T) {
284 testCases := []struct {
285 data []byte
286 expectedResult string
287 }{
288 // Test to convert JSON array to set.
289 {[]byte(`["bar","foo"]`), `[bar foo]`},
290 // Test to convert JSON string to set.
291 {[]byte(`"bar"`), `[bar]`},
292 // Test to convert JSON empty array to set.
293 {[]byte(`[]`), `[]`},
294 // Test to convert JSON empty string to set.
295 {[]byte(`""`), `[]`},
296 }
297
298 for _, testCase := range testCases {
299 var set StringSet
300 set.UnmarshalJSON(testCase.data)
301 if result := set.String(); result != testCase.expectedResult {
302 t.Fatalf("expected: %s, got: %s", testCase.expectedResult, result)
303 }
304 }
305}
306
307// StringSet.String() is called with series of cases for valid and erroneous inputs and the result is validated.
308func TestStringSetString(t *testing.T) {

Callers

nothing calls this directly

Calls 2

UnmarshalJSONMethod · 0.95
StringMethod · 0.95

Tested by

no test coverage detected