diff --git a/api/metadata/annotations.go b/api/metadata/annotations.go index a8f560913..f17897ede 100644 --- a/api/metadata/annotations.go +++ b/api/metadata/annotations.go @@ -92,6 +92,11 @@ func GetProfileOrDefault(annotation map[string]string) ProfileType { } } +func (p ProfileType) isValidProfile() bool { + _, ok := supportedProfiles[p] + return ok +} + func IsDevProfile(annotation map[string]string) bool { if annotation == nil { return false diff --git a/api/metadata/annotations_test.go b/api/metadata/annotations_test.go index b0437bb38..f69dbe912 100644 --- a/api/metadata/annotations_test.go +++ b/api/metadata/annotations_test.go @@ -41,3 +41,19 @@ func TestGetProfile(t *testing.T) { }) } } + +func TestIsValidProfile(t *testing.T) { + profiles := []ProfileType{DefaultProfile, GitOpsProfile, DevProfile} + for _, profile := range profiles { + if !profile.isValidProfile() { + t.Errorf("Profile %s is not valid", profile) + } + } + if ProdProfile.isValidProfile() { + t.Errorf("ProdProfile is deprecated and should not be valid") + } + // any random string should not be a valid profile + if ProfileType("random").isValidProfile() { + t.Errorf("random is not a valid profile") + } +}