-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy_strategies_test.go
102 lines (90 loc) · 1.92 KB
/
deploy_strategies_test.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package guvnor
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
func TestDeploymentStrategy_String(t *testing.T) {
tests := []struct {
strategy DeploymentStrategy
want string
}{
{
strategy: DefaultStrategy,
want: "default",
},
{
strategy: ReplaceStrategy,
want: "replace",
},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
got := tt.strategy.String()
assert.Equal(t, tt.want, got)
})
}
}
func TestDeploymentStrategy_MarshalYAML(t *testing.T) {
type testStruct struct {
DeploymentStrategy DeploymentStrategy `yaml:"deploymentStrategy"`
}
tests := []struct {
name string
toMarshal testStruct
want string
}{
{
name: "standard",
toMarshal: testStruct{
DeploymentStrategy: ReplaceStrategy,
},
want: "deploymentStrategy: replace\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := yaml.Marshal(tt.toMarshal)
require.NoError(t, err)
assert.Equal(t, tt.want, string(got))
})
}
}
func TestDeploymentStrategy_UnmarshalYAML(t *testing.T) {
type testStruct struct {
DeploymentStrategy DeploymentStrategy `yaml:"deploymentStrategy"`
}
tests := []struct {
name string
data string
want testStruct
wantErr string
}{
{
name: "success",
data: "deploymentStrategy: replace\n",
want: testStruct{
DeploymentStrategy: ReplaceStrategy,
},
},
{
name: "unknown type",
data: "deploymentStrategy: buzzcock\n",
want: testStruct{},
wantErr: "deployment strategy 'buzzcock' not recognised",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := testStruct{}
err := yaml.Unmarshal([]byte(tt.data), &got)
if tt.wantErr == "" {
assert.NoError(t, err)
} else {
assert.EqualError(t, err, tt.wantErr)
}
assert.Equal(t, tt.want, got)
})
}
}