Skip to content

Commit 76082a5

Browse files
committed
test(recipe): assert optional context keys are absent, not nil-valued
Signed-off-by: Brian Lockwood <lockwobr@gmail.com>
1 parent e70aaaa commit 76082a5

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

pkg/recipe/coverage_subsumption_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,11 @@ func TestStrictGapErrorRendering(t *testing.T) {
270270
// excludedOverlays / constraintWarnings are attached verbatim, and
271271
// absent rather than empty when there is nothing to report.
272272
if tt.excluded == nil {
273-
if se.Context["excludedOverlays"] != nil {
274-
t.Errorf("excludedOverlays = %#v, want absent", se.Context["excludedOverlays"])
273+
// Two-value lookup: a key present but holding nil is a
274+
// different wire shape from an absent key, and `!= nil`
275+
// cannot tell them apart.
276+
if v, present := se.Context["excludedOverlays"]; present {
277+
t.Errorf("excludedOverlays = %#v, want the key absent", v)
275278
}
276279
} else if got, ok := se.Context["excludedOverlays"].([]ExcludedOverlay); !ok {
277280
t.Errorf("excludedOverlays = %#v, want []ExcludedOverlay", se.Context["excludedOverlays"])
@@ -280,8 +283,8 @@ func TestStrictGapErrorRendering(t *testing.T) {
280283
}
281284

282285
if tt.warnings == nil {
283-
if se.Context["constraintWarnings"] != nil {
284-
t.Errorf("constraintWarnings = %#v, want absent", se.Context["constraintWarnings"])
286+
if v, present := se.Context["constraintWarnings"]; present {
287+
t.Errorf("constraintWarnings = %#v, want the key absent", v)
285288
}
286289
} else if got, ok := se.Context["constraintWarnings"].([]ConstraintWarning); !ok {
287290
t.Errorf("constraintWarnings = %#v, want []ConstraintWarning", se.Context["constraintWarnings"])

0 commit comments

Comments
 (0)