(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestUnmarshal(t *testing.T) { |
| 11 | t.Parallel() |
| 12 | |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | in string |
| 16 | want LifecycleScript |
| 17 | }{ |
| 18 | { |
| 19 | name: "command string", |
| 20 | in: `"echo hello"`, |
| 21 | want: LifecycleScript{ |
| 22 | shellCommands: map[string]string{ |
| 23 | "echo hello": "echo hello", |
| 24 | }, |
| 25 | }, |
| 26 | }, |
| 27 | { |
| 28 | name: "command array", |
| 29 | in: `["echo", "hello"]`, |
| 30 | want: LifecycleScript{ |
| 31 | nonShellCommands: map[string][]string{ |
| 32 | "echo hello": {"echo", "hello"}, |
| 33 | }, |
| 34 | }, |
| 35 | }, |
| 36 | { |
| 37 | name: "command map", |
| 38 | in: `{"script 1": ["echo", "hello"], "script 2": ["echo", "world"], "script 3": "echo hello world"}`, |
| 39 | want: LifecycleScript{ |
| 40 | shellCommands: map[string]string{ |
| 41 | "script 3": "echo hello world", |
| 42 | }, |
| 43 | nonShellCommands: map[string][]string{ |
| 44 | "script 1": {"echo", "hello"}, |
| 45 | "script 2": {"echo", "world"}, |
| 46 | }, |
| 47 | }, |
| 48 | }, |
| 49 | } |
| 50 | |
| 51 | for _, tt := range tests { |
| 52 | t.Run(tt.name, func(t *testing.T) { |
| 53 | var got LifecycleScript |
| 54 | if err := json.Unmarshal([]byte(tt.in), &got); err != nil { |
| 55 | t.Fatal(err) |
| 56 | } |
| 57 | require.Equal(t, tt.want, got) |
| 58 | }) |
| 59 | } |
| 60 | } |
nothing calls this directly
no outgoing calls
no test coverage detected