@@ -45,22 +45,39 @@ func TestDeploymentSpecSetDefaults(t *testing.T) {
45
45
46
46
func TestDeploymentSpecResetImmutableFields (t * testing.T ) {
47
47
tests := []struct {
48
- Original DeploymentSpec
49
- Target DeploymentSpec
50
- Expected DeploymentSpec
51
- Result []string
48
+ Original DeploymentSpec
49
+ Target DeploymentSpec
50
+ Expected DeploymentSpec
51
+ ApplyDefaults bool
52
+ Result []string
52
53
}{
53
54
// Valid "changes"
54
55
{
55
56
DeploymentSpec {Image : util .NewString ("foo" )},
56
57
DeploymentSpec {Image : util .NewString ("foo2" )},
57
58
DeploymentSpec {Image : util .NewString ("foo2" )},
59
+ false ,
60
+ nil ,
61
+ },
62
+ {
63
+ DeploymentSpec {Image : util .NewString ("foo" )},
64
+ DeploymentSpec {Image : util .NewString ("foo2" )},
65
+ DeploymentSpec {Image : util .NewString ("foo2" )},
66
+ true ,
58
67
nil ,
59
68
},
60
69
{
61
70
DeploymentSpec {ImagePullPolicy : util .NewPullPolicy (v1 .PullAlways )},
62
71
DeploymentSpec {ImagePullPolicy : util .NewPullPolicy (v1 .PullNever )},
63
72
DeploymentSpec {ImagePullPolicy : util .NewPullPolicy (v1 .PullNever )},
73
+ false ,
74
+ nil ,
75
+ },
76
+ {
77
+ DeploymentSpec {ImagePullPolicy : util .NewPullPolicy (v1 .PullAlways )},
78
+ DeploymentSpec {ImagePullPolicy : util .NewPullPolicy (v1 .PullNever )},
79
+ DeploymentSpec {ImagePullPolicy : util .NewPullPolicy (v1 .PullNever )},
80
+ true ,
64
81
nil ,
65
82
},
66
83
@@ -69,12 +86,31 @@ func TestDeploymentSpecResetImmutableFields(t *testing.T) {
69
86
DeploymentSpec {Mode : NewMode (DeploymentModeSingle )},
70
87
DeploymentSpec {Mode : NewMode (DeploymentModeCluster )},
71
88
DeploymentSpec {Mode : NewMode (DeploymentModeSingle )},
89
+ false ,
72
90
[]string {"mode" },
73
91
},
92
+ {
93
+ DeploymentSpec {Mode : NewMode (DeploymentModeSingle )},
94
+ DeploymentSpec {Mode : NewMode (DeploymentModeCluster )},
95
+ DeploymentSpec {Mode : NewMode (DeploymentModeSingle )},
96
+ true ,
97
+ []string {"mode" , "agents.count" },
98
+ },
74
99
}
75
100
76
101
for _ , test := range tests {
102
+ if test .ApplyDefaults {
103
+ test .Original .SetDefaults ("foo" )
104
+ test .Expected .SetDefaults ("foo" )
105
+ test .Target .SetDefaultsFrom (test .Original )
106
+ test .Target .SetDefaults ("foo" )
107
+ }
77
108
result := test .Original .ResetImmutableFields (& test .Target )
109
+ if test .ApplyDefaults {
110
+ if len (result ) > 0 {
111
+ test .Target .SetDefaults ("foo" )
112
+ }
113
+ }
78
114
assert .Equal (t , test .Result , result )
79
115
assert .Equal (t , test .Expected , test .Target )
80
116
}
0 commit comments