From 7fee50cb99189481b29319b215d24938858592d3 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 5 Jul 2019 13:02:31 +0200 Subject: [PATCH] Add more tests for profile activation based on regex Signed-off-by: David Gageot --- pkg/skaffold/schema/profiles.go | 7 +++++-- pkg/skaffold/schema/profiles_test.go | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/skaffold/schema/profiles.go b/pkg/skaffold/schema/profiles.go index 851173d0662..7026ba478bd 100644 --- a/pkg/skaffold/schema/profiles.go +++ b/pkg/skaffold/schema/profiles.go @@ -132,11 +132,14 @@ func satisfies(expected, actual string) bool { } func matches(expected, actual string) bool { - matcher, err := re.Compile(expected) + if actual == expected { + return true + } + matcher, err := re.Compile(expected) if err != nil { logrus.Infof("profile activation criteria '%s' is not a valid regexp, falling back to string", expected) - return actual == expected + return false } return matcher.MatchString(actual) diff --git a/pkg/skaffold/schema/profiles_test.go b/pkg/skaffold/schema/profiles_test.go index 774c5902550..5846a645cff 100644 --- a/pkg/skaffold/schema/profiles_test.go +++ b/pkg/skaffold/schema/profiles_test.go @@ -348,8 +348,10 @@ func TestActivatedProfiles(t *testing.T) { {Name: "run-profile", Activation: []latest.Activation{{Command: "run"}}}, {Name: "dev-profile", Activation: []latest.Activation{{Command: "dev"}}}, {Name: "non-run-profile", Activation: []latest.Activation{{Command: "!run"}}}, + {Name: "run-or-dev-profile", Activation: []latest.Activation{{Command: "(run)|(dev)"}}}, + {Name: "other-profile", Activation: []latest.Activation{{Command: "!(run)|(dev)"}}}, }, - expected: []string{"dev-profile", "non-run-profile"}, + expected: []string{"dev-profile", "non-run-profile", "run-or-dev-profile"}, }, { description: "Auto-activated by env variable", opts: &cfg.SkaffoldOptions{}, @@ -357,8 +359,9 @@ func TestActivatedProfiles(t *testing.T) { {Name: "activated", Activation: []latest.Activation{{Env: "KEY=VALUE"}}}, {Name: "not-activated", Activation: []latest.Activation{{Env: "KEY=OTHER"}}}, {Name: "also-activated", Activation: []latest.Activation{{Env: "KEY=!OTHER"}}}, + {Name: "regex-activated", Activation: []latest.Activation{{Env: "KEY=V.*E"}}}, }, - expected: []string{"activated", "also-activated"}, + expected: []string{"activated", "also-activated", "regex-activated"}, }, { description: "Invalid env variable", opts: &cfg.SkaffoldOptions{}, @@ -375,6 +378,7 @@ func TestActivatedProfiles(t *testing.T) { {Name: "also-activated", Activation: []latest.Activation{{KubeContext: "!dev-context"}}}, {Name: "activated-regexp", Activation: []latest.Activation{{KubeContext: "prod-.*"}}}, {Name: "not-activated-regexp", Activation: []latest.Activation{{KubeContext: "dev-.*"}}}, + {Name: "invalid-regexp", Activation: []latest.Activation{{KubeContext: `\`}}}, }, expected: []string{"activated", "also-activated", "activated-regexp"}, }, {