#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
|
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 {
|
func getGroovyScriptsSecretVolumeName(jenkins *v1alpha2.Jenkins) string {
|
||||||
return "gs-" + jenkins.Spec.GroovyScripts.Secret.Name
|
return "gs-" + jenkins.Spec.GroovyScripts.Secret.Name
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
package resources
|
package resources
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetJenkinsMasterPodBaseVolumes(t *testing.T) {
|
func TestGetJenkinsMasterPodBaseVolumes(t *testing.T) {
|
||||||
|
|
@ -38,16 +39,7 @@ func TestGetJenkinsMasterPodBaseVolumes(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
groovyExists := false
|
groovyExists, cascExists := checkSecretVolumesPresence(jenkins)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.True(t, groovyExists)
|
assert.True(t, groovyExists)
|
||||||
assert.True(t, cascExists)
|
assert.True(t, cascExists)
|
||||||
|
|
@ -79,14 +71,10 @@ func TestGetJenkinsMasterPodBaseVolumes(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeExists := false
|
groovyExists, cascExists := checkSecretVolumesPresence(jenkins)
|
||||||
for _, volume := range GetJenkinsMasterPodBaseVolumes(jenkins) {
|
|
||||||
if volume.Name == ("casc-" + jenkins.Spec.ConfigurationAsCode.Secret.Name) {
|
|
||||||
volumeExists = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.True(t, volumeExists)
|
assert.True(t, cascExists)
|
||||||
|
assert.False(t, groovyExists)
|
||||||
})
|
})
|
||||||
t.Run("casc without secret name", func(t *testing.T) {
|
t.Run("casc without secret name", func(t *testing.T) {
|
||||||
jenkins := &v1alpha2.Jenkins{
|
jenkins := &v1alpha2.Jenkins{
|
||||||
|
|
@ -115,14 +103,10 @@ func TestGetJenkinsMasterPodBaseVolumes(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeExists := false
|
groovyExists, cascExists := checkSecretVolumesPresence(jenkins)
|
||||||
for _, volume := range GetJenkinsMasterPodBaseVolumes(jenkins) {
|
|
||||||
if volume.Name == ("gs-" + jenkins.Spec.GroovyScripts.Secret.Name) {
|
|
||||||
volumeExists = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
t.Run("casc and groovy script shared secret name", func(t *testing.T) {
|
||||||
jenkins := &v1alpha2.Jenkins{
|
jenkins := &v1alpha2.Jenkins{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue