github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/pgwire/pgerror/severity_test.go (about) 1 // Copyright 2020 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 pgerror 12 13 import ( 14 "fmt" 15 "testing" 16 17 "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" 18 "github.com/cockroachdb/errors" 19 "github.com/stretchr/testify/require" 20 ) 21 22 func TestSeverity(t *testing.T) { 23 testCases := []struct { 24 err error 25 expectedSeverity string 26 }{ 27 {WithSeverity(fmt.Errorf("notice me"), "NOTICE ME"), "NOTICE ME"}, 28 {WithSeverity(WithSeverity(fmt.Errorf("notice me"), "IGNORE ME"), "NOTICE ME"), "NOTICE ME"}, 29 {WithSeverity(WithCandidateCode(fmt.Errorf("notice me"), pgcode.FeatureNotSupported), "NOTICE ME"), "NOTICE ME"}, 30 {New(pgcode.Uncategorized, "i am an error"), "ERROR"}, 31 {WithCandidateCode(WithSeverity(errors.Newf("i am not an error"), "NOT AN ERROR"), pgcode.System), "NOT AN ERROR"}, 32 {fmt.Errorf("something else"), "ERROR"}, 33 } 34 35 for _, tc := range testCases { 36 t.Run(tc.err.Error(), func(t *testing.T) { 37 severity := GetSeverity(tc.err) 38 require.Equal(t, tc.expectedSeverity, severity) 39 }) 40 } 41 }