github.com/zchee/zap-cloudlogging@v0.0.0-20220819025602-19b026d3900e/source_location_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 TestSourceLocation(t *testing.T) { 12 t.Parallel() 13 14 got := SourceLocation(Caller(0)).Interface.(*sourceLocation) 15 16 if gotFile, wantFile := got.File, "zap-cloudlogging/source_location_test.go"; !strings.Contains(gotFile, wantFile) { 17 t.Errorf("except contains got %s in %s", gotFile, wantFile) 18 } 19 if gotLine, wantLine := got.Line, int64(14); gotLine != wantLine { 20 t.Errorf("except equal got %d in %d", gotLine, wantLine) 21 } 22 if gotFunc, wantFunc := got.Function, "zap-cloudlogging.TestSourceLocation"; !strings.Contains(gotFunc, wantFunc) { 23 t.Errorf("except contains got %s in %s", gotFunc, wantFunc) 24 } 25 } 26 27 func TestNewSource(t *testing.T) { 28 t.Parallel() 29 30 got := newSource(Caller(0)) 31 32 if gotFile, wantFile := got.File, "zap-cloudlogging/source_location_test.go"; !strings.Contains(gotFile, wantFile) { 33 t.Fatalf("except contains got %s in %s", gotFile, wantFile) 34 } 35 if gotLine, wantLine := got.Line, int64(30); gotLine != wantLine { 36 t.Errorf("except equal got %d in %d", gotLine, wantLine) 37 } 38 if gotFunc, wantFunc := got.Function, "zap-cloudlogging.TestNewSource"; !strings.Contains(gotFunc, wantFunc) { 39 t.Errorf("except contains got %s in %s", gotFunc, wantFunc) 40 } 41 }