blob: 6e9de8a88c1d874dfe87e2897d2c3c354de2e6dd [file] [log] [blame]
Matteo Scandolo2bf742a2019-10-01 11:33:34 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3
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
26func Test_SetLogLevel(t *testing.T) {
27 log := logrus.New()
28
Matteo Scandolo40e067f2019-10-16 16:59:41 -070029 common.SetLogLevel(log, "trace", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070030 assert.Equal(t, log.Level, logrus.TraceLevel)
31
Matteo Scandolo40e067f2019-10-16 16:59:41 -070032 common.SetLogLevel(log, "debug", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070033 assert.Equal(t, log.Level, logrus.DebugLevel)
34
Matteo Scandolo40e067f2019-10-16 16:59:41 -070035 common.SetLogLevel(log, "info", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070036 assert.Equal(t, log.Level, logrus.InfoLevel)
37
Matteo Scandolo40e067f2019-10-16 16:59:41 -070038 common.SetLogLevel(log, "warn", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070039 assert.Equal(t, log.Level, logrus.WarnLevel)
40
Matteo Scandolo40e067f2019-10-16 16:59:41 -070041 common.SetLogLevel(log, "error", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070042 assert.Equal(t, log.Level, logrus.ErrorLevel)
43
Matteo Scandolo40e067f2019-10-16 16:59:41 -070044 common.SetLogLevel(log, "foobar", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070045 assert.Equal(t, log.Level, logrus.DebugLevel)
46}
47
48func Test_SetLogLevelCaller(t *testing.T) {
49 log := logrus.New()
50
Matteo Scandolo40e067f2019-10-16 16:59:41 -070051 common.SetLogLevel(log, "debug", true)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070052 assert.Equal(t, log.ReportCaller, true)
53
Matteo Scandolo40e067f2019-10-16 16:59:41 -070054 common.SetLogLevel(log, "debug", false)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070055 assert.Equal(t, log.ReportCaller, false)
56}