github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/errorutil/error_test.go (about) 1 // Copyright 2017 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package errorutil 12 13 import ( 14 "fmt" 15 "strings" 16 "testing" 17 ) 18 19 // Renumber lines so they're stable no matter what changes above. (We 20 // could make the regexes accept any string of digits, but we also 21 // want to make sure that the correct line numbers get captured). 22 // 23 //line error_test.go:1000 24 25 func TestUnexpectedWithIssueErrorf(t *testing.T) { 26 err := UnexpectedWithIssueErrorf(1234, "args: %d %s %f", 1, "two", 3.0) 27 exp := "unexpected error: args: 1 two 3.000000" 28 if err.Error() != exp { 29 t.Errorf("expected message:\n %s\ngot:\n %s", exp, err.Error()) 30 } 31 32 safeMsg := fmt.Sprintf("%+v", err) 33 reqHint := "We've been trying to track this particular issue down. Please report your " + 34 "reproduction at https://github.com/cockroachdb/cockroach/issues/1234 unless " + 35 "that issue seems to have been resolved (in which case you might want to " + 36 "update crdb to a newer version)." 37 if !strings.Contains(safeMsg, reqHint) { 38 t.Errorf("expected substring in error\n%s\ngot:\n%s", exp, safeMsg) 39 } 40 41 // Check that the issue number is present in the safe details. 42 exp = "4 safe details enclosed" 43 if !strings.Contains(safeMsg, exp) { 44 t.Errorf("expected substring in error\n%s\ngot:\n%s", exp, safeMsg) 45 } 46 }