Skip to content

Commit aed0266

Browse files
authored
Fix binary path in integration tests for windows (#17)
1 parent 74e67bc commit aed0266

5 files changed

Lines changed: 24 additions & 10 deletions

File tree

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
BINARY_NAME=lstk
2+
ifeq ($(OS),Windows_NT)
3+
BINARY_NAME=lstk.exe
4+
endif
25
BUILD_DIR=bin
36

47
.PHONY: build clean test test-integration lint mock-generate
58

6-
build:
9+
$(BUILD_DIR)/$(BINARY_NAME):
710
go build -o $(BUILD_DIR)/$(BINARY_NAME) .
811

12+
build: clean $(BUILD_DIR)/$(BINARY_NAME)
13+
914
clean:
1015
rm -rf $(BUILD_DIR)
1116

1217
test:
1318
@JUNIT=""; [ -n "$$CREATE_JUNIT_REPORT" ] && JUNIT="--junitfile test-results.xml"; \
1419
go run gotest.tools/gotestsum@latest --format testdox $$JUNIT -- ./cmd/... ./internal/...
1520

16-
test-integration: build
21+
test-integration: $(BUILD_DIR)/$(BINARY_NAME)
1722
@JUNIT=""; [ -n "$$CREATE_JUNIT_REPORT" ] && JUNIT="--junitfile ../../test-integration-results.xml"; \
1823
cd test/integration && go run gotest.tools/gotestsum@latest --format testdox $$JUNIT -- -count=1 ./...
1924

test/integration/config_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ func TestConfigFileCreatedOnStartup(t *testing.T) {
3434

3535
configFile := filepath.Join(configDir, "config.toml")
3636

37-
cmd := exec.Command("../../bin/lstk", "start")
37+
cmd := exec.Command(binaryPath(), "start")
3838
cmd.Env = env
39-
cmd.Start()
39+
err := cmd.Start()
40+
require.NoError(t, err, "failed to start lstk")
4041
defer cmd.Process.Kill()
4142

4243
// Poll for config file creation - check every 50ms, timeout after 2s

test/integration/logout_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestLogoutCommandRemovesToken(t *testing.T) {
2626
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
2727
defer cancel()
2828

29-
cmd := exec.CommandContext(ctx, "../../bin/lstk", "logout")
29+
cmd := exec.CommandContext(ctx, binaryPath(), "logout")
3030
output, err := cmd.CombinedOutput()
3131

3232
require.NoError(t, err, "lstk logout failed: %s", output)
@@ -44,7 +44,7 @@ func TestLogoutCommandSucceedsWhenNoToken(t *testing.T) {
4444
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
4545
defer cancel()
4646

47-
cmd := exec.CommandContext(ctx, "../../bin/lstk", "logout")
47+
cmd := exec.CommandContext(ctx, binaryPath(), "logout")
4848
output, err := cmd.CombinedOutput()
4949

5050
// Should succeed even if no token

test/integration/main_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ package integration_test
22

33
import (
44
"context"
5+
"runtime"
56
"testing"
67

78
"github.com/docker/docker/client"
89
)
910

11+
func binaryPath() string {
12+
if runtime.GOOS == "windows" {
13+
return "../../bin/lstk.exe"
14+
}
15+
return "../../bin/lstk"
16+
}
17+
1018
var dockerClient *client.Client
1119
var dockerAvailable bool
1220

test/integration/start_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestStartCommandSucceedsWithValidToken(t *testing.T) {
4444
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
4545
defer cancel()
4646

47-
cmd := exec.CommandContext(ctx, "../../bin/lstk", "start")
47+
cmd := exec.CommandContext(ctx, binaryPath(), "start")
4848
cmd.Env = append(os.Environ(), "LOCALSTACK_AUTH_TOKEN="+authToken)
4949
output, err := cmd.CombinedOutput()
5050

@@ -63,7 +63,7 @@ func TestStartCommandTriggersLoginWithoutToken(t *testing.T) {
6363
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
6464
defer cancel()
6565

66-
cmd := exec.CommandContext(ctx, "../../bin/lstk", "start")
66+
cmd := exec.CommandContext(ctx, binaryPath(), "start")
6767
cmd.Env = envWithoutAuthToken()
6868

6969
// Capture output asynchronously
@@ -108,7 +108,7 @@ func TestStartCommandSucceedsWithKeyringToken(t *testing.T) {
108108
defer cancel()
109109

110110
// Run without LOCALSTACK_AUTH_TOKEN should use keyring
111-
cmd := exec.CommandContext(ctx, "../../bin/lstk", "start")
111+
cmd := exec.CommandContext(ctx, binaryPath(), "start")
112112
cmd.Env = envWithoutAuthToken()
113113
output, err := cmd.CombinedOutput()
114114

@@ -127,7 +127,7 @@ func TestStartCommandFailsWithInvalidToken(t *testing.T) {
127127
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
128128
defer cancel()
129129

130-
cmd := exec.CommandContext(ctx, "../../bin/lstk", "start")
130+
cmd := exec.CommandContext(ctx, binaryPath(), "start")
131131
cmd.Env = append(os.Environ(), "LOCALSTACK_AUTH_TOKEN=invalid-token")
132132
output, err := cmd.CombinedOutput()
133133

0 commit comments

Comments
 (0)