@@ -111,46 +111,37 @@ func TestResolveReleaseLifecycleDerivedWaitStrategy(t *testing.T) {
111111 }
112112}
113113
114- func TestResolveReleaseLifecycleWithFlagsReportsDerivedWaitStrategy (t * testing.T ) {
115- input , err := decodeReleasePolicy (map [string ]any {
116- cfg .HelmReleaseSectionName : map [string ]any {
117- cfg .HelmWaitSectionName : map [string ]any {
118- cfg .HelmWaitStrategySectionName : "hookOnly" ,
119- },
120- cfg .HelmUpgradeSectionName : map [string ]any {
121- cfg .HelmOnFailureSectionName : "rollback" ,
122- cfg .HelmWaitSectionName : map [string ]any {
123- cfg .HelmWaitJobsSectionName : true ,
114+ func TestResolveReleaseLifecycleWithFlagsDerivesWaitStrategyAfterFlagOverlay (t * testing.T ) {
115+ for _ , tt := range []struct {
116+ name string
117+ configuredFailure string
118+ flags map [string ]any
119+ wantStrategy kube.WaitStrategy
120+ wantDerived bool
121+ }{
122+ {name : "configured rollback" , configuredFailure : "rollback" , wantStrategy : kube .StatusWatcherStrategy , wantDerived : true },
123+ {name : "flag rollback" , flags : map [string ]any {cfg .HelmOnFailureSectionName : "rollback" }, wantStrategy : kube .StatusWatcherStrategy , wantDerived : true },
124+ {name : "flag keep disables configured rollback" , configuredFailure : "rollback" , flags : map [string ]any {cfg .HelmOnFailureSectionName : "keep" }, wantStrategy : kube .HookOnlyStrategy },
125+ } {
126+ t .Run (tt .name , func (t * testing.T ) {
127+ upgrade := map [string ]any {}
128+ if tt .configuredFailure != "" {
129+ upgrade [cfg .HelmOnFailureSectionName ] = tt .configuredFailure
130+ }
131+ input , err := decodeReleasePolicy (map [string ]any {
132+ cfg .HelmReleaseSectionName : map [string ]any {
133+ cfg .HelmWaitSectionName : map [string ]any {cfg .HelmWaitStrategySectionName : "hookOnly" },
134+ cfg .HelmUpgradeSectionName : upgrade ,
124135 },
125- },
126- },
127- })
128- require .NoError (t , err )
129-
130- resolution , err := resolveReleaseLifecycleWithFlags (input , releaseOperationUpgrade , nil )
131- require .NoError (t , err )
132- assert .Equal (t , kube .StatusWatcherStrategy , resolution .Policy .WaitStrategy )
133- assert .True (t , resolution .Policy .WaitForJobs )
134- assert .True (t , hasLifecycleWarning (resolution .Warnings , warningWaitDerived ))
135- }
136-
137- func TestResolveReleaseLifecycleWithFlagsCanDisableDerivedWaitStrategy (t * testing.T ) {
138- input , err := decodeReleasePolicy (map [string ]any {
139- cfg .HelmReleaseSectionName : map [string ]any {
140- cfg .HelmWaitSectionName : map [string ]any {cfg .HelmWaitStrategySectionName : "hookOnly" },
141- cfg .HelmUpgradeSectionName : map [string ]any {
142- cfg .HelmOnFailureSectionName : "rollback" ,
143- },
144- },
145- })
146- require .NoError (t , err )
136+ })
137+ require .NoError (t , err )
147138
148- resolution , err := resolveReleaseLifecycleWithFlags (input , releaseOperationUpgrade , map [ string ] any {
149- cfg . HelmOnFailureSectionName : "keep" ,
150- } )
151- require . NoError (t , err )
152- assert . Equal ( t , kube . HookOnlyStrategy , resolution . Policy . WaitStrategy )
153- assert . False ( t , hasLifecycleWarning ( resolution . Warnings , warningWaitDerived ))
139+ resolution , err := resolveReleaseLifecycleWithFlags (input , releaseOperationUpgrade , tt . flags )
140+ require . NoError ( t , err )
141+ assert . Equal ( t , tt . wantStrategy , resolution . Policy . WaitStrategy )
142+ assert . Equal (t , tt . wantDerived , hasLifecycleWarning ( resolution . Warnings , warningWaitDerived ) )
143+ } )
144+ }
154145}
155146
156147func TestResolveReleaseLifecycleWithFlagsHighestPrecedence (t * testing.T ) {
0 commit comments