Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding flag to pull previous deploy settings #16

Merged
merged 3 commits into from
Jun 4, 2024
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ vet: ## Run vet on all code with the go vet command.
##@ Tests
.PHONY: test
test: ## Unit test all modules.
go test -v -race ./...
go test -v -parallel=1 -race ./...

.PHONY: test-short
test-short: ## Unit test all modules in short mode.
go test -v -race -short ./...
go test -v -parallel=1 -race -short ./...

##@ Misc.
# The help target prints out all targets with their descriptions organized
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -7,15 +6,12 @@ github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731 h1:R/ZjJpjQK
github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli-altsrc/v3 v3.0.0-alpha2/go.mod h1:Q79oyIY/z4jtzIrKEK6MUeWC7/szGr46x4QdOaOAIWc=
github.com/urfave/cli/v3 v3.0.0-alpha9 h1:P0RMy5fQm1AslQS+XCmy9UknDXctOmG/q/FZkUFnJSo=
github.com/urfave/cli/v3 v3.0.0-alpha9/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
Expand All @@ -26,6 +22,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/exp v0.0.0-20240529005216-23cca8864a10 h1:vpzMC/iZhYFAjJzHU0Cfuq+w1vLLsF2vLkDrPjzKYck=
golang.org/x/exp v0.0.0-20240529005216-23cca8864a10/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
13 changes: 9 additions & 4 deletions internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import (
)

func Test_BuildCommands_HelpText(t *testing.T) {
// urfave cli is not currently thread safe
// t.Parallel()
t.Parallel()

app := commands.App()
err := app.Run(context.Background(), []string{"ci", "build", "--help"})
Expand All @@ -28,8 +27,7 @@ func Test_Integration_BuildCommands_Happy(t *testing.T) {
t.Skip("skipping integration test in short mode")
}

// urfave cli is not currently thread safe
// t.Parallel()
t.Parallel()

tests := []struct {
name string
Expand Down Expand Up @@ -228,6 +226,12 @@ func Test_Integration_BuildCommands_Happy(t *testing.T) {
}

func Test_Integration_BuildCommands_GlobalArgs(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test in short mode")
}

t.Parallel()

tests := []struct {
name string
command string
Expand Down Expand Up @@ -340,6 +344,7 @@ func Test_Integration_BuildCommands_GlobalArgs(t *testing.T) {
h.Endpoint,
}
testArgs := strings.Fields(tt.command)
t.Log(append(staticArgs, testArgs...))
err := app.Run(context.Background(), append(staticArgs, testArgs...))
assert.Nil(t, err, "command returned an error")
request, body := h.ReceivedRequest()
Expand Down
35 changes: 26 additions & 9 deletions internal/commands/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,53 @@ import (
"strings"
)

func requireValidEnumValue(value string, allowedValues []string, enumName string) error {
if !slices.Contains(allowedValues, value) {
type StringLike interface {
~string
}

func requireValidEnumValue[S StringLike](value S, allowedValues []string, enumName string) error {
if !slices.Contains(allowedValues, string(value)) {
return fmt.Errorf("flag %s must be one of [%s]", enumName, strings.Join(allowedTransportTypes, ", "))
}

return nil
}

func requireIntInRange(value int64, lower int64, upper int64, flagName string) error {
type IntLike interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

func requireIntInRange[N IntLike](
value N,
lower N,
upper N,
flagName string,
) error {
if value < lower || value > upper {
return fmt.Errorf("flag %s must be between %d and %d", flagName, lower, upper)
}

return nil
}

func requireFloatInRange(value float64, lower float64, upper float64, flagName string) error {
type FloatLike interface {
~float32 | ~float64
}

func requireFloatInRange[N FloatLike](value N, lower N, upper N, flagName string) error {
if value < lower || value > upper {
return fmt.Errorf("flag %s must be between %s and %s",
flagName,
strconv.FormatFloat(lower, 'f', -1, 64),
strconv.FormatFloat(upper, 'f', -1, 64))
strconv.FormatFloat(float64(lower), 'f', -1, 64),
strconv.FormatFloat(float64(upper), 'f', -1, 64))
}

return nil
}

func requireMaxDecimals(value float64, max int, flagName string) error {
func requireMaxDecimals[N FloatLike](value N, max int, flagName string) error {
var decimals int
stringValue := strconv.FormatFloat(value, 'f', -1, 64)
stringValue := strconv.FormatFloat(float64(value), 'f', -1, 64)
index := strings.IndexByte(stringValue, '.')
if index > -1 {
decimals = len(stringValue) - index - 1
Expand All @@ -47,4 +64,4 @@ func requireMaxDecimals(value float64, max int, flagName string) error {
}

return nil
}
}
Loading
Loading