multus-cni/logging/logging_test.go
nicklesimba 9085c84672 Unit tests and update to quickstart guide (#354)
* Added a test for GetLoggingLevel

* Added up to 96% coverage for checkpoint.go

* Improved coverage of checkpoint.go to 96.4%

* Improved coverage of checkpoint.go to 96.4%

* Adding changes so i will have them saved for my remote fork thingy

* Fixed unit tests in checkpoint_test.go and conf_test.go

* Removed unnecessary comments

* improved conf code coverage by an amount that is greater than 0!

* improved coverage, but line 144 of conf.go needs a look

* Added unit tests to multus and types, also fixed a bug in conf.go

* added label to import types/020 in types.go

* hopefully resolved merge conflicts

* increased code coverage in multus.go and conf.go, also added bug fixes and formatting

* addressed all comments in review

* Updated testing.go with better comments

* changed 'thejohn' to '_not_type' for readability

* added additional unit tests

* added tests to kubeletclient.go

* added more unit tests to k8sclient.go and kubeletclient.go

* Added network status annotations section to quickstart and added more unit tests

* made changes to tests based on code review
2019-08-05 15:04:35 -04:00

83 lines
2.1 KiB
Go

// Copyright (c) 2018 Intel Corporation
//
// 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 logging
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestLogging(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Logging")
}
var _ = Describe("logging operations", func() {
BeforeEach(func() {
loggingStderr = false
loggingFp = nil
loggingLevel = PanicLevel
})
It("Check file setter with empty", func() {
SetLogFile("")
Expect(loggingFp).To(BeNil())
})
It("Check file setter with empty", func() {
SetLogFile("/tmp/foobar.logging")
Expect(loggingFp).NotTo(Equal(nil))
// check file existance
})
It("Check file setter with bad filepath", func() {
SetLogFile("/invalid/filepath")
Expect(loggingFp).NotTo(Equal(nil))
// check file existance
})
It("Check loglevel setter", func() {
SetLogLevel("debug")
Expect(loggingLevel).To(Equal(DebugLevel))
SetLogLevel("Error")
Expect(loggingLevel).To(Equal(ErrorLevel))
SetLogLevel("VERbose")
Expect(loggingLevel).To(Equal(VerboseLevel))
SetLogLevel("PANIC")
Expect(loggingLevel).To(Equal(PanicLevel))
})
It("Check loglevel setter with invalid level", func() {
currentLevel := loggingLevel
SetLogLevel("XXXX")
Expect(loggingLevel).To(Equal(currentLevel))
})
It("Check log to stderr setter with invalid level", func() {
currentVal := loggingStderr
SetLogStderr(!currentVal)
Expect(loggingStderr).NotTo(Equal(currentVal))
})
// Tests public getter
It("Check getter for logging level with current level", func() {
currentLevel := loggingLevel
Expect(currentLevel).To(Equal(GetLoggingLevel()))
})
})