github.com/zchee/zap-cloudlogging@v0.0.0-20220819025602-19b026d3900e/labels_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 "testing" 8 9 "github.com/google/go-cmp/cmp" 10 "github.com/google/go-cmp/cmp/cmpopts" 11 "go.uber.org/zap" 12 ) 13 14 func TestLabel(t *testing.T) { 15 t.Parallel() 16 17 field := Label("key", "value") 18 19 if diff := cmp.Diff(field, zap.String("labels.key", "value")); diff != "" { 20 t.Fatalf("(-want, +got)\n%s\n", diff) 21 } 22 } 23 24 func TestLabels(t *testing.T) { 25 t.Parallel() 26 27 field := Labels( 28 "hello", "world", 29 "hi", "universe", 30 ) 31 32 labels := new(labelMap) 33 for key, val := range map[string]string{"hello": "world", "hi": "universe"} { 34 labels.Add(key, val) 35 } 36 37 if diff := cmp.Diff(field, zap.Object(LabelsKey, labels), 38 cmpopts.IgnoreUnexported(labelMap{}), 39 ); diff != "" { 40 t.Fatalf("(-want, +got)\n%s\n", diff) 41 } 42 }