Skip to content

Commit 94ce10f

Browse files
Add additional core functions
1 parent f782f78 commit 94ce10f

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

support/core.go

+30
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,33 @@ func GetNodeInternalIP(t Test, node corev1.Node) (IP string) {
184184

185185
return
186186
}
187+
188+
func GetContainerName(t Test, container corev1.Container) string {
189+
t.T().Helper()
190+
t.Expect(container.Name).Should(gomega.Not(gomega.BeEmpty()))
191+
return container.Name
192+
}
193+
194+
func GetVolumeName(t Test, volume corev1.Volume) string {
195+
t.T().Helper()
196+
t.Expect(volume.Name).Should(gomega.Not(gomega.BeEmpty()))
197+
return volume.Name
198+
}
199+
200+
func GetServiceAccountName(t Test, serviceAccount corev1.ServiceAccount) string {
201+
t.T().Helper()
202+
t.Expect(serviceAccount.Name).Should(gomega.Not(gomega.BeEmpty()))
203+
return serviceAccount.Name
204+
}
205+
206+
func GetVolumeMountName(t Test, volumeMount corev1.VolumeMount) string {
207+
t.T().Helper()
208+
t.Expect(volumeMount.Name).Should(gomega.Not(gomega.BeEmpty()))
209+
return volumeMount.Name
210+
}
211+
212+
func GetEnvVarName(t Test, envVar corev1.EnvVar) string {
213+
t.T().Helper()
214+
t.Expect(envVar.Name).Should(gomega.Not(gomega.BeEmpty()))
215+
return envVar.Name
216+
}

support/core_test.go

+47
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,50 @@ func TestGetNodes(t *testing.T) {
4343
test.Expect(nodes[0].Name).To(gomega.Equal("test-node"), "Expected node name 'test-node', but got '%s'", nodes[0].Name)
4444

4545
}
46+
47+
func TestGetContainerName(t *testing.T) {
48+
test := NewTest(t)
49+
container := corev1.Container{
50+
Name: "test-container",
51+
}
52+
containerName := GetContainerName(test, container)
53+
test.Expect(containerName).To(gomega.Equal("test-container"), "Expected container name 'test-container', but got '%s'", containerName)
54+
}
55+
56+
func TestGetVolumeName(t *testing.T) {
57+
test := NewTest(t)
58+
volume := corev1.Volume{
59+
Name: "test-volume",
60+
}
61+
volumeName := GetVolumeName(test, volume)
62+
test.Expect(volumeName).To(gomega.Equal("test-volume"), "Expected volume name 'test-volume', but got '%s'", volumeName)
63+
}
64+
65+
func TestGetServiceAccountName(t *testing.T) {
66+
test := NewTest(t)
67+
serviceAccount := corev1.ServiceAccount{
68+
ObjectMeta: metav1.ObjectMeta{
69+
Name: "test-service-account",
70+
},
71+
}
72+
serviceAccountName := GetServiceAccountName(test, serviceAccount)
73+
test.Expect(serviceAccountName).To(gomega.Equal("test-service-account"), "Expected service account name 'test-service-account', but got '%s'", serviceAccountName)
74+
}
75+
76+
func TestGetVolumeMountName(t *testing.T) {
77+
test := NewTest(t)
78+
volumeMount := corev1.VolumeMount{
79+
Name: "test-volume-mount",
80+
}
81+
volumeMountName := GetVolumeMountName(test, volumeMount)
82+
test.Expect(volumeMountName).To(gomega.Equal("test-volume-mount"), "Expected volume mount name 'test-volume-mount', but got '%s'", volumeMountName)
83+
}
84+
85+
func TestGetEnvVarName(t *testing.T) {
86+
test := NewTest(t)
87+
envVar := corev1.EnvVar{
88+
Name: "test-env-var",
89+
}
90+
envVarName := GetEnvVarName(test, envVar)
91+
test.Expect(envVarName).To(gomega.Equal("test-env-var"), "Expected env var name 'test-env-var', but got '%s'", envVarName)
92+
}

0 commit comments

Comments
 (0)