Repository navigation
Expand file tree
/
Copy pathcreate_internal_test.go
More file actions
67 lines (59 loc) · 2.01 KB
/
Copy pathcreate_internal_test.go
File metadata and controls
67 lines (59 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cli
import (
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/coder/coder/v2/codersdk"
)
func TestPresetSelectOptions(t *testing.T) {
t.Parallel()
eu := codersdk.Preset{ID: uuid.New(), Name: "eu", Description: "Deploys to EU"}
us := codersdk.Preset{ID: uuid.New(), Name: "us"}
namedNone := codersdk.Preset{ID: uuid.New(), Name: "None"}
namedNoneWithDescription := codersdk.Preset{ID: uuid.New(), Name: "None", Description: "Minimal"}
tests := []struct {
name string
presets []codersdk.Preset
wantOptions []string
wantNone string
wantPresets map[string]uuid.UUID
}{
{
name: "NoneFirst",
presets: []codersdk.Preset{eu, us},
wantOptions: []string{"None", "eu: Deploys to EU", "us"},
wantNone: "None",
wantPresets: map[string]uuid.UUID{"eu: Deploys to EU": eu.ID, "us": us.ID},
},
{
// A preset whose label is "None" must stay selectable, so the
// option for applying no preset gets a distinct label.
name: "PresetNamedNone",
presets: []codersdk.Preset{namedNone, us},
wantOptions: []string{"None (no preset)", "None", "us"},
wantNone: "None (no preset)",
wantPresets: map[string]uuid.UUID{"None": namedNone.ID, "us": us.ID},
},
{
name: "PresetNamedNoneWithDescription",
presets: []codersdk.Preset{namedNoneWithDescription},
wantOptions: []string{"None", "None: Minimal"},
wantNone: "None",
wantPresets: map[string]uuid.UUID{"None: Minimal": namedNoneWithDescription.ID},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
options, noneOption, presetMap := presetSelectOptions(tt.presets)
require.Equal(t, tt.wantOptions, options)
require.Equal(t, tt.wantNone, noneOption)
require.NotContains(t, presetMap, noneOption)
require.Len(t, presetMap, len(tt.wantPresets))
for option, id := range tt.wantPresets {
require.Contains(t, presetMap, option)
require.Equal(t, id, presetMap[option].ID)
}
})
}
}