1 package asker
2
3 import (
4 "testing"
5
6 "github.com/google/go-cmp/cmp"
7 )
8
9 func Test_buildPersonalizedConfigurationOptions(t *testing.T) {
10 type args struct {
11 configuration ContainerConfiguration
12 }
13 tests := []struct {
14 name string
15 args args
16 wantOptions []string
17 wantTracker []OperationOnContainer
18 }{
19 {
20 name: "default options",
21 args: args{configuration: ContainerConfiguration{
22 Ports: []string{},
23 Envs: map[string]string{},
24 }},
25 wantOptions: []string{
26 "NOTHING - configuration is correct",
27 "Add new port",
28 "Add new environment variable",
29 },
30 wantTracker: []OperationOnContainer{
31 {
32 Ops: "Nothing",
33 Kind: "",
34 Key: "",
35 }, {
36 Ops: "Add",
37 Kind: "Port",
38 Key: "",
39 }, {
40 Ops: "Add",
41 Kind: "EnvVar",
42 Key: "",
43 }},
44 },
45 {
46 name: "all options",
47 args: args{configuration: ContainerConfiguration{
48 Ports: []string{"7000", "8000"},
49 Envs: map[string]string{"foo": "bar"},
50 }},
51 wantOptions: []string{
52 "NOTHING - configuration is correct",
53 "Delete port \"7000\"",
54 "Delete port \"8000\"",
55 "Add new port",
56 "Delete environment variable \"foo\"",
57 "Add new environment variable",
58 },
59 wantTracker: []OperationOnContainer{
60 {
61 Ops: "Nothing",
62 Kind: "",
63 Key: "",
64 }, {
65 Ops: "Delete",
66 Kind: "Port",
67 Key: "7000",
68 }, {
69 Ops: "Delete",
70 Kind: "Port",
71 Key: "8000",
72 }, {
73 Ops: "Add",
74 Kind: "Port",
75 Key: "",
76 }, {
77 Ops: "Delete",
78 Kind: "EnvVar",
79 Key: "foo",
80 }, {
81 Ops: "Add",
82 Kind: "EnvVar",
83 Key: "",
84 }},
85 },
86 }
87 for _, tt := range tests {
88 t.Run(tt.name, func(t *testing.T) {
89 gotOptions, gotTracker := buildPersonalizedConfigurationOptions(tt.args.configuration)
90
91 if diff := cmp.Diff(tt.wantOptions, gotOptions); diff != "" {
92 t.Errorf("buildPersonalizedConfigurationOptions() wantOptions mismatch (-want +got):\n%s", diff)
93 }
94 if diff := cmp.Diff(tt.wantTracker, gotTracker); diff != "" {
95 t.Errorf("buildPersonalizedConfigurationOptions() wantTracker mismatch (-want +got):\n%s", diff)
96 }
97 })
98 }
99 }
100
View as plain text