blob: dbd9ffefd3533626f3f394154ab5c29cfceda717 [file] [log] [blame]
khenaidoo7da372d2018-09-21 16:03:09 -04001/*
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 */
16package log
17
18import (
19 "github.com/opencord/voltha-go/common/log"
20 "github.com/stretchr/testify/assert"
21 "google.golang.org/grpc/grpclog"
22 "testing"
23)
24
25/*
26Prerequite: Start the kafka/zookeeper containers.
27*/
28
29var testLogger log.Logger
30
31
32func TestInit (t *testing.T) {
33 var err error
34 testLogger, err = log.AddPackage(log.JSON, log.ErrorLevel, nil)
35 assert.NotNil(t, testLogger)
36 assert.Nil(t, err)
37}
38
39func verifyLogLevel(t *testing.T, minimumLevel int) {
40 log.SetAllLogLevel(minimumLevel)
41 var success bool
42 for i := 0; i < 6; i++ {
43 success = testLogger.V(i)
44 if i == 1 && minimumLevel == 2{
45 // TODO: Update the test when a new version of Zap logger is available. It has a bug with that
46 // specific combination
47 continue
48 }
49 if i < minimumLevel {
50 assert.False(t, success)
51 } else {
52 assert.True(t, success)
53 }
54 }
55}
56
57func TestLogLevelDebug (t *testing.T) {
58 for i := 0; i < 6; i++ {
59 verifyLogLevel(t, i)
60 }
61}
62
63func TestUpdateAllLoggers (t *testing.T) {
64 err := log.UpdateAllLoggers(log.Fields{"update": "update"})
65 assert.Nil(t, err)
66}
67
68func TestUpdateLoggers (t *testing.T) {
69 testLogger, err := log.UpdateLogger(log.Fields{"update": "update"})
70 assert.Nil(t, err)
71 assert.NotNil(t, testLogger)
72}
73
74func TestUseAsGrpcLoggerV2(t *testing.T) {
75 var grpcLogger grpclog.LoggerV2
76 thisLogger, _ := log.AddPackage(log.JSON, log.ErrorLevel, nil)
77 grpcLogger = thisLogger
78 assert.NotNil(t, grpcLogger)
79}