Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 1 | /* |
| 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 Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 17 | package common_test |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 18 | |
| 19 | import ( |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 20 | "github.com/opencord/bbsim/internal/common" |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 21 | "github.com/sirupsen/logrus" |
| 22 | "gotest.tools/assert" |
| 23 | "testing" |
| 24 | ) |
| 25 | |
| 26 | func Test_SetLogLevel(t *testing.T) { |
| 27 | log := logrus.New() |
| 28 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 29 | common.SetLogLevel(log, "trace", false) |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 30 | assert.Equal(t, log.Level, logrus.TraceLevel) |
| 31 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 32 | common.SetLogLevel(log, "debug", false) |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 33 | assert.Equal(t, log.Level, logrus.DebugLevel) |
| 34 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 35 | common.SetLogLevel(log, "info", false) |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 36 | assert.Equal(t, log.Level, logrus.InfoLevel) |
| 37 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 38 | common.SetLogLevel(log, "warn", false) |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 39 | assert.Equal(t, log.Level, logrus.WarnLevel) |
| 40 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 41 | common.SetLogLevel(log, "error", false) |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 42 | assert.Equal(t, log.Level, logrus.ErrorLevel) |
| 43 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 44 | common.SetLogLevel(log, "foobar", false) |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 45 | assert.Equal(t, log.Level, logrus.DebugLevel) |
| 46 | } |
| 47 | |
| 48 | func Test_SetLogLevelCaller(t *testing.T) { |
| 49 | log := logrus.New() |
| 50 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 51 | common.SetLogLevel(log, "debug", true) |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 52 | assert.Equal(t, log.ReportCaller, true) |
| 53 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 54 | common.SetLogLevel(log, "debug", false) |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 55 | assert.Equal(t, log.ReportCaller, false) |
| 56 | } |