mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-07 13:51:36 +00:00
Bundle S CI follow-up #2: G-3 env-var collision + gopter discard-storm
Two CI failures from the previous Bundle S commits:
1. G-3 env-var docs drift guard caught three test-only env vars in
cmd/agent/dispatch_test.go that started with CERTCTL_:
CERTCTL_NONEXISTENT_TEST_VAR / CERTCTL_TEST_VAR / CERTCTL_BOOL_TEST
Renamed to TESTONLY_AGENT_* — the getEnvDefault / getEnvBoolDefault
tests don't depend on the CERTCTL_ namespace; they validate the
helpers' fallback behavior with arbitrary keys.
2. TestProperty_WrongPassphraseRejected gave up under -race after
'26 passed, 132 discarded'. Root cause: gen.AlphaString().SuchThat(
len(s)>0 && len(s)<64) rejected too many cases; gopter's discard
threshold tripped before MinSuccessfulTests (30) was reached.
Same issue in the round-trip property.
Fix: drop SuchThat on both crypto property tests; sanitize length
INSIDE the predicate (substitute 'default-key' for empty; truncate
strings >50 chars). Result: 0 discards. Both tests pass cleanly
in 11.9s without -race.
Verification
- go test -short -count=1 ./cmd/agent/... PASS (no test-name
surprises)
- go test -count=1 -timeout=120s -run='TestProperty_' ./internal/
crypto/... PASS in 11.9s
Bundle: S-ci-fix-2
This commit is contained in:
+12
-12
@@ -420,16 +420,16 @@ func TestAgent_MarkRetired_ClosesSignalOnce(t *testing.T) {
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
func TestGetEnvDefault_FallsBackToDefault(t *testing.T) {
|
||||
t.Setenv("CERTCTL_NONEXISTENT_TEST_VAR", "")
|
||||
got := getEnvDefault("CERTCTL_NONEXISTENT_TEST_VAR", "fallback")
|
||||
t.Setenv("TESTONLY_AGENT_NONEXISTENT_VAR", "")
|
||||
got := getEnvDefault("TESTONLY_AGENT_NONEXISTENT_VAR", "fallback")
|
||||
if got != "fallback" {
|
||||
t.Errorf("expected fallback, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEnvDefault_UsesEnvWhenSet(t *testing.T) {
|
||||
t.Setenv("CERTCTL_TEST_VAR", "from-env")
|
||||
got := getEnvDefault("CERTCTL_TEST_VAR", "fallback")
|
||||
t.Setenv("TESTONLY_AGENT_VAR", "from-env")
|
||||
got := getEnvDefault("TESTONLY_AGENT_VAR", "fallback")
|
||||
if got != "from-env" {
|
||||
t.Errorf("expected from-env, got %q", got)
|
||||
}
|
||||
@@ -438,8 +438,8 @@ func TestGetEnvDefault_UsesEnvWhenSet(t *testing.T) {
|
||||
func TestGetEnvBoolDefault_TruthyValues(t *testing.T) {
|
||||
for _, v := range []string{"1", "t", "true", "yes", "on", "TRUE", "True"} {
|
||||
t.Run(v, func(t *testing.T) {
|
||||
t.Setenv("CERTCTL_BOOL_TEST", v)
|
||||
if !getEnvBoolDefault("CERTCTL_BOOL_TEST", false) {
|
||||
t.Setenv("TESTONLY_AGENT_BOOL", v)
|
||||
if !getEnvBoolDefault("TESTONLY_AGENT_BOOL", false) {
|
||||
t.Errorf("expected true for %q", v)
|
||||
}
|
||||
})
|
||||
@@ -449,8 +449,8 @@ func TestGetEnvBoolDefault_TruthyValues(t *testing.T) {
|
||||
func TestGetEnvBoolDefault_FalsyValues(t *testing.T) {
|
||||
for _, v := range []string{"0", "f", "false", "no", "off"} {
|
||||
t.Run(v, func(t *testing.T) {
|
||||
t.Setenv("CERTCTL_BOOL_TEST", v)
|
||||
if getEnvBoolDefault("CERTCTL_BOOL_TEST", true) {
|
||||
t.Setenv("TESTONLY_AGENT_BOOL", v)
|
||||
if getEnvBoolDefault("TESTONLY_AGENT_BOOL", true) {
|
||||
t.Errorf("expected false for %q", v)
|
||||
}
|
||||
})
|
||||
@@ -458,15 +458,15 @@ func TestGetEnvBoolDefault_FalsyValues(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetEnvBoolDefault_UnrecognizedReturnsDefault(t *testing.T) {
|
||||
t.Setenv("CERTCTL_BOOL_TEST", "frobnicate")
|
||||
if !getEnvBoolDefault("CERTCTL_BOOL_TEST", true) {
|
||||
t.Setenv("TESTONLY_AGENT_BOOL", "frobnicate")
|
||||
if !getEnvBoolDefault("TESTONLY_AGENT_BOOL", true) {
|
||||
t.Errorf("expected default(true) for unrecognized value")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEnvBoolDefault_EmptyReturnsDefault(t *testing.T) {
|
||||
t.Setenv("CERTCTL_BOOL_TEST", "")
|
||||
if !getEnvBoolDefault("CERTCTL_BOOL_TEST", true) {
|
||||
t.Setenv("TESTONLY_AGENT_BOOL", "")
|
||||
if !getEnvBoolDefault("TESTONLY_AGENT_BOOL", true) {
|
||||
t.Errorf("expected default(true) for empty value")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user