-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor skipvalidations to include create (#6189)
- Loading branch information
Showing
7 changed files
with
131 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package validations | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ValidSkippableValidationsMap returns a map for all valid skippable validations as keys, defaulting values to false. | ||
// Defaulting to False means these validations won't be skipped unless set to True. | ||
func validSkippableValidationsMap(skippableValidations []string) map[string]bool { | ||
validationsMap := make(map[string]bool, len(skippableValidations)) | ||
|
||
for i := range skippableValidations { | ||
validationsMap[skippableValidations[i]] = false | ||
} | ||
|
||
return validationsMap | ||
} | ||
|
||
// ValidateSkippableValidation validates if provided validations are supported by EKSA to skip for upgrades. | ||
func ValidateSkippableValidation(skippedValidations []string, skippableValidations []string) (map[string]bool, error) { | ||
svMap := validSkippableValidationsMap(skippableValidations) | ||
|
||
for i := range skippedValidations { | ||
validationName := skippedValidations[i] | ||
_, ok := svMap[validationName] | ||
if !ok { | ||
return nil, fmt.Errorf("invalid validation name to be skipped. The supported validations that can be skipped using --skip-validations are %s", strings.Join(skippableValidations[:], ",")) | ||
} | ||
svMap[validationName] = true | ||
} | ||
|
||
return svMap, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package validations_test | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/aws/eks-anywhere/pkg/validations" | ||
"github.com/aws/eks-anywhere/pkg/validations/createvalidations" | ||
"github.com/aws/eks-anywhere/pkg/validations/upgradevalidations" | ||
) | ||
|
||
func TestValidateSkippableValidation(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want map[string]bool | ||
wantErr error | ||
skippedValidations []string | ||
skippableValidations []string | ||
}{ | ||
{ | ||
name: "invalid upgrade validation param", | ||
want: nil, | ||
wantErr: fmt.Errorf("invalid validation name to be skipped. The supported validations that can be skipped using --skip-validations are %s", strings.Join(upgradevalidations.SkippableValidations[:], ",")), | ||
skippedValidations: []string{"test"}, | ||
skippableValidations: []string{upgradevalidations.PDB}, | ||
}, | ||
{ | ||
name: "valid upgrade validation param", | ||
want: map[string]bool{ | ||
upgradevalidations.PDB: true, | ||
}, | ||
wantErr: nil, | ||
skippedValidations: []string{upgradevalidations.PDB}, | ||
skippableValidations: []string{upgradevalidations.PDB}, | ||
}, | ||
{ | ||
name: "valid create validation param", | ||
want: map[string]bool{ | ||
createvalidations.VSphereUserPriv: true, | ||
}, | ||
wantErr: nil, | ||
skippedValidations: []string{createvalidations.VSphereUserPriv}, | ||
skippableValidations: []string{createvalidations.VSphereUserPriv}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := validations.ValidateSkippableValidation(tt.skippedValidations, tt.skippableValidations) | ||
if !reflect.DeepEqual(err, tt.wantErr) { | ||
t.Errorf("ValidateSkippableValidation() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ValidateSkippableValidation() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
pkg/validations/upgradevalidations/upgradeskipvalidations.go
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
pkg/validations/upgradevalidations/upgradeskipvalidations_test.go
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters