Skip to content

Commit

Permalink
Add additional core functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianZaccaria committed May 21, 2024
1 parent f782f78 commit 94ce10f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
30 changes: 30 additions & 0 deletions support/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,33 @@ func GetNodeInternalIP(t Test, node corev1.Node) (IP string) {

return
}

func GetContainerName(t Test, container corev1.Container) string {
t.T().Helper()
t.Expect(container.Name).Should(gomega.Not(gomega.BeEmpty()))
return container.Name
}

func GetVolumeName(t Test, volume corev1.Volume) string {
t.T().Helper()
t.Expect(volume.Name).Should(gomega.Not(gomega.BeEmpty()))
return volume.Name
}

func GetServiceAccountName(t Test, serviceAccount corev1.ServiceAccount) string {
t.T().Helper()
t.Expect(serviceAccount.Name).Should(gomega.Not(gomega.BeEmpty()))
return serviceAccount.Name
}

func GetVolumeMountName(t Test, volumeMount corev1.VolumeMount) string {
t.T().Helper()
t.Expect(volumeMount.Name).Should(gomega.Not(gomega.BeEmpty()))
return volumeMount.Name
}

func GetEnvVarName(t Test, envVar corev1.EnvVar) string {
t.T().Helper()
t.Expect(envVar.Name).Should(gomega.Not(gomega.BeEmpty()))
return envVar.Name
}
47 changes: 47 additions & 0 deletions support/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,50 @@ func TestGetNodes(t *testing.T) {
test.Expect(nodes[0].Name).To(gomega.Equal("test-node"), "Expected node name 'test-node', but got '%s'", nodes[0].Name)

}

func TestGetContainerName(t *testing.T) {
test := NewTest(t)
container := corev1.Container{
Name: "test-container",
}
containerName := GetContainerName(test, container)
test.Expect(containerName).To(gomega.Equal("test-container"), "Expected container name 'test-container', but got '%s'", containerName)
}

func TestGetVolumeName(t *testing.T) {
test := NewTest(t)
volume := corev1.Volume{
Name: "test-volume",
}
volumeName := GetVolumeName(test, volume)
test.Expect(volumeName).To(gomega.Equal("test-volume"), "Expected volume name 'test-volume', but got '%s'", volumeName)
}

func TestGetServiceAccountName(t *testing.T) {
test := NewTest(t)
serviceAccount := corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: "test-service-account",
},
}
serviceAccountName := GetServiceAccountName(test, serviceAccount)
test.Expect(serviceAccountName).To(gomega.Equal("test-service-account"), "Expected service account name 'test-service-account', but got '%s'", serviceAccountName)
}

func TestGetVolumeMountName(t *testing.T) {
test := NewTest(t)
volumeMount := corev1.VolumeMount{
Name: "test-volume-mount",
}
volumeMountName := GetVolumeMountName(test, volumeMount)
test.Expect(volumeMountName).To(gomega.Equal("test-volume-mount"), "Expected volume mount name 'test-volume-mount', but got '%s'", volumeMountName)
}

func TestGetEnvVarName(t *testing.T) {
test := NewTest(t)
envVar := corev1.EnvVar{
Name: "test-env-var",
}
envVarName := GetEnvVarName(test, envVar)
test.Expect(envVarName).To(gomega.Equal("test-env-var"), "Expected env var name 'test-env-var', but got '%s'", envVarName)
}

0 comments on commit 94ce10f

Please sign in to comment.