(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestIsValidTemplateParameterOption(t *testing.T) { |
| 12 | t.Parallel() |
| 13 | |
| 14 | options := []codersdk.TemplateVersionParameterOption{ |
| 15 | {Name: "Vim", Value: "vim"}, |
| 16 | {Name: "Emacs", Value: "emacs"}, |
| 17 | {Name: "VS Code", Value: "vscode"}, |
| 18 | } |
| 19 | |
| 20 | t.Run("SingleSelectValid", func(t *testing.T) { |
| 21 | t.Parallel() |
| 22 | bp := codersdk.WorkspaceBuildParameter{Name: "editor", Value: "vim"} |
| 23 | tvp := codersdk.TemplateVersionParameter{ |
| 24 | Name: "editor", |
| 25 | Type: "string", |
| 26 | Options: options, |
| 27 | } |
| 28 | assert.True(t, isValidTemplateParameterOption(bp, tvp)) |
| 29 | }) |
| 30 | |
| 31 | t.Run("SingleSelectInvalid", func(t *testing.T) { |
| 32 | t.Parallel() |
| 33 | bp := codersdk.WorkspaceBuildParameter{Name: "editor", Value: "notepad"} |
| 34 | tvp := codersdk.TemplateVersionParameter{ |
| 35 | Name: "editor", |
| 36 | Type: "string", |
| 37 | Options: options, |
| 38 | } |
| 39 | assert.False(t, isValidTemplateParameterOption(bp, tvp)) |
| 40 | }) |
| 41 | |
| 42 | t.Run("MultiSelectAllValid", func(t *testing.T) { |
| 43 | t.Parallel() |
| 44 | bp := codersdk.WorkspaceBuildParameter{Name: "editors", Value: `["vim","emacs"]`} |
| 45 | tvp := codersdk.TemplateVersionParameter{ |
| 46 | Name: "editors", |
| 47 | Type: "list(string)", |
| 48 | Options: options, |
| 49 | } |
| 50 | assert.True(t, isValidTemplateParameterOption(bp, tvp)) |
| 51 | }) |
| 52 | |
| 53 | t.Run("MultiSelectOneInvalid", func(t *testing.T) { |
| 54 | t.Parallel() |
| 55 | bp := codersdk.WorkspaceBuildParameter{Name: "editors", Value: `["vim","notepad"]`} |
| 56 | tvp := codersdk.TemplateVersionParameter{ |
| 57 | Name: "editors", |
| 58 | Type: "list(string)", |
| 59 | Options: options, |
| 60 | } |
| 61 | assert.False(t, isValidTemplateParameterOption(bp, tvp)) |
| 62 | }) |
| 63 | |
| 64 | t.Run("MultiSelectEmptyArray", func(t *testing.T) { |
| 65 | t.Parallel() |
| 66 | bp := codersdk.WorkspaceBuildParameter{Name: "editors", Value: `[]`} |
| 67 | tvp := codersdk.TemplateVersionParameter{ |
| 68 | Name: "editors", |
nothing calls this directly
no test coverage detected