@@ -769,45 +769,36 @@ func TestDropAppArmor(t *testing.T) {
769769 }}
770770
771771 for _ , test := range tests {
772- for _ , enabled := range []bool {true , false } {
773- for _ , fieldsEnabled := range []bool {true , false } {
774- t .Run (fmt .Sprintf ("%v/enabled=%v/fields=%v" , test .description , enabled , fieldsEnabled ), func (t * testing.T ) {
775- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .AppArmor , enabled )
776- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .AppArmorFields , fieldsEnabled )
777772
778- newPod := test .pod .DeepCopy ()
773+ t .Run (fmt .Sprintf ("%v" , test .description ), func (t * testing.T ) {
774+ newPod := test .pod .DeepCopy ()
779775
780- if hasAnnotations := appArmorAnnotationsInUse (newPod .Annotations ); hasAnnotations != test .hasAnnotations {
781- t .Errorf ("appArmorAnnotationsInUse does not match expectation: %t != %t" , hasAnnotations , test .hasAnnotations )
782- }
783- if hasFields := appArmorFieldsInUse (& newPod .Spec ); hasFields != test .hasFields {
784- t .Errorf ("appArmorFieldsInUse does not match expectation: %t != %t" , hasFields , test .hasFields )
785- }
786-
787- DropDisabledPodFields (newPod , newPod )
788- require .Equal (t , & test .pod , newPod , "unchanged pod should never be mutated" )
776+ if hasAnnotations := appArmorAnnotationsInUse (newPod .Annotations ); hasAnnotations != test .hasAnnotations {
777+ t .Errorf ("appArmorAnnotationsInUse does not match expectation: %t != %t" , hasAnnotations , test .hasAnnotations )
778+ }
779+ if hasFields := appArmorFieldsInUse (& newPod .Spec ); hasFields != test .hasFields {
780+ t .Errorf ("appArmorFieldsInUse does not match expectation: %t != %t" , hasFields , test .hasFields )
781+ }
789782
790- DropDisabledPodFields (newPod , nil )
783+ DropDisabledPodFields (newPod , newPod )
784+ require .Equal (t , & test .pod , newPod , "unchanged pod should never be mutated" )
791785
792- if enabled && fieldsEnabled {
793- assert .Equal (t , & test .pod , newPod , "pod should not be mutated when both feature gates are enabled" )
794- return
795- }
786+ DropDisabledPodFields (newPod , nil )
787+ assert .Equal (t , & test .pod , newPod , "pod should not be mutated when both feature gates are enabled" )
796788
797- expectAnnotations := test .hasAnnotations && enabled
798- assert .Equal (t , expectAnnotations , appArmorAnnotationsInUse (newPod .Annotations ), "AppArmor annotations expectation" )
799- if expectAnnotations == test .hasAnnotations {
800- assert .Equal (t , test .pod .Annotations , newPod .Annotations , "annotations should not be mutated" )
801- }
789+ expectAnnotations := test .hasAnnotations
790+ assert .Equal (t , expectAnnotations , appArmorAnnotationsInUse (newPod .Annotations ), "AppArmor annotations expectation" )
791+ if expectAnnotations == test .hasAnnotations {
792+ assert .Equal (t , test .pod .Annotations , newPod .Annotations , "annotations should not be mutated" )
793+ }
802794
803- expectFields := test .hasFields && enabled && fieldsEnabled
804- assert .Equal (t , expectFields , appArmorFieldsInUse (& newPod .Spec ), "AppArmor fields expectation" )
805- if expectFields == test .hasFields {
806- assert .Equal (t , & test .pod .Spec , & newPod .Spec , "PodSpec should not be mutated" )
807- }
808- })
795+ expectFields := test .hasFields
796+ assert .Equal (t , expectFields , appArmorFieldsInUse (& newPod .Spec ), "AppArmor fields expectation" )
797+ if expectFields == test .hasFields {
798+ assert .Equal (t , & test .pod .Spec , & newPod .Spec , "PodSpec should not be mutated" )
809799 }
810- }
800+ })
801+
811802 }
812803}
813804
0 commit comments