Skip to content

Commit

Permalink
chore: utils test suite
Browse files Browse the repository at this point in the history
Add test suite for utils package.

Signed-off-by: Fred Rolland <frolland@nvidia.com>
  • Loading branch information
rollandf committed Mar 3, 2024
1 parent 4c421a2 commit 7e7c2a3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
36 changes: 36 additions & 0 deletions pkg/utils/utils_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
2024 NVIDIA CORPORATION & AFFILIATES
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 utils

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

var _ = BeforeSuite(func() {
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
})

func TestState(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "utils test Suite")
}
14 changes: 12 additions & 2 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,37 @@ import (
)

var _ = Describe("Utils tests", func() {
var clusterTypeProvider mocks.Provider

Context("Testing CniBinDirectory retrieval", func() {
It("Should return user set directory", func() {
userSetDir := "/user/set/directory"
staticConfigProvider := staticconfig.NewProvider(staticconfig.StaticConfig{CniBinDirectory: userSetDir})
clusterTypeProvider := mocks.Provider{}
clusterTypeProvider.On("IsOpenshift").Return(false)
result := GetCniBinDirectory(staticConfigProvider, &clusterTypeProvider)
Expect(result).To(Equal(userSetDir))
})

It("Should return Openshift directory for OCP cluster", func() {
It("Should return user set directory for OCP cluster", func() {
userSetDir := "/user/set/directory"
staticConfigProvider := staticconfig.NewProvider(staticconfig.StaticConfig{CniBinDirectory: userSetDir})
clusterTypeProvider := mocks.Provider{}
clusterTypeProvider.On("IsOpenshift").Return(true)
result := GetCniBinDirectory(staticConfigProvider, &clusterTypeProvider)
Expect(result).To(Equal(userSetDir))
})

It("Should return default Openshift directory for OCP cluster", func() {
staticConfigProvider := staticconfig.NewProvider(staticconfig.StaticConfig{CniBinDirectory: ""})
clusterTypeProvider := mocks.Provider{}
clusterTypeProvider.On("IsOpenshift").Return(true)
result := GetCniBinDirectory(staticConfigProvider, &clusterTypeProvider)
Expect(result).To(Equal(consts.OcpCniBinDirectory))
})

It("Should return default K8s directory for non-OCP cluster", func() {
staticConfigProvider := staticconfig.NewProvider(staticconfig.StaticConfig{CniBinDirectory: ""})
clusterTypeProvider := mocks.Provider{}
clusterTypeProvider.On("IsOpenshift").Return(false)
result := GetCniBinDirectory(staticConfigProvider, &clusterTypeProvider)
Expect(result).To(Equal(consts.DefaultCniBinDirectory))
Expand Down

0 comments on commit 7e7c2a3

Please sign in to comment.