diff --git a/cmd/kosli/snapshotECS.go b/cmd/kosli/snapshotECS.go index 3d05372f4..aaeec4d5d 100644 --- a/cmd/kosli/snapshotECS.go +++ b/cmd/kosli/snapshotECS.go @@ -50,7 +50,7 @@ kosli snapshot ecs my-env \ kosli snapshot ecs my-env --clusters my-cluster ... # include clusters matching a pattern in the AWS account -kosli snapshot ecs my-env --clusters-regex "my-cluster-*" ... +kosli snapshot ecs my-env --clusters-regex "^my-cluster-.*" ... # include clusters matching a list of names in the AWS account kosli snapshot ecs my-env --clusters my-cluster1,my-cluster2 ... @@ -59,7 +59,7 @@ kosli snapshot ecs my-env --clusters my-cluster1,my-cluster2 ... kosli snapshot ecs my-env --exclude my-cluster ... # exclude clusters matching a pattern in the AWS account -kosli snapshot ecs my-env --exclude-regex "my-cluster-*" ... +kosli snapshot ecs my-env --exclude-regex "^my-cluster-.*" ... # exclude clusters matching a list of names in the AWS account kosli snapshot ecs my-env --exclude my-cluster1,my-cluster2 ... @@ -68,10 +68,10 @@ kosli snapshot ecs my-env --exclude my-cluster1,my-cluster2 ... kosli snapshot ecs my-env --clusters my-cluster --services backend-app ... # include Services matching a pattern in one cluster -kosli snapshot ecs my-env --clusters my-cluster --services-regex "backend-*" ... +kosli snapshot ecs my-env --clusters my-cluster --services-regex "^backend-.*" ... # include production Services only (by naming convention) in all clusters in the AWS account -kosli snapshot ecs my-env --services-regex "*-prod-*" ... +kosli snapshot ecs my-env --services-regex ".*-prod-.*" ... # include Services matching a name in all clusters in the AWS account kosli snapshot ecs my-env --services backend-app ... @@ -80,10 +80,10 @@ kosli snapshot ecs my-env --services backend-app ... kosli snapshot ecs my-env --services backend-app,frontend-app ... # exclude Services matching a pattern in one cluster -kosli snapshot ecs my-env --clusters my-cluster --exclude-services-regex "backend-*" ... +kosli snapshot ecs my-env --clusters my-cluster --exclude-services-regex "^backend-.*" ... # exclude Production services only (by naming convention) in all clusters in the AWS account -kosli snapshot ecs my-env --exclude-services-regex "*-prod-*" ... +kosli snapshot ecs my-env --exclude-services-regex ".*-prod-.*" ... # exclude Services matching a name in one cluster kosli snapshot ecs my-env --clusters my-cluster --exclude-services backend-app ... diff --git a/cmd/kosli/snapshotECS_test.go b/cmd/kosli/snapshotECS_test.go index 415f335b0..9fcfdb540 100644 --- a/cmd/kosli/snapshotECS_test.go +++ b/cmd/kosli/snapshotECS_test.go @@ -2,9 +2,11 @@ package main import ( "fmt" + "regexp" "testing" "github.com/kosli-dev/cli/internal/testHelpers" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" ) @@ -129,6 +131,18 @@ func (suite *SnapshotECSTestSuite) TestSnapshotECSCmd() { } } +// the --*-regex flags compile their values as Go regexes, so every regex +// pattern shown in the help examples must actually compile +func TestSnapshotECSExampleRegexesAreValid(t *testing.T) { + patterns := regexp.MustCompile(`--[a-z-]*regex "([^"]*)"`).FindAllStringSubmatch(snapshotECSExample, -1) + require.NotEmpty(t, patterns, "expected the examples to contain regex patterns") + + for _, p := range patterns { + _, err := regexp.Compile(p[1]) + require.NoError(t, err, "example regex %q does not compile", p[1]) + } +} + // In order for 'go test' to run this suite, we need to create // a normal test function and pass our suite to suite.Run func TestSnapshotECSTestSuite(t *testing.T) {