Skip to content

Commit 03aedf4

Browse files
committed
test(cmd): drop devel build tag, add upgrade integration tests
The devel tag no longer changed any build (version_devel.go was removed earlier), it only gated the integration tests out of the normal suite. Drop it entirely: remove //go:build devel from the harness and integration tests, the -tags devel flags from the Makefile and CI, and the related doc mentions. Add in-process integration tests for `zcli upgrade` covering --check (0/1/2), explicit --version, and the already-up-to-date path, driven through the harness with the version API stubbed via ZEROPS_VERSION_API_URL. Un-tagging exposed pre-existing lint debt in the test files (these were never linted before): drop the unused ctx param from the harness Run (clearing the nil-context hits), use exec.CommandContext, and exclude musttag for _test.go (tests marshal internal persisted structs that rely on default JSON keys).
1 parent 6481fb8 commit 03aedf4

15 files changed

Lines changed: 122 additions & 77 deletions

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
go-version-file: "go.mod"
4040

4141
- name: test-integration
42-
run: go test -v -tags devel ./src/cmd/...
42+
run: go test -v ./src/cmd/...
4343

4444
lint:
4545
name: lint

.golangci.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ linters:
9595
- linters: [staticcheck]
9696
path: src/cmdRunner/run.go
9797
text: "ST1005:"
98+
# Integration tests marshal internal persisted structs (e.g.
99+
# cliStorage.Data) to seed on-disk state. Those types intentionally rely
100+
# on Go's default field-name JSON keys, so don't require explicit tags.
101+
- linters: [musttag]
102+
path: _test\.go$
98103

99104
issues:
100105
max-same-issues: 0

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
1010

1111
- `make test` — runs `go test -v ./cmd/... ./src/...`. Run a single test with `go test -v -run TestName ./src/<pkg>/...`.
1212
- `make lint` — runs the pinned `./bin/golangci-lint` for darwin/arm64, linux/amd64, and windows/amd64. Config: `.golangci.yaml`.
13-
- `make build-dev` — build a dev binary for the host into `./bin/zcli` (build tag `devel`, debug-friendly via `-gcflags='all=-l -N'`, version injected from git).
14-
- `make all` — cross-builds dev binaries for windows-amd, linux-amd, darwin-amd, darwin-arm. Single-target builds: `make linux-amd` etc. All build targets share the `DEV_BUILD` recipe in the Makefile (version metadata, devel tag, gcflags).
13+
- `make build-dev` — build a dev binary for the host into `./bin/zcli` (debug-friendly via `-gcflags='all=-l -N'`, version injected from git).
14+
- `make all` — cross-builds dev binaries for windows-amd, linux-amd, darwin-amd, darwin-arm. Single-target builds: `make linux-amd` etc. All build targets share the `DEV_BUILD` recipe in the Makefile (version metadata, gcflags).
1515
- `make install` — production install into `~/.local/bin/zcli` (same path as the public `install.sh` script). Stripped/optimized, version from `git describe`, same flag set as `.goreleaser.yaml`.
1616
- `make install-dev` — installs to `$GOBIN` (or `$GOPATH/bin`) as `zcli-dev` so it sits with other Go dev tools and coexists on PATH with a production `zcli`.
1717
- `make goreleaser-check` / `make goreleaser-snapshot` — validate `.goreleaser.yaml` and dry-run a release build to `./dist`.

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ DEV_INSTALL_DIR := $(or $(shell go env GOBIN),$(shell go env GOPATH)/bin)
2222
# Dev-build version metadata (matches what tools/build.sh used to compose).
2323
DEV_VERSION := $(shell git rev-parse --abbrev-ref HEAD):$(shell git describe --tags 2>/dev/null)-($(shell git config --get user.name):<$(shell git config --get user.email)>)
2424
# -gcflags disables inlining and optimizations so the binary is dlv-friendly.
25-
DEV_BUILD := go build -tags devel \
25+
DEV_BUILD := go build \
2626
-gcflags='all=-l -N' \
2727
-ldflags='-X "github.com/zeropsio/zcli/src/version.version=$(DEV_VERSION)"'
2828

@@ -44,8 +44,8 @@ help: ## Show this help.
4444
test: ## Run the full Go test suite.
4545
go test -v ./cmd/... ./src/...
4646

47-
test-integration: ## Run the integration test suite (devel build tag).
48-
go test -v -tags devel ./src/cmd/...
47+
test-integration: ## Run just the in-process integration tests (src/cmd).
48+
go test -v ./src/cmd/...
4949

5050
# Lint each target GOOS in turn so platform-specific build tags get covered.
5151
lint: $(BIN)/.golangci-lint-$(GOLANGCI_LINT_VERSION) ## Run golangci-lint for darwin/arm64, linux/amd64, windows/amd64.
@@ -55,7 +55,7 @@ lint: $(BIN)/.golangci-lint-$(GOLANGCI_LINT_VERSION) ## Run golangci-lint for da
5555

5656
##@ Build
5757

58-
build-dev: ## Build a dev binary for the host into ./bin/zcli (devel tag, no optimizations).
58+
build-dev: ## Build a dev binary for the host into ./bin/zcli (no optimizations, dlv-friendly).
5959
$(DEV_BUILD) -o $(BIN)/zcli ./cmd/zcli
6060

6161
all: windows-amd linux-amd darwin-amd darwin-arm ## Cross-build all dev targets.
@@ -79,7 +79,7 @@ install: ## Build a production zcli (stripped, optimized) and install it into ~/
7979
$(PROD_BUILD) -o $(PROD_INSTALL_DIR)/zcli ./cmd/zcli
8080
@echo "installed $(PROD_INSTALL_DIR)/zcli ($(PROD_VERSION))"
8181

82-
install-dev: ## Build a dev zcli-dev (devel tag, debug-friendly) and install it into $GOBIN.
82+
install-dev: ## Build a dev zcli-dev (debug-friendly) and install it into $GOBIN.
8383
$(DEV_BUILD) -o $(DEV_INSTALL_DIR)/zcli-dev ./cmd/zcli
8484
@echo "installed $(DEV_INSTALL_DIR)/zcli-dev"
8585

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Common targets (run `make help` for the full list):
144144

145145
| Target | What it does |
146146
|---|---|
147-
| `make build-dev` | Build `./bin/zcli` with the `devel` tag, no optimizations (dlv-friendly). |
147+
| `make build-dev` | Build `./bin/zcli` with no optimizations (dlv-friendly). |
148148
| `make install` | Build a production `zcli` and install to `~/.local/bin` (same path as `install.sh`). |
149149
| `make install-dev` | Install a `zcli-dev` binary into `$GOBIN` (or `$GOPATH/bin`). |
150150
| `make test` | Run the full Go test suite. |

src/cmd/integration_harness_test.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
//go:build devel
2-
31
// Shared scaffolding for the package's integration tests.
42
//
5-
// All integration tests build under the `devel` build tag (so the
6-
// production-version-check HTTP call from src/version is stubbed to a no-op)
7-
// and run via `make test-integration`. They drive the CLI in-process through
8-
// cmdBuilder.RunRootCmd, point the REST client at an httptest.Server, and
9-
// isolate per-test state by setting ZEROPS_CLI_DATA_FILE_PATH,
10-
// ZEROPS_CLI_LOG_FILE_PATH, and ZEROPS_CLI_YAML_FILE_PATH to per-test temp
11-
// files. yamlReader's package-level cache is reset before and after each test.
12-
// See pushDeploy_helpers_test.go for push/deploy-specific helpers.
3+
// Integration tests drive the CLI in-process through cmdBuilder.RunRootCmd,
4+
// point the REST client at an httptest.Server, and isolate per-test state by
5+
// setting ZEROPS_CLI_DATA_FILE_PATH, ZEROPS_CLI_LOG_FILE_PATH, and
6+
// ZEROPS_CLI_YAML_FILE_PATH to per-test temp files. ZEROPS_VERSION_API_URL is
7+
// pointed at the test server so the background version check never reaches the
8+
// real API. yamlReader's package-level cache is reset before and after each
9+
// test. See pushDeploy_helpers_test.go for push/deploy-specific helpers.
1310

1411
package cmd
1512

@@ -63,6 +60,9 @@ func newFixture(t *testing.T) *fixture {
6360
t.Setenv(constants.CliLogFilePathEnvVar, logPath)
6461
t.Setenv(constants.CliZcliYamlFilePathEnvVar, yamlPath)
6562
t.Setenv(constants.CliTokenEnvVar, "")
63+
// Keep the background version check off the real network. Tests that
64+
// exercise the version API re-point this at a registered handler.
65+
t.Setenv(constants.VersionApiUrlEnvVar, server.URL+"/__version_check__")
6666

6767
return &fixture{
6868
t: t,
@@ -117,13 +117,16 @@ type result struct {
117117
ExitCode int
118118
}
119119

120-
// Run executes the CLI in-process with the given args. ctx defaults to
121-
// context.Background() when nil.
122-
func (f *fixture) Run(ctx context.Context, args ...string) result {
120+
// Run executes the CLI in-process with the given args, using the test's
121+
// context. Use RunCtx when a specific (e.g. canceled) context is needed.
122+
func (f *fixture) Run(args ...string) result {
123+
f.t.Helper()
124+
return f.RunCtx(f.t.Context(), args...)
125+
}
126+
127+
// RunCtx is Run with an explicit context.
128+
func (f *fixture) RunCtx(ctx context.Context, args ...string) result {
123129
f.t.Helper()
124-
if ctx == nil {
125-
ctx = context.Background()
126-
}
127130
var stdout, stderr bytes.Buffer
128131
code := cmdBuilder.RunRootCmd(
129132
ctx,

src/cmd/login_integration_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build devel
2-
31
package cmd
42

53
import (
@@ -33,7 +31,7 @@ func TestLoginCommand_PersistsTokenAndRegion(t *testing.T) {
3331
"fullName": "Test User",
3432
})
3533

36-
res := f.Run(nil, "login", "secret-token", "--region-url", f.Server.URL+"/regions")
34+
res := f.Run("login", "secret-token", "--region-url", f.Server.URL+"/regions")
3735

3836
require.Equalf(t, 0, res.ExitCode, "stderr=%q", res.Stderr)
3937
assert.Contains(t, res.Stderr, "Test User", "success message should name the user")

src/cmd/projectList_integration_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build devel
2-
31
package cmd
42

53
import (
@@ -51,7 +49,7 @@ func TestProjectListCommand(t *testing.T) {
5149
}},
5250
})
5351

54-
res := f.Run(nil, "project", "list")
52+
res := f.Run("project", "list")
5553

5654
require.Equalf(t, 0, res.ExitCode, "stderr=%q", res.Stderr)
5755
for _, want := range []string{"demo-project", "Acme Org", "00000000-0000-0000-0000-0000000000bb"} {

src/cmd/pushDeploy_bugs_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build devel
2-
31
package cmd
42

53
// This file collects integration regression tests that pin previously
@@ -34,7 +32,6 @@ func TestServicePushCommand_SetupFlagOverridesAutoMatch(t *testing.T) {
3432
s := registerPushStubs(t, f, "backend")
3533

3634
res := f.Run(
37-
nil,
3835
"service", "push",
3936
"--service-id", pushServiceID,
4037
"--working-dir", workDir,
@@ -166,7 +163,6 @@ func TestServicePushCommand_RunningProcessWithNullAppVersionNoCrash(t *testing.T
166163
// the null AppVersion and the second poll's FINISHED status completes
167164
// the push.
168165
res := f.Run(
169-
nil,
170166
"service", "push",
171167
"--service-id", pushServiceID,
172168
"--working-dir", workDir,

src/cmd/pushDeploy_helpers_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build devel
2-
31
package cmd
42

53
import (

0 commit comments

Comments
 (0)