Skip to content

Commit

Permalink
Add more tests for profile activation based on regex
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Jul 5, 2019
1 parent 3d1b463 commit 7fee50c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pkg/skaffold/schema/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions pkg/skaffold/schema/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,20 @@ 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{},
profiles: []latest.Profile{
{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{},
Expand All @@ -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"},
}, {
Expand Down

0 comments on commit 7fee50c

Please sign in to comment.