github.com/banzaicloud/operator-tools@v0.28.10/pkg/logger/logger_test.go (about) 1 // Copyright © 2020 Banzai Cloud 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package logger 16 17 import ( 18 "bytes" 19 "testing" 20 21 "github.com/go-logr/logr" 22 "github.com/stretchr/testify/require" 23 ) 24 25 func TestInfoLog(t *testing.T) { 26 type foo string 27 var buf bytes.Buffer 28 29 sink := NewSpinnerLogSink(Out(&buf)) 30 sink.ShowTime(false) 31 sink.Info(0, "test", "foo", foo("bar")) 32 expected := []byte("\r\x1b[K✓ test foo=bar\n") 33 require.Equal(t, expected, buf.Bytes()) 34 } 35 36 func TestSpinnerLogSinkWithLogrLogger(t *testing.T) { 37 type foo string 38 var buf bytes.Buffer 39 40 sink := NewSpinnerLogSink(Out(&buf)) 41 sink.ShowTime(false) 42 43 log := logr.New(sink) 44 log.Info("test", "foo", foo("bar")) 45 expected := []byte("\r\x1b[K✓ test foo=bar\n") 46 require.Equal(t, expected, buf.Bytes()) 47 }