summaryrefslogtreecommitdiff
path: root/internal/cli/cli_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-14 10:27:29 +0300
committerPaul Buetow <paul@buetow.org>2026-04-14 10:27:29 +0300
commit74e1b8f37d318112d52e5a80f0f589f1b0cc7f34 (patch)
treec8dbdd3740b6e9f7f14620f549decafcefae5a02 /internal/cli/cli_test.go
parent254426152804be2a439a071d17478976089d2643 (diff)
test: microservice coverage for task 63
Add table-driven HTTP and unit tests for report (all formats, negatives), upload/auth boundaries, upload helpers, readiness, Run and logging. Extend authkeys tests for Close, CreateKey validation, and post-close errors. Add CLI tests for defaultListenFromEnv and create-client-key with -auth-db only. Add mage CoverMicroservice for local/CI-style coverage measurement. Use context.Background and os.Chdir for Go 1.21-compatible tests. Made-with: Cursor
Diffstat (limited to 'internal/cli/cli_test.go')
-rw-r--r--internal/cli/cli_test.go32
1 files changed, 31 insertions, 1 deletions
diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go
index ff7b046..a89fa50 100644
--- a/internal/cli/cli_test.go
+++ b/internal/cli/cli_test.go
@@ -118,7 +118,14 @@ func TestStableImportAndQuery(t *testing.T) {
func TestStableIntegrationTestSubcommand(t *testing.T) {
root := moduleRoot(t)
- t.Chdir(root)
+ cwd, err := os.Getwd()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Chdir(root); err != nil {
+ t.Fatal(err)
+ }
+ defer func() { _ = os.Chdir(cwd) }()
if err := Execute([]string{"test"}); err != nil {
t.Fatal(err)
}
@@ -174,3 +181,26 @@ func TestCreateClientKeyWritesToken(t *testing.T) {
t.Fatalf("token too short %q", tok)
}
}
+
+func TestDefaultListenFromEnv(t *testing.T) {
+ t.Setenv("GOPRECORDS_LISTEN", ":7777")
+ if defaultListenFromEnv() != ":7777" {
+ t.Fatalf("got %q", defaultListenFromEnv())
+ }
+ t.Setenv("GOPRECORDS_LISTEN", "")
+ if defaultListenFromEnv() != ":8080" {
+ t.Fatalf("default got %q", defaultListenFromEnv())
+ }
+}
+
+func TestCreateClientKeyWithAuthDBOnly(t *testing.T) {
+ db := filepath.Join(t.TempDir(), "keys.db")
+ out := captureStdout(t, func() {
+ if err := Execute([]string{"--create-client-key", "hostonly", "-auth-db", db}); err != nil {
+ t.Fatal(err)
+ }
+ })
+ if len(strings.TrimSpace(out)) < 20 {
+ t.Fatalf("token too short %q", out)
+ }
+}