Skip to content

Commit

Permalink
wj
Browse files Browse the repository at this point in the history
  • Loading branch information
keroxp committed Jun 17, 2024
1 parent e08efdf commit ff7d0aa
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 535 deletions.
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
MOCKGEN := go run github.com/golang/mock/[email protected]
.PHONY: test
test:
go test -coverprofile=coverage.txt -covermode=count
go test ./... -coverprofile=coverage.txt -covermode=count
test-container:
docker build -t canarycage/test-container test-container
push-test-container: test-container
docker tag canarycage/test-container loilodev/http-server:latest
docker push loilodev/http-server:latest
version:
go run cli/cage/main.go -v | cut -f 3 -d ' '

mocks:
mkdir -p mocks/mock_awsiface && $(MOCKGEN) -source=./awsiface/iface.go > mocks/mock_awsiface/iface.go

mocks: mocks/mock_awsiface/iface.go mocks/mock_cage/iface.go mocks/mock_upgrade/upgrade.go
mocks/mock_awsiface/iface.go: awsiface/iface.go
$(MOCKGEN) -source=./awsiface/iface.go > mocks/mock_awsiface/iface.go
mocks/mock_cage/iface.go: cage.go
$(MOCKGEN) -source=./cage.go > mocks/mock_cage/cage.go
mocks/mock_upgrade/upgrade.go: cli/cage/upgrade/upgrade.go
$(MOCKGEN) -source=./cli/cage/upgrade/upgrade.go > mocks/mock_upgrade/upgrade.go
.PHONY: mocks
4 changes: 1 addition & 3 deletions cage.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:generate go run github.com/golang/mock/mockgen -source $GOFILE -destination ../mocks/mock_$GOPACKAGE/$GOFILE -package mock_$GOPACKAGE
package cage

import (
Expand All @@ -11,8 +10,7 @@ import (
type Cage interface {
Up(ctx context.Context) (*UpResult, error)
Run(ctx context.Context, input *RunInput) (*RunResult, error)
RollOut(ctx context.Context) (*RollOutResult, error)
Recreate(ctx context.Context) (*RecreateResult, error)
RollOut(ctx context.Context, input *RollOutInput) (*RollOutResult, error)
}

type Time interface {
Expand Down
27 changes: 3 additions & 24 deletions cli/cage/commands/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,29 @@ func TestCommands(t *testing.T) {
cmds.Up(&envars),
cmds.RollOut(&envars),
cmds.Run(&envars),
cmds.Recreate(&envars),
}
return app, cagecli
}
t.Run("rollout", func(t *testing.T) {
t.Run("basic", func(t *testing.T) {
app, cagecli := setup(t, stdinService)
cagecli.EXPECT().RollOut(gomock.Any()).Return(&cage.RollOutResult{}, nil)
cagecli.EXPECT().RollOut(gomock.Any(), gomock.Any()).Return(&cage.RollOutResult{}, nil)
err := app.Run([]string{"cage", "rollout", "--region", "ap-notheast-1", "../../../fixtures"})
assert.NoError(t, err)
})
t.Run("basic/ci", func(t *testing.T) {
app, cagecli := setup(t, "")
cagecli.EXPECT().RollOut(gomock.Any()).Return(&cage.RollOutResult{}, nil)
cagecli.EXPECT().RollOut(gomock.Any(), gomock.Any()).Return(&cage.RollOutResult{}, nil)
err := app.Run([]string{"cage", "rollout", "--region", "ap-notheast-1", "../../../fixtures"})
assert.NoError(t, err)
})
t.Run("error", func(t *testing.T) {
app, cagecli := setup(t, stdinService)
cagecli.EXPECT().RollOut(gomock.Any()).Return(&cage.RollOutResult{}, fmt.Errorf("error"))
cagecli.EXPECT().RollOut(gomock.Any(), gomock.Any()).Return(&cage.RollOutResult{}, fmt.Errorf("error"))
err := app.Run([]string{"cage", "rollout", "--region", "ap-notheast-1", "../../../fixtures"})
assert.EqualError(t, err, "error")
})
})
t.Run("recreate", func(t *testing.T) {
t.Run("basic", func(t *testing.T) {
app, cagecli := setup(t, stdinService)
cagecli.EXPECT().Recreate(gomock.Any()).Return(&cage.RecreateResult{}, nil)
err := app.Run([]string{"cage", "recreate", "--region", "ap-notheast-1", "../../../fixtures"})
assert.NoError(t, err)
})
t.Run("basic/ci", func(t *testing.T) {
app, cagecli := setup(t, "")
cagecli.EXPECT().Recreate(gomock.Any()).Return(&cage.RecreateResult{}, nil)
err := app.Run([]string{"cage", "recreate", "--region", "ap-notheast-1", "../../../fixtures"})
assert.NoError(t, err)
})
t.Run("error", func(t *testing.T) {
app, cagecli := setup(t, stdinService)
cagecli.EXPECT().Recreate(gomock.Any()).Return(nil, fmt.Errorf("error"))
err := app.Run([]string{"cage", "recreate", "--region", "ap-notheast-1", "../../../fixtures"})
assert.EqualError(t, err, "error")
})
})
t.Run("up", func(t *testing.T) {
t.Run("basic", func(t *testing.T) {
app, cagecli := setup(t, stdinService)
Expand Down
42 changes: 0 additions & 42 deletions cli/cage/commands/recreate.go

This file was deleted.

9 changes: 8 additions & 1 deletion cli/cage/commands/rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
func (c *CageCommands) RollOut(
envars *cage.Envars,
) *cli.Command {
var updateServiceConf bool
return &cli.Command{
Name: "rollout",
Usage: "roll out ECS service to next task definition",
Expand All @@ -29,6 +30,12 @@ func (c *CageCommands) RollOut(
Usage: "EC2 instance ARN for placing canary task. required only when LaunchType is EC2",
Destination: &envars.CanaryInstanceArn,
},
&cli.BoolFlag{
Name: "updateService",
EnvVars: []string{cage.UpdateServiceKey},
Usage: "Update service configurations except for task definiton. Default is false.",
Destination: &updateServiceConf,
},
},
Action: func(ctx *cli.Context) error {
dir, _, err := c.requireArgs(ctx, 1, 1)
Expand All @@ -42,7 +49,7 @@ func (c *CageCommands) RollOut(
if err := c.Prompt.ConfirmService(envars); err != nil {
return err
}
result, err := cagecli.RollOut(context.Background())
result, err := cagecli.RollOut(context.Background(), &cage.RollOutInput{UpdateService: updateServiceConf})
if err != nil {
if result.ServiceIntact {
log.Errorf("🤕 failed to roll out new tasks but service '%s' is not changed", envars.Service)
Expand Down
1 change: 0 additions & 1 deletion cli/cage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func main() {
cmds.Up(&envars),
cmds.RollOut(&envars),
cmds.Run(&envars),
cmds.Recreate(&envars),
cmds.Upgrade(upgrade.NewUpgrader(version)),
}
app.Flags = []cli.Flag{
Expand Down
1 change: 1 addition & 0 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const TaskDefinitionArnKey = "CAGE_TASK_DEFINITION_ARN"
const CanaryInstanceArnKey = "CAGE_CANARY_INSTANCE_ARN"
const RegionKey = "CAGE_REGION"
const CanaryTaskIdleDuration = "CAGE_CANARY_TASK_IDLE_DURATION"
const UpdateServiceKey = "CAGE_UPDATE_SERVIEC"

func EnsureEnvars(
dest *Envars,
Expand Down
25 changes: 5 additions & 20 deletions mocks/mock_cage/cage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 0 additions & 139 deletions recreate.go

This file was deleted.

Loading

0 comments on commit ff7d0aa

Please sign in to comment.