#96 Small tests improvements
This commit is contained in:
parent
4b4cebadfa
commit
e8277cc8a0
|
|
@ -150,6 +150,18 @@ func GetJenkinsMasterPodBaseVolumes(jenkins *v1alpha2.Jenkins) []corev1.Volume {
|
|||
return volumes
|
||||
}
|
||||
|
||||
func checkSecretVolumesPresence(jenkins *v1alpha2.Jenkins) (groovyExists bool, cascExists bool) {
|
||||
for _, volume := range GetJenkinsMasterPodBaseVolumes(jenkins) {
|
||||
if volume.Name == ("gs-" + jenkins.Spec.GroovyScripts.Secret.Name) {
|
||||
groovyExists = true
|
||||
} else if volume.Name == ("casc-" + jenkins.Spec.ConfigurationAsCode.Secret.Name) {
|
||||
cascExists = true
|
||||
}
|
||||
}
|
||||
|
||||
return groovyExists, cascExists
|
||||
}
|
||||
|
||||
func getGroovyScriptsSecretVolumeName(jenkins *v1alpha2.Jenkins) string {
|
||||
return "gs-" + jenkins.Spec.GroovyScripts.Secret.Name
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package resources
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetJenkinsMasterPodBaseVolumes(t *testing.T) {
|
||||
|
|
@ -38,16 +39,7 @@ func TestGetJenkinsMasterPodBaseVolumes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
groovyExists := false
|
||||
cascExists := false
|
||||
|
||||
for _, volume := range GetJenkinsMasterPodBaseVolumes(jenkins) {
|
||||
if volume.Name == ("gs-" + jenkins.Spec.GroovyScripts.Secret.Name) {
|
||||
groovyExists = true
|
||||
} else if volume.Name == ("casc-" + jenkins.Spec.ConfigurationAsCode.Secret.Name) {
|
||||
cascExists = true
|
||||
}
|
||||
}
|
||||
groovyExists, cascExists := checkSecretVolumesPresence(jenkins)
|
||||
|
||||
assert.True(t, groovyExists)
|
||||
assert.True(t, cascExists)
|
||||
|
|
@ -79,14 +71,10 @@ func TestGetJenkinsMasterPodBaseVolumes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
volumeExists := false
|
||||
for _, volume := range GetJenkinsMasterPodBaseVolumes(jenkins) {
|
||||
if volume.Name == ("casc-" + jenkins.Spec.ConfigurationAsCode.Secret.Name) {
|
||||
volumeExists = true
|
||||
}
|
||||
}
|
||||
groovyExists, cascExists := checkSecretVolumesPresence(jenkins)
|
||||
|
||||
assert.True(t, volumeExists)
|
||||
assert.True(t, cascExists)
|
||||
assert.False(t, groovyExists)
|
||||
})
|
||||
t.Run("casc without secret name", func(t *testing.T) {
|
||||
jenkins := &v1alpha2.Jenkins{
|
||||
|
|
@ -115,14 +103,10 @@ func TestGetJenkinsMasterPodBaseVolumes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
volumeExists := false
|
||||
for _, volume := range GetJenkinsMasterPodBaseVolumes(jenkins) {
|
||||
if volume.Name == ("gs-" + jenkins.Spec.GroovyScripts.Secret.Name) {
|
||||
volumeExists = true
|
||||
}
|
||||
}
|
||||
groovyExists, cascExists := checkSecretVolumesPresence(jenkins)
|
||||
|
||||
assert.True(t, volumeExists)
|
||||
assert.True(t, groovyExists)
|
||||
assert.False(t, cascExists)
|
||||
})
|
||||
t.Run("casc and groovy script shared secret name", func(t *testing.T) {
|
||||
jenkins := &v1alpha2.Jenkins{
|
||||
|
|
|
|||
Loading…
Reference in New Issue