From ea6277a6bf65d35cad5492c6a94e751e8ea1ed34 Mon Sep 17 00:00:00 2001 From: Noble Mittal <62551163+beingnoble03@users.noreply.github.com> Date: Thu, 25 Jan 2024 15:01:23 +0530 Subject: [PATCH] Add missing tests for `go/event/syslogger` (#15005) Signed-off-by: Noble Mittal --- go/event/syslogger/fake_logger_test.go | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 go/event/syslogger/fake_logger_test.go diff --git a/go/event/syslogger/fake_logger_test.go b/go/event/syslogger/fake_logger_test.go new file mode 100644 index 00000000000..df4a8f8294e --- /dev/null +++ b/go/event/syslogger/fake_logger_test.go @@ -0,0 +1,47 @@ +/* +Copyright 2024 The Vitess 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 syslogger + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetLogsForNoLogs(t *testing.T) { + tl := NewTestLogger() + errLoggerMsg := tl.getLog() + + want := loggerMsg{ + msg: "no logs!", + level: "ERROR", + } + + assert.Equal(t, errLoggerMsg, want) +} + +func TestGetAllLogs(t *testing.T) { + tl := NewTestLogger() + tl.recordInfof("Test info log") + tl.recordErrorf("Test error log") + tl.recordWarningf("Test warning log") + + want := []string{"INFO:Test info log", "ERROR:Test error log", "WARNING:Test warning log"} + loggerMsgs := tl.GetAllLogs() + + assert.Equal(t, loggerMsgs, want) +}