Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit 5e2232d

Browse files
Add unit tests for diagnostic suite (#528)
Co-authored-by: Javier Peña <[email protected]>
1 parent 4f3d47a commit 5e2232d

File tree

1 file changed

+170
-0
lines changed

1 file changed

+170
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// Copyright (C) 2021 Red Hat, Inc.
2+
//
3+
// This program is free software; you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation; either version 2 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License along
14+
// with this program; if not, write to the Free Software Foundation, Inc.,
15+
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16+
17+
// Package diagnostic provides a test suite which gathers OpenShift cluster information.
18+
package diagnostic
19+
20+
import (
21+
"testing"
22+
23+
"github.com/stretchr/testify/assert"
24+
"github.com/test-network-function/test-network-function/pkg/config"
25+
"github.com/test-network-function/test-network-function/pkg/config/configsections"
26+
)
27+
28+
//nolint:funlen
29+
func TestGetMasterAndWorkerNodeName(t *testing.T) {
30+
testCases := []struct {
31+
testEnv *config.TestEnvironment
32+
isMasterTest bool
33+
expectedNodeName string
34+
}{
35+
{ // Test Case 1 - IsMaster & HasDebugPod
36+
testEnv: &config.TestEnvironment{
37+
NodesUnderTest: map[string]*config.NodeConfig{
38+
"node01": {
39+
Name: "node01",
40+
Node: configsections.Node{
41+
Labels: []string{configsections.MasterLabel},
42+
},
43+
DebugContainer: &config.Container{
44+
ContainerConfig: configsections.ContainerConfig{
45+
ContainerIdentifier: configsections.ContainerIdentifier{
46+
PodName: "debugTest",
47+
},
48+
},
49+
},
50+
},
51+
},
52+
},
53+
expectedNodeName: "node01",
54+
isMasterTest: true,
55+
},
56+
{ // Test Case 2 - IsWorker & HasDebugPod
57+
testEnv: &config.TestEnvironment{
58+
NodesUnderTest: map[string]*config.NodeConfig{
59+
"node01": {
60+
Name: "node01",
61+
Node: configsections.Node{
62+
Labels: []string{configsections.WorkerLabel},
63+
},
64+
DebugContainer: &config.Container{
65+
ContainerConfig: configsections.ContainerConfig{
66+
ContainerIdentifier: configsections.ContainerIdentifier{
67+
PodName: "debugTest",
68+
},
69+
},
70+
},
71+
},
72+
},
73+
},
74+
expectedNodeName: "",
75+
isMasterTest: true,
76+
},
77+
{ // Test Case 3 - IsMaster & No DebugPod
78+
testEnv: &config.TestEnvironment{
79+
NodesUnderTest: map[string]*config.NodeConfig{
80+
"node01": {
81+
Name: "node01",
82+
Node: configsections.Node{
83+
Labels: []string{configsections.MasterLabel},
84+
},
85+
DebugContainer: nil,
86+
},
87+
},
88+
},
89+
expectedNodeName: "",
90+
isMasterTest: true,
91+
},
92+
{ // Test Case 4 - IsWorker & HasDebugPod
93+
testEnv: &config.TestEnvironment{
94+
NodesUnderTest: map[string]*config.NodeConfig{
95+
"node01": {
96+
Name: "node01",
97+
Node: configsections.Node{
98+
Labels: []string{configsections.WorkerLabel},
99+
},
100+
DebugContainer: &config.Container{
101+
ContainerConfig: configsections.ContainerConfig{
102+
ContainerIdentifier: configsections.ContainerIdentifier{
103+
PodName: "debugTest",
104+
},
105+
},
106+
},
107+
},
108+
},
109+
},
110+
expectedNodeName: "node01",
111+
isMasterTest: false,
112+
},
113+
{ // Test Case 5 - IsMaster & HasDebugPod
114+
testEnv: &config.TestEnvironment{
115+
NodesUnderTest: map[string]*config.NodeConfig{
116+
"node01": {
117+
Name: "node01",
118+
Node: configsections.Node{
119+
Labels: []string{configsections.MasterLabel},
120+
},
121+
DebugContainer: &config.Container{
122+
ContainerConfig: configsections.ContainerConfig{
123+
ContainerIdentifier: configsections.ContainerIdentifier{
124+
PodName: "debugTest",
125+
},
126+
},
127+
},
128+
},
129+
},
130+
},
131+
expectedNodeName: "",
132+
isMasterTest: false,
133+
},
134+
{ // Test Case 6 - IsWorker & No DebugPod
135+
testEnv: &config.TestEnvironment{
136+
NodesUnderTest: map[string]*config.NodeConfig{
137+
"node01": {
138+
Name: "node01",
139+
Node: configsections.Node{
140+
Labels: []string{configsections.WorkerLabel},
141+
},
142+
DebugContainer: nil,
143+
},
144+
},
145+
},
146+
expectedNodeName: "",
147+
isMasterTest: false,
148+
},
149+
}
150+
151+
for _, tc := range testCases {
152+
if tc.isMasterTest {
153+
assert.Equal(t, tc.expectedNodeName, getMasterNodeName(tc.testEnv))
154+
} else {
155+
assert.Equal(t, tc.expectedNodeName, getWorkerNodeName(tc.testEnv))
156+
}
157+
}
158+
}
159+
160+
func TestNewNodeSummary(t *testing.T) {
161+
assert.NotNil(t, GetNodeSummary())
162+
}
163+
164+
func TestGetVersionsOcp(t *testing.T) {
165+
assert.NotNil(t, GetVersionsOcp())
166+
}
167+
168+
func TestNewCsiDriverInfo(t *testing.T) {
169+
assert.NotNil(t, GetCsiDriverInfo())
170+
}

0 commit comments

Comments
 (0)