Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cmd/kosli/snapshotECS.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand All @@ -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 ...
Expand All @@ -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 ...
Expand All @@ -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 ...
Expand Down
14 changes: 14 additions & 0 deletions cmd/kosli/snapshotECS_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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) {
Expand Down