Files
virtual-kubelet/log/klogv2/klogv2_test.go
2021-01-15 18:23:32 +00:00

61 lines
1.6 KiB
Go

// Copyright © 2021 The virtual-kubelet authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package klogv2
import (
"testing"
"github.com/virtual-kubelet/virtual-kubelet/log"
)
func TestFieldMap_String(t *testing.T) {
var tests = []struct {
fields fieldMap
expected string
}{
{
fieldMap{Fields: nil},
"",
},
{
fieldMap{Fields: make(log.Fields)},
"",
},
{
fieldMap{Fields: map[string]interface{}{"one": 1}},
" [one=1]",
},
{
fieldMap{Fields: map[string]interface{}{"one": 1, "two": 2}},
" [one=1 two=2]",
},
}
for _, tt := range tests {
// Assert fields haven't been processed yet.
if len(tt.fields.processedFields) > 0 {
t.Fatal("fields shouldn't have been processed yet")
}
// Assert fields have been processed, if any.
actual := tt.fields.String()
if len(tt.fields.Fields) > 0 && len(tt.fields.processedFields) == 0 {
t.Fatal("fields should have been processed by now")
}
// Assert processFields yields desired results.
if actual != tt.expected {
t.Fatalf("expected: %s, got: %s", actual, tt.expected)
}
}
}