github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/raft_test.go (about) 1 // Copyright 2019 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 kvserver 12 13 import ( 14 "math" 15 "testing" 16 17 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 18 "github.com/cockroachdb/errors" 19 ) 20 21 // TestWrapNumbersAsSafe tests the wrapNumbersAsSafe through ReportablesToSafeError. 22 func TestWrapNumbersAsSafe(t *testing.T) { 23 defer leaktest.AfterTest(t)() 24 25 reportables := []interface{}{ 26 uint(math.MaxUint32), 27 uint8(math.MaxUint8), 28 uint16(math.MaxUint16), 29 uint32(math.MaxUint32), 30 uint64(math.MaxUint64), 31 32 int(math.MaxInt32), 33 int8(math.MaxInt8), 34 int16(math.MaxInt16), 35 int32(math.MaxInt32), 36 int64(math.MaxInt64), 37 38 float32(math.MaxFloat32), 39 float64(math.MaxFloat64), 40 41 "unsafe-string", 42 "123", 43 } 44 45 wrapNumbersAsSafe(reportables...) 46 const format = "some reportables" 47 err := errors.WithSafeDetails(leafErr{}, format, reportables...) 48 49 const expected = `<kvserver.leafErr> 50 wrapper: <*safedetails.withSafeDetails> 51 (more details:) 52 some reportables 53 -- arg 1: 4294967295 54 -- arg 2: 255 55 -- arg 3: 65535 56 -- arg 4: 4294967295 57 -- arg 5: 18446744073709551615 58 -- arg 6: 2147483647 59 -- arg 7: 127 60 -- arg 8: 32767 61 -- arg 9: 2147483647 62 -- arg 10: 9223372036854775807 63 -- arg 11: 3.4028235e+38 64 -- arg 12: 1.7976931348623157e+308 65 -- arg 13: <string> 66 -- arg 14: <string>` 67 68 if redacted := errors.Redact(err); expected != redacted { 69 t.Fatalf("expected error to be:\n%s\n\nbut was:\n%s", expected, redacted) 70 } 71 72 } 73 74 type leafErr struct{} 75 76 func (leafErr) Error() string { return "error" }