Skip to content

Commit ac8ad3e

Browse files
committed
Use Go for integration tests; test output exactly
1 parent d4f0f09 commit ac8ad3e

22 files changed

+524
-78
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ jobs:
5656
uses: golangci/golangci-lint-action@v3
5757
with:
5858
version: v1.59
59+
60+
- name: Run tests
61+
run: make test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ php-*
44
!internal/legacy/archives/windows_php.ini.tpl
55
completion
66

7+
# Executable built with `go build ./cmd/platform` (or `make build`)
8+
/platform
9+
710
# Binaries for programs and plugins
811
*.exe
912
*.exe~

.gitlab-ci.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ stages:
22
- check
33
- php
44
- build
5-
- behave-test
5+
- integration-test
66
- release
77

88
.go-cache:
@@ -127,18 +127,14 @@ build:
127127
- dist/
128128
expire_in: 1 day
129129

130-
behave-test-linux:
131-
stage: behave-test
130+
integration-test-linux:
131+
stage: integration-test
132+
image: cimg/go:1.22
133+
extends: .go-cache
132134
dependencies:
133135
- build
134-
variables:
135-
PATH_CLI: platform_linux_amd64_v1/platform
136-
before_script:
137-
- apt-get install -y python3 python3-pip
138-
- pip3 install --no-cache-dir behave sh selenium requests
139-
script:
140-
- bash tests/test-behave.sh
141-
image: pjcdawkins/platformsh-cli
136+
script: |
137+
TEST_CLI_PATH=$PWD/dist/platform_linux_amd64_v1/platform go test -failfast -mod=readonly -v ./tests/integration/...
142138
143139
release:
144140
stage: release
@@ -152,7 +148,7 @@ release:
152148
- make release
153149
dependencies:
154150
- unit-test-lint
155-
- behave-test-linux
151+
- integration-test-linux
156152
- build-php-linux-arm
157153
- build-php-linux-x86
158154
- build-php-macos-arm

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ php: $(PHP_BINARY_PATH)
6262

6363
.PHONY: goreleaser
6464
goreleaser:
65-
go install github.com/goreleaser/goreleaser@$(GORELEASER_VERSION)
65+
command -v goreleaser >/dev/null || go install github.com/goreleaser/goreleaser@$(GORELEASER_VERSION)
6666

6767
.PHONY: single
6868
single: goreleaser internal/legacy/archives/platform.phar php ## Build a single target release for Platform.sh or Upsun
@@ -83,11 +83,17 @@ release: goreleaser clean-phar internal/legacy/archives/platform.phar php ## Rel
8383

8484
.PHONY: test
8585
test: ## Run unit tests
86-
go clean -testcache
8786
go test -v -race -mod=readonly -cover ./...
8887

88+
platform: internal/legacy/archives/platform.phar php
89+
go build ./cmd/platform
90+
91+
.PHONY: integration-test
92+
integration-test: platform
93+
TEST_CLI_PATH="$(PWD)/platform" go test -failfast -mod=readonly -v ./tests/integration/...
94+
8995
golangci-lint:
90-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
96+
command -v golangci-lint >/dev/null || go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
9197

9298
.PHONY: lint
9399
lint: golangci-lint ## Run linter

commands/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ func newRootCommand(cnf *config.Config, assets *vendorization.VendorAssets) *cob
5757
viper.Set("no-interaction", true)
5858
cmd.SetErr(io.Discard)
5959
}
60+
if cnf.Application.Version != "" {
61+
version = cnf.Application.Version
62+
}
6063
if viper.GetBool("version") {
6164
versionCommand.Run(cmd, []string{})
6265
os.Exit(0)

internal/config/schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Config struct {
2929
UserStateFile string `validate:"omitempty" yaml:"user_state_file"` // defaults to "state.json"
3030
WritableUserDir string `validate:"omitempty" yaml:"writable_user_dir"` // defaults to UserConfigDir
3131
TempSubDir string `validate:"omitempty" yaml:"tmp_sub_dir"` // defaults to Slug+"-tmp"
32+
Version string `validate:"omitempty"` // defaults to version variable set by GoReleaser
3233
} `validate:"required"`
3334
Updates struct {
3435
Check bool `validate:"omitempty"` // defaults to true

scripts/generate_test_data.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
set -e
6+
cd "$DIR/.."
7+
make clean-phar platform
8+
export data_dir="$(realpath tests/integration/data)"
9+
export TEST_CLI_PATH="$(realpath ./platform)"
10+
export CLI_CONFIG_FILE="$data_dir/config.yaml"
11+
export TEST_CLI_NO_INTERACTION=1
12+
13+
# Clear the working directory to avoid this repository being detected as a "project".
14+
cd /
15+
echo "Using command: $TEST_CLI_PATH"
16+
"$TEST_CLI_PATH" version
17+
for c in help list version 'help list' 'help create'; do
18+
export filename="$data_dir"/"$c".stdout.txt
19+
echo "Generating $filename"
20+
COLUMNS=120 "$TEST_CLI_PATH" $c > "$filename"
21+
done

tests/features/basics.feature

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/features/projects.feature

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/features/steps/cli.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)