github.com/letsencrypt/boulder@v0.20251208.0/errors/errors_test.go (about) 1 package errors 2 3 import ( 4 "testing" 5 6 "github.com/letsencrypt/boulder/identifier" 7 "github.com/letsencrypt/boulder/test" 8 ) 9 10 // TestWithSubErrors tests that a boulder error can be created by adding 11 // suberrors to an existing top level boulder error 12 func TestWithSubErrors(t *testing.T) { 13 topErr := &BoulderError{ 14 Type: RateLimit, 15 Detail: "don't you think you have enough certificates already?", 16 } 17 18 subErrs := []SubBoulderError{ 19 { 20 Identifier: identifier.NewDNS("example.com"), 21 BoulderError: &BoulderError{ 22 Type: RateLimit, 23 Detail: "everyone uses this example domain", 24 }, 25 }, 26 { 27 Identifier: identifier.NewDNS("what about example.com"), 28 BoulderError: &BoulderError{ 29 Type: RateLimit, 30 Detail: "try a real identifier value next time", 31 }, 32 }, 33 } 34 35 outResult := topErr.WithSubErrors(subErrs) 36 // The outResult should be a new, distinct error 37 test.AssertNotEquals(t, topErr, outResult) 38 // The outResult error should have the correct sub errors 39 test.AssertDeepEquals(t, outResult.SubErrors, subErrs) 40 // Adding another suberr shouldn't squash the original sub errors 41 anotherSubErr := SubBoulderError{ 42 Identifier: identifier.NewDNS("another ident"), 43 BoulderError: &BoulderError{ 44 Type: RateLimit, 45 Detail: "another rate limit err", 46 }, 47 } 48 outResult = outResult.WithSubErrors([]SubBoulderError{anotherSubErr}) 49 test.AssertDeepEquals(t, outResult.SubErrors, append(subErrs, anotherSubErr)) 50 }