github.com/zchee/zap-cloudlogging@v0.0.0-20220819025602-19b026d3900e/error_report_test.go (about) 1 // Copyright 2022 The zap-cloudlogging Authors 2 // SPDX-License-Identifier: BSD-3-Clause 3 4 package zapcloudlogging 5 6 import ( 7 "strings" 8 "testing" 9 ) 10 11 func TestErrorReport(t *testing.T) { 12 t.Parallel() 13 14 got := ErrorReport(Caller(0)).Interface.(*reportContext) 15 16 if gotFile, wantFile := got.ReportLocation.File, "zap-cloudlogging/error_report_test.go"; !strings.Contains(gotFile, wantFile) { 17 t.Errorf("except contains got %s in %s", gotFile, wantFile) 18 } 19 if gotLine, wantLine := got.ReportLocation.Line, int64(14); gotLine != wantLine { 20 t.Errorf("except equal got %d in %d", gotLine, wantLine) 21 } 22 if gotFunc, wantFunc := got.ReportLocation.Function, "zap-cloudlogging.TestErrorReport"; !strings.Contains(gotFunc, wantFunc) { 23 t.Errorf("except contains got %s in %s", gotFunc, wantFunc) 24 } 25 } 26 27 func TestNewReportContext(t *testing.T) { 28 t.Parallel() 29 30 got := newReportContext(Caller(0)) 31 32 if gotFile, wantFile := got.ReportLocation.File, "zap-cloudlogging/error_report_test.go"; !strings.Contains(gotFile, wantFile) { 33 t.Fatalf("except contains got %s in %s", gotFile, wantFile) 34 } 35 if gotLine, wantLine := got.ReportLocation.Line, int64(30); gotLine != wantLine { 36 t.Fatalf("except equal got %d in %d", gotLine, wantLine) 37 } 38 if gotFunc, wantFunc := got.ReportLocation.Function, "zap-cloudlogging.TestNewReportContext"; !strings.Contains(gotFunc, wantFunc) { 39 t.Errorf("except contains got %s in %s", gotFunc, wantFunc) 40 } 41 }