9 func TestStrSliceMarshalJSON(t *testing.T) {
10 for _, testcase := range []struct {
14 // MADNESS(stevvooe): No clue why nil would be "" but empty would be
15 // "null". Had to make a change here that may affect compatibility.
16 {input: nil, expected: "null"},
18 {StrSlice{"/bin/sh", "-c", "echo"}, `["/bin/sh","-c","echo"]`},
20 data, err := json.Marshal(testcase.input)
24 if string(data) != testcase.expected {
25 t.Fatalf("%#v: expected %v, got %v", testcase.input, testcase.expected, string(data))
30 func TestStrSliceUnmarshalJSON(t *testing.T) {
31 parts := map[string][]string{
32 "": {"default", "values"},
34 `["/bin/sh","-c","echo"]`: {"/bin/sh", "-c", "echo"},
36 for json, expectedParts := range parts {
37 strs := StrSlice{"default", "values"}
38 if err := strs.UnmarshalJSON([]byte(json)); err != nil {
42 actualParts := []string(strs)
43 if !reflect.DeepEqual(actualParts, expectedParts) {
44 t.Fatalf("%#v: expected %v, got %v", json, expectedParts, actualParts)
50 func TestStrSliceUnmarshalString(t *testing.T) {
52 echo, err := json.Marshal("echo")
56 if err := json.Unmarshal(echo, &e); err != nil {
61 t.Fatalf("expected 1 element after unmarshal: %q", e)
65 t.Fatalf("expected `echo`, got: %q", e[0])
69 func TestStrSliceUnmarshalSlice(t *testing.T) {
71 echo, err := json.Marshal([]string{"echo"})
75 if err := json.Unmarshal(echo, &e); err != nil {
80 t.Fatalf("expected 1 element after unmarshal: %q", e)
84 t.Fatalf("expected `echo`, got: %q", e[0])