#90 Add kubernetes plugin e2e tests

This commit is contained in:
Jakub Al-Khalili 2019-09-12 14:47:58 +02:00
parent 9698079a02
commit 56d305eeab
3 changed files with 82 additions and 1 deletions

31
cicd/jobs/k8s.jenkins Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env groovy
pipelineJob('k8s-e2e') {
displayName('Kubernetes Plugin E2E Test')
logRotator {
numToKeep(10)
daysToKeep(30)
}
configure { project ->
project / 'properties' / 'org.jenkinsci.plugins.workflow.job.properties.DurabilityHintJobProperty' {
hint('PERFORMANCE_OPTIMIZED')
}
}
definition {
cpsScm {
scm {
git {
remote {
url('https://github.com/jenkinsci/kubernetes-operator.git')
credentials('jenkins-operator')
}
branches('*/master')
}
}
scriptPath('cicd/pipelines/k8s.jenkins')
}
}
}

View File

@ -0,0 +1,17 @@
#!/usr/bin/env groovy
def label = "k8s-e2e"
def home = "/home/jenkins"
def workspace = "${home}/workspace/build-jenkins-operator"
podTemplate(label: label,
containers: [
containerTemplate(name: 'alpine', image: 'alpine:3.10.2'),
],
) {
node(label) {
container('alpine') {
echo "its working"
}
}
}

View File

@ -5,16 +5,17 @@ import (
"fmt"
"testing"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/groovy"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/plugins"
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
"github.com/bndr/gojenkins"
framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -96,6 +97,38 @@ func TestConfiguration(t *testing.T) {
verifyJenkinsSeedJobs(t, client, []seedJobConfig{mySeedJob})
}
func TestPlugin(t *testing.T) {
t.Parallel()
namespace, ctx := setupTest(t)
// Deletes test namespace
defer ctx.Cleanup()
jobID := "k8s-e2e"
seedJobs := &[]v1alpha2.SeedJob{
{
ID: "jenkins-operator",
CredentialID: "jenkins-operator",
JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType,
Targets: "cicd/jobs/k8s.jenkins",
Description: "Jenkins Operator repository",
RepositoryBranch: "master",
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
},
}
jenkins := createJenkinsCR(t, "k8s-e2e", namespace, seedJobs, v1alpha2.GroovyScripts{}, v1alpha2.ConfigurationAsCode{})
waitForJenkinsUserConfigurationToComplete(t, jenkins)
jenkinsClient := verifyJenkinsAPIConnection(t, jenkins)
waitForJob(t, jenkinsClient, jobID)
job, err := jenkinsClient.GetJob(jobID)
require.NoError(t, err, job)
i, err := job.InvokeSimple(map[string]string{})
require.NoError(t, err, i)
}
func createUserConfigurationSecret(t *testing.T, namespace string, stringData map[string]string) {
userConfiguration := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{