github.com/openshift-online/ocm-sdk-go@v0.1.420/database/error_code_test.go (about) 1 /* 2 Copyright (c) 2021 Red Hat, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package database 18 19 import ( 20 "io" 21 22 . "github.com/onsi/ginkgo/v2/dsl/table" // nolint 23 . "github.com/onsi/gomega" // nolint 24 25 "github.com/jackc/pgconn" 26 "github.com/lib/pq" 27 ) 28 29 var _ = DescribeTable( 30 "Error code extraction", 31 func(err error, expected string) { 32 actual := ErrorCode(err) 33 Expect(actual).To(Equal(expected)) 34 }, 35 Entry( 36 "Nil", 37 nil, 38 "", 39 ), 40 Entry( 41 "From 'pq'", 42 &pq.Error{ 43 Code: "123", 44 }, 45 "123", 46 ), 47 Entry( 48 "From 'pgconn'", 49 &pgconn.PgError{ 50 Code: "123", 51 }, 52 "123", 53 ), 54 Entry( 55 "Non SQL error", 56 io.EOF, 57 "", 58 ), 59 )