Add comprehensive test suite #17
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "dev"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
flag.Parse()frominit()tomain()in both server and client (idiomatic Go, enables same-package testing)internal/list(96.6%),internal/shared(91.4%),cmd/cert-proxy-server(62%),cmd/cert-proxy-client/cert(88.5%),cmd/cert-proxy-client/worker(97.1%)stretchr/testifyfor readable assertionsIntegration tests
Run by default with
go test ./.... Skip with-tags skip_integration.Test plan
go test ./...passesgo test -tags skip_integration ./...skips integration testsgo vet ./...cleanUnit tests for all packages: - internal/list: UniqStrings, OrderedStrings, AddItemsFromReader/File - internal/shared: Mkdir, CertPool, TLS{Client,Server}Config - cmd/cert-proxy-server: authn, authz, serve, cnList, use() chain - cmd/cert-proxy-client/cert: NewReq, Execute (download, symlink, IMS, force, hooks, permissions), Format flag - cmd/cert-proxy-client/worker: Pool lifecycle, error propagation Integration tests (run by default, skip with -tags skip_integration): - Binary -help and -version flags - End-to-end PEM download via mutual TLS - Force mode (re-download) - Auto mode (multi-domain) - Direct API tests (list, cert, privkey auth, 304 responses) Uses stretchr/testify for readable assertions.AI-Generated Review
Overall: Good PR, ready to merge with minor observations.
The refactoring of
flag.Parse()frominit()tomain()is the idiomatic Go pattern and correctly unblocks same-package testing. The test suite is well-structured with proper teardown viat.Cleanup, good use ofhttptest, and a solid integration suite that exercises the full mTLS flow end-to-end.Coverage of 78.6% is reasonable for a first pass. Tests pass cleanly.
Summary of inline comments:
go.sumand won't build in isolationsaveGlobals()(transport save/restore never needed)t.Parallel()useopensslgeneration path (acceptable, just noting)Verdict: Approve with optional squash.
This review was AI-generated using Claude Code.
@ -0,0 +68,4 @@func saveGlobals(t *testing.T) {t.Helper()[ai] Fixed in
bacaf0c: added a comment documenting thatsaveGlobals()must not be used witht.Parallel()due to shared globals. Full parallel support awaits refactoringUseSymlink/Forceinto an options struct passed toExecute().@ -0,0 +76,4 @@UseSymlink = origSymlinkForce = origForcehttp.DefaultClient.Transport = origTransport})origTransportis saved and restored here but never actually mutated by any test — the tests usehttptest.NewServerwhich works with the real default transport. This save/restore is dead code.Also note:
UseSymlinkandForceare mutated without synchronization. Fine sincego testruns package tests sequentially by default, but addingt.Parallel()later would cause races.[AI-generated]
@ai: please provide a fix for parallel tests
@ -0,0 +273,4 @@dir := filepath.Join(certbase, domain)require.NoError(t, os.MkdirAll(dir, 0755))require.NoError(t, os.WriteFile(filepath.Join(dir, "bundle.p12"), []byte("PKCS12DATA"), 0644))This test writes literal
"PKCS12DATA"and reads it back — it validates the routing/serving logic but not the realopenssl pkcs12bundle generation. That's a fine unit test boundary, just calling it out so coverage expectations are clear.[AI-generated]
@ -2,2 +2,4 @@go 1.26.2require github.com/stretchr/testify v1.11.1In the first commit this was marked
// indirect, which is incorrect since test files import testify directly. The second commit fixes it viago mod tidy. Consider squashing the two commits so the intermediate broken state doesn't exist in history.[AI-generated]
@ -0,0 +293,4 @@require.NoError(t, err, "first run failed: %s", string(out))fi1, _ := os.Stat(filepath.Join(outDir, "example.com", "cert.pem"))time.Sleep(1100 * time.Millisecond)The 1.1s sleep is needed for filesystem mtime granularity — acceptable tradeoff, just noting it makes this single test noticeably slower than the rest.
[AI-generated]
merged manually
Pull request closed