@@ -24,6 +24,7 @@ import (
24
24
25
25
"github.com/spf13/pflag"
26
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
+ "k8s.io/apimachinery/pkg/util/sets"
27
28
"k8s.io/apimachinery/pkg/util/validation/field"
28
29
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
29
30
kubeadmapiv1beta2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
@@ -703,26 +704,81 @@ func TestValidateFeatureGates(t *testing.T) {
703
704
704
705
func TestValidateIgnorePreflightErrors (t * testing.T ) {
705
706
var tests = []struct {
706
- ignorePreflightErrors []string
707
- expectedLen int
708
- expectedError bool
707
+ ignorePreflightErrorsFromCLI []string
708
+ ignorePreflightErrorsFromConfigFile []string
709
+ expectedSet sets.String
710
+ expectedError bool
709
711
}{
710
- {[]string {}, 0 , false }, // empty list
711
- {[]string {"check1" , "check2" }, 2 , false }, // non-duplicate
712
- {[]string {"check1" , "check2" , "check1" }, 2 , false }, // duplicates
713
- {[]string {"check1" , "check2" , "all" }, 3 , true }, // non-duplicate, but 'all' present together wth individual checks
714
- {[]string {"all" }, 1 , false }, // skip all checks by using new flag
715
- {[]string {"all" }, 1 , false }, // skip all checks by using both old and new flags at the same time
712
+ { // empty lists in CLI and config file
713
+ []string {},
714
+ []string {},
715
+ sets .NewString (),
716
+ false ,
717
+ },
718
+ { // empty list in CLI only
719
+ []string {},
720
+ []string {"a" },
721
+ sets .NewString ("a" ),
722
+ false ,
723
+ },
724
+ { // empty list in config file only
725
+ []string {"a" },
726
+ []string {},
727
+ sets .NewString ("a" ),
728
+ false ,
729
+ },
730
+ { // no duplicates, no overlap
731
+ []string {"a" , "b" },
732
+ []string {"c" , "d" },
733
+ sets .NewString ("a" , "b" , "c" , "d" ),
734
+ false ,
735
+ },
736
+ { // some duplicates, with some overlapping duplicates
737
+ []string {"a" , "b" , "a" },
738
+ []string {"c" , "b" },
739
+ sets .NewString ("a" , "b" , "c" ),
740
+ false ,
741
+ },
742
+ { // non-duplicate, but 'all' present together with individual checks in CLI
743
+ []string {"a" , "b" , "all" },
744
+ []string {},
745
+ sets .NewString (),
746
+ true ,
747
+ },
748
+ { // empty list in CLI, but 'all' present in config file, which is forbidden
749
+ []string {},
750
+ []string {"all" },
751
+ sets .NewString (),
752
+ true ,
753
+ },
754
+ { // non-duplicate, but 'all' present in config file, which is forbidden
755
+ []string {"a" , "b" },
756
+ []string {"all" },
757
+ sets .NewString (),
758
+ true ,
759
+ },
760
+ { // non-duplicate, but 'all' present in CLI, while values are in config file, which is forbidden
761
+ []string {"all" },
762
+ []string {"a" , "b" },
763
+ sets .NewString (),
764
+ true ,
765
+ },
766
+ { // skip all checks
767
+ []string {"all" },
768
+ []string {},
769
+ sets .NewString ("all" ),
770
+ false ,
771
+ },
716
772
}
717
773
for _ , rt := range tests {
718
- result , err := ValidateIgnorePreflightErrors (rt .ignorePreflightErrors )
774
+ result , err := ValidateIgnorePreflightErrors (rt .ignorePreflightErrorsFromCLI , rt . ignorePreflightErrorsFromConfigFile )
719
775
switch {
720
776
case err != nil && ! rt .expectedError :
721
- t .Errorf ("ValidateIgnorePreflightErrors: unexpected error for input (%s), error: %v" , rt .ignorePreflightErrors , err )
777
+ t .Errorf ("ValidateIgnorePreflightErrors: unexpected error for input (%s, %s ), error: %v" , rt .ignorePreflightErrorsFromCLI , rt . ignorePreflightErrorsFromConfigFile , err )
722
778
case err == nil && rt .expectedError :
723
- t .Errorf ("ValidateIgnorePreflightErrors: expected error for input (%s) but got: %v" , rt .ignorePreflightErrors , result )
724
- case result . Len () != rt .expectedLen :
725
- t .Errorf ("ValidateIgnorePreflightErrors: expected Len = %d for input (%s) but got: %v, %v " , rt .expectedLen , rt .ignorePreflightErrors , result . Len () , result )
779
+ t .Errorf ("ValidateIgnorePreflightErrors: expected error for input (%s, %s ) but got: %v" , rt .ignorePreflightErrorsFromCLI , rt . ignorePreflightErrorsFromConfigFile , result )
780
+ case err == nil && ! result . Equal ( rt .expectedSet ) :
781
+ t .Errorf ("ValidateIgnorePreflightErrors: expected (%v) for input (%s, %s ) but got: %v" , rt .expectedSet , rt .ignorePreflightErrorsFromCLI , rt . ignorePreflightErrorsFromConfigFile , result )
726
782
}
727
783
}
728
784
}
0 commit comments