Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
use compose-ecs binary we just built
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Apr 24, 2023
1 parent 5083311 commit 3da16ae
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ all: cli
cli: ## Compile the cli
@docker build . --target cli \
--platform local \
--build-arg BUILD_TAGS=e2e,kube \
--build-arg BUILD_TAGS=e2e \
--build-arg GIT_TAG=$(GIT_TAG) \
--output ./bin

e2e-win-ci: ## Run end to end local tests on Windows CI, no Docker for Linux containers available ATM. Set E2E_TEST=TestName to run a single test
go test -count=1 -v $(TEST_FLAGS) ./local/e2e/cli-only

e2e-ecs: ## Run End to end ECS tests. Set E2E_TEST=TestName to run a single test
e2e-ecs: cli ## Run End to end ECS tests. Set E2E_TEST=TestName to run a single test
go test -timeout 30m -count=1 -v $(TEST_FLAGS) ./ecs/e2e/ecs

cross: ## Compile the CLI for linux, darwin and windows
Expand All @@ -54,7 +54,6 @@ cross: ## Compile the CLI for linux, darwin and windows

test: ## Run unit tests
@docker build --progress=plain . \
--build-arg BUILD_TAGS=kube \
--build-arg GIT_TAG=$(GIT_TAG) \
--target test

Expand All @@ -63,7 +62,7 @@ cache-clear: ## Clear the builder cache

lint: ## run linter(s)
@docker build . \
--build-arg BUILD_TAGS=kube,e2e \
--build-arg BUILD_TAGS=e2e \
--build-arg GIT_TAG=$(GIT_TAG) \
--target lint

Expand Down
3 changes: 0 additions & 3 deletions builder.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
BINARY?=bin/compose-ecs
BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION)

COMPOSE_BINARY?=bin/docker-compose
COMPOSE_BINARY_WITH_EXTENSION=$(COMPOSE_BINARY)$(EXTENSION)

WORK_DIR:=$(shell mktemp -d)

TAGS:=
Expand Down
6 changes: 4 additions & 2 deletions cli/cmd/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func createSecret() *cobra.Command {
if len(args) == 2 {
file = args[1]
}
fmt.Println("create secret from " + file)
if len(file) == 0 {
return fmt.Errorf("secret data source empty: %q", file)
}
Expand All @@ -63,11 +64,12 @@ func createSecret() *cobra.Command {
case "-":
in = os.Stdin
default:
in, err := os.Open(file)
f, err := os.Open(file)
if err != nil {
return err
}
defer func() { _ = in.Close() }()
in = f
defer in.Close() //nolint:errcheck
}
content, err := io.ReadAll(in)
if err != nil {
Expand Down
23 changes: 15 additions & 8 deletions ecs/e2e/ecs/e2e-ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,39 @@ func TestSecrets(t *testing.T) {
secretFile := filepath.Join(t.TempDir(), "secret.txt")
err := os.WriteFile(secretFile, []byte("pass1"), 0644)
assert.Check(t, err == nil)
res := icmd.RunCommand("compose-ecs", "secret", "create", secretName, secretFile)
assert.Check(t, strings.Contains(res.Stdout(), secretName), res.Stdout())
res := icmd.RunCommand(composeECS(), "secret", "create", secretName, secretFile)
stdout := res.Stdout()
stderr := res.Stderr()
fmt.Println(stderr)
assert.Check(t, strings.Contains(stdout, secretName), stdout)
})

t.Run("list secrets", func(t *testing.T) {
res := icmd.RunCommand("compose-ecs", "secret", "list")
res := icmd.RunCommand(composeECS(), "secret", "list")
assert.Check(t, strings.Contains(res.Stdout(), secretName), res.Stdout())
})

t.Run("inspect secret", func(t *testing.T) {
res := icmd.RunCommand("compose-ecs", "secret", "inspect", secretName)
res := icmd.RunCommand(composeECS(), "secret", "inspect", secretName)
assert.Check(t, strings.Contains(res.Stdout(), `"Name": "`+secretName+`"`), res.Stdout())
})

t.Run("rm secret", func(t *testing.T) {
icmd.RunCommand("compose-ecs", "secret", "rm", secretName)
icmd.RunCommand(composeECS(), "secret", "rm", secretName)
res := icmd.RunCommand("secret", "list")
assert.Check(t, !strings.Contains(res.Stdout(), secretName), res.Stdout())
})
}

func TestCompose(t *testing.T) {
t.Run("compose-ecs up", func(t *testing.T) {
res := icmd.RunCommand("compose-ecs", "up")
res := icmd.RunCommand(composeECS(), "up")
res.Assert(t, icmd.Success)
})

var webURL, wordsURL, secretsURL string
t.Run("compose-ecs ps", func(t *testing.T) {
res := icmd.RunCommand("compose-ecs", "ps")
res := icmd.RunCommand(composeECS(), "ps")
lines := strings.Split(strings.TrimSpace(res.Stdout()), "\n")

assert.Equal(t, 5, len(lines))
Expand Down Expand Up @@ -126,7 +129,7 @@ func TestCompose(t *testing.T) {
})

t.Run("compose-ecs down", func(t *testing.T) {
res := icmd.RunCommand("compose-ecs", "down")
res := icmd.RunCommand(composeECS(), "down")

checkUp := func(t poll.LogT) poll.Result {
out := res.Combined()
Expand All @@ -139,6 +142,10 @@ func TestCompose(t *testing.T) {
})
}

func composeECS() string {
return filepath.Clean("./../../../bin/compose-ecs")
}

// HTTPGetWithRetry performs an HTTP GET on an `endpoint`, using retryDelay also as a request timeout.
// In the case of an error or the response status is not the expected one, it retries the same request,
// returning the response body as a string (empty if we could not reach it)
Expand Down

0 comments on commit 3da16ae

Please sign in to comment.