From 74e1b8f37d318112d52e5a80f0f589f1b0cc7f34 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 14 Apr 2026 10:27:29 +0300 Subject: 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 --- internal/cli/cli_test.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'internal/cli/cli_test.go') 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) + } +} -- cgit v1.2.3