Skip to content

Commit e3ea5df

Browse files
committed
test: use constant for TestGenerateNodeZipObjects expectations
Signed-off-by: Chin-Ya Huang <[email protected]>
1 parent 72f4d87 commit e3ea5df

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

pkg/simulator/objects/process_node_zips_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ func TestGenerateNodeZipList(t *testing.T) {
3737
}
3838

3939
func TestGenerateNodeZipObjects(t *testing.T) {
40+
const (
41+
expectedPodCount = 2
42+
expectedPodName = "harvester-node-0"
43+
expectedContainerCount = 11
44+
expectedConfigLength = 2
45+
expectedFileCount = 30
46+
)
47+
4048
tmpDir, err := os.MkdirTemp("/tmp", "zipfiles-")
4149
if err != nil {
4250
t.Fatalf("Error creating tmp directory %v", err)
@@ -61,26 +69,26 @@ func TestGenerateNodeZipObjects(t *testing.T) {
6169
}
6270

6371
// verify pod
64-
if len(podList) != 2 {
65-
t.Fatalf("expected to find 1 pod created to match the node, but found %d", len(podList))
72+
if len(podList) != expectedPodCount {
73+
t.Fatalf("expected to find %d pod created to match the node, but found %d", expectedPodCount, len(podList))
6674
}
6775

6876
// parse containers in the pod
6977
node1Pod := podList[0]
70-
if node1Pod.Name != "harvester-node-0" {
71-
t.Fatalf("expected pod name to be node1 but got %s", node1Pod.Name)
78+
if node1Pod.Name != expectedPodName {
79+
t.Fatalf("expected pod name to be %s but got %s", expectedPodName, node1Pod.Name)
7280
}
7381

74-
if len(node1Pod.Spec.Containers) != 11 {
75-
t.Fatalf("expected 11 containers but found %d", len(node1Pod.Spec.Containers))
82+
if len(node1Pod.Spec.Containers) != expectedContainerCount {
83+
t.Fatalf("expected %d containers but found %d", expectedContainerCount, len(node1Pod.Spec.Containers))
7684
}
7785

78-
if len(nodeConfig) != 2 {
79-
t.Fatalf("expected to find 1 node but found %d", len(nodeConfig))
86+
if len(nodeConfig) != expectedConfigLength {
87+
t.Fatalf("expected to find %d node but found %d", expectedConfigLength, len(nodeConfig))
8088
}
8189

8290
// parse content
83-
if len(nodeConfig[0].Spec) != 30 {
84-
t.Fatalf("expected to find 30 files, but found %d", len(nodeConfig[0].Spec))
91+
if len(nodeConfig[0].Spec) != expectedFileCount {
92+
t.Fatalf("expected to find %d files, but found %d", expectedFileCount, len(nodeConfig[0].Spec))
8593
}
8694
}

0 commit comments

Comments
 (0)