Skip to content

refactor: inject k8s.Runner for testable orchestration (#25)#31

Merged
robbycochran merged 3 commits into
mainfrom
rc-fixup3
Jun 5, 2026
Merged

refactor: inject k8s.Runner for testable orchestration (#25)#31
robbycochran merged 3 commits into
mainfrom
rc-fixup3

Conversation

@robbycochran

@robbycochran robbycochran commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

Extract k8s.Runner interface and MockRunner for testable orchestration. All injectable functions now have tests. Closes #25.

Changes

k8s.Runner interface — mirrors all 11 methods on k8s.Client. Orchestration functions accept Runner instead of constructing clients internally. Variables renamed: nsRunner (namespaced) and clusterRunner (cluster-scoped).

k8s.MockRunner — records calls, returns prefix-matched responses/errors. Includes HasCall, CallCount helpers.

Tests added (12 new)

Function Tests What they verify
teardownK8s 2 Namespace not found skips deletes; full cleanup in order
deployRemote 5 Success flow (ns/CRD/RBAC/Helm/Route); Helm failure stops; CRD failure stops; no apps domain
ensureCreds 5 Namespace missing; secrets exist; force deletes; Atlassian created/skipped
deployLocal 1 No gateway returns error (via mockGW)

Test results

Path Result
Go unit tests 92/92
Launcher tests 7/7
Bats (both) 29/29

128 total tests (was 83 at session start).

Closes #25.

robbycochran and others added 2 commits June 5, 2026 01:19
Extract k8s.Runner interface from k8s.Client. Orchestration functions
(deployRemote, teardownK8s, ensureCreds, newRemote) now accept Runner
instead of constructing clients internally.

Add k8s.MockRunner — records calls with prefix-matched responses and
errors. Enables unit testing orchestration without a live cluster.

Add teardown_test.go with 2 tests:
- TestTeardownK8s_NamespaceNotFound: skips all deletes
- TestTeardownK8s_FullCleanup: verifies helm uninstall, CRD/SCC/
  secret/namespace deletes, gateway cleanup in correct order

Validated: unit 82+7, bats 29+29, Go+podman 19/19.

Closes #25.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
10 new tests using MockRunner:

deployRemote (5 tests):
- Success: verifies namespace, CRD, RBAC, Helm, rollout, Route in order
- Helm failure: stops before rollout
- CRD failure: stops before Helm
- No apps domain: returns error
- deployLocal with no gateway: returns error

ensureCreds (5 tests):
- Namespace not found: returns error
- Secrets already exist: no creation attempted
- Force mode: deletes both secrets
- Atlassian created: when JIRA_URL set
- Atlassian skipped: when JIRA_URL empty

Total: 92 Go harness + 7 launcher + 29 bats = 128 tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@robbycochran robbycochran merged commit bd49cad into main Jun 5, 2026
@robbycochran robbycochran deleted the rc-fixup3 branch June 13, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: make orchestration functions testable via dependency injection

1 participant