github.com/confluentinc/confluent-kafka-go@v1.9.2/schemaregistry/serde/testhelpers.go (about) 1 /** 2 * Copyright 2022 Confluent 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 serde 18 19 import ( 20 "fmt" 21 "reflect" 22 "runtime" 23 "testing" 24 ) 25 26 // FailFunc is a function to call in case of failure 27 type FailFunc func(string, ...error) 28 29 // MaybeFail represents a fail function 30 var MaybeFail FailFunc 31 32 // InitFailFunc returns an initial fail function 33 func InitFailFunc(t *testing.T) FailFunc { 34 tester := t 35 return func(msg string, errors ...error) { 36 for _, err := range errors { 37 if err != nil { 38 pc := make([]uintptr, 1) 39 runtime.Callers(2, pc) 40 caller := runtime.FuncForPC(pc[0]) 41 _, line := caller.FileLine(caller.Entry()) 42 43 tester.Fatalf("%s:%d failed: %s %s", caller.Name(), line, msg, err) 44 } 45 } 46 } 47 } 48 49 // Expect compares the actual and expected values 50 func Expect(actual, expected interface{}) error { 51 if !reflect.DeepEqual(actual, expected) { 52 return fmt.Errorf("expected: %v, Actual: %v", expected, actual) 53 } 54 55 return nil 56 }