blob: 7b9e08ce17575eb32a6f55df6a2ba580449fe70d [file] [log] [blame]
Matteo Scandolo2bf742a2019-10-01 11:33:34 -07001/*
Joey Armstrong2c039362024-02-04 18:51:52 -05002 * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo2bf742a2019-10-01 11:33:34 -07003
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Matteo Scandolo40e067f2019-10-16 16:59:41 -070017package common_test
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070018
19import (
Matteo Scandolo40e067f2019-10-16 16:59:41 -070020 "github.com/opencord/bbsim/internal/common"
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070021 "github.com/sirupsen/logrus"
22 "gotest.tools/assert"
23 "testing"
24)
25
Matteo Scandolo8a574812021-05-20 15:18:53 -070026func init() {
27 common.SetLogLevel(logrus.StandardLogger(), "error", false)
28}
29
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070030func Test_SetLogLevel(t *testing.T) {
31 log := logrus.New()
32
Matteo Scandolo40e067f2019-10-16 16:59:41 -070033 common.SetLogLevel(log, "trace", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070034 assert.Equal(t, log.Level, logrus.TraceLevel)
35
Matteo Scandolo40e067f2019-10-16 16:59:41 -070036 common.SetLogLevel(log, "debug", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070037 assert.Equal(t, log.Level, logrus.DebugLevel)
38
Matteo Scandolo40e067f2019-10-16 16:59:41 -070039 common.SetLogLevel(log, "info", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070040 assert.Equal(t, log.Level, logrus.InfoLevel)
41
Matteo Scandolo40e067f2019-10-16 16:59:41 -070042 common.SetLogLevel(log, "warn", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070043 assert.Equal(t, log.Level, logrus.WarnLevel)
44
Matteo Scandolo40e067f2019-10-16 16:59:41 -070045 common.SetLogLevel(log, "error", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070046 assert.Equal(t, log.Level, logrus.ErrorLevel)
47
Matteo Scandolo40e067f2019-10-16 16:59:41 -070048 common.SetLogLevel(log, "foobar", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070049 assert.Equal(t, log.Level, logrus.DebugLevel)
50}
51
52func Test_SetLogLevelCaller(t *testing.T) {
53 log := logrus.New()
54
Matteo Scandolo40e067f2019-10-16 16:59:41 -070055 common.SetLogLevel(log, "debug", true)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070056 assert.Equal(t, log.ReportCaller, true)
57
Matteo Scandolo40e067f2019-10-16 16:59:41 -070058 common.SetLogLevel(log, "debug", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070059 assert.Equal(t, log.ReportCaller, false)
60}