mirror of
https://github.com/jenkinsci/kubernetes-operator.git
synced 2026-10-04 07:01:16 +02:00
Improve e2e tests
This commit is contained in:
+13
-3
@@ -123,11 +123,11 @@ func createJenkinsCRWithSeedJob(t *testing.T, namespace string) *virtuslabv1alph
|
||||
//TODO(bantoniak) add seed job with private key
|
||||
SeedJobs: []virtuslabv1alpha1.SeedJob{
|
||||
{
|
||||
ID: "jenkins-operator-e2e",
|
||||
ID: "jenkins-operator",
|
||||
Targets: "cicd/jobs/*.jenkins",
|
||||
Description: "Jenkins Operator e2e tests repository",
|
||||
Description: "Jenkins Operator repository",
|
||||
RepositoryBranch: "master",
|
||||
RepositoryURL: "https://github.com/VirtusLab/jenkins-operator-e2e.git",
|
||||
RepositoryURL: "https://github.com/VirtusLab/jenkins-operator.git",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -150,3 +150,13 @@ func verifyJenkinsAPIConnection(t *testing.T, jenkins *virtuslabv1alpha1.Jenkins
|
||||
t.Log("I can establish connection to Jenkins API")
|
||||
return client
|
||||
}
|
||||
|
||||
func restartJenkinsMasterPod(t *testing.T, jenkins *virtuslabv1alpha1.Jenkins) {
|
||||
t.Log("Restarting Jenkins master pod")
|
||||
jenkinsPod := getJenkinsMasterPod(t, jenkins)
|
||||
err := framework.Global.Client.Delete(context.TODO(), jenkinsPod)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("Jenkins master pod has been restarted")
|
||||
}
|
||||
|
||||
@@ -35,11 +35,3 @@ func checkBaseConfigurationCompleteTimeIsNotSet(t *testing.T, jenkins *virtuslab
|
||||
t.Fatalf("Status.BaseConfigurationCompletedTime is set after restart of pod, status %+v", jenkinsStatus.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func restartJenkinsMasterPod(t *testing.T, jenkins *virtuslabv1alpha1.Jenkins) {
|
||||
jenkinsPod := getJenkinsMasterPod(t, jenkins)
|
||||
err := framework.Global.Client.Delete(context.TODO(), jenkinsPod)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,41 +32,34 @@ func TestUserConfiguration(t *testing.T) {
|
||||
}
|
||||
|
||||
func verifyJenkinsSeedJobs(t *testing.T, client *gojenkins.Jenkins, jenkins *virtuslabv1alpha1.Jenkins) {
|
||||
// check if job has been configured and executed successfully
|
||||
err := wait.Poll(time.Second*10, time.Minute*2, func() (bool, error) {
|
||||
t.Logf("Attempting to get configure seed job status '%v'", seedjobs.ConfigureSeedJobsName)
|
||||
seedJob, err := client.GetJob(seedjobs.ConfigureSeedJobsName)
|
||||
if err != nil || seedJob == nil {
|
||||
return false, nil
|
||||
}
|
||||
build, err := seedJob.GetLastSuccessfulBuild()
|
||||
if err != nil || build == nil {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
assert.NoError(t, err, "couldn't get jenkins job")
|
||||
t.Logf("Attempting to get configure seed job status '%v'", seedjobs.ConfigureSeedJobsName)
|
||||
configureSeedJobs, err := client.GetJob(seedjobs.ConfigureSeedJobsName)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, configureSeedJobs)
|
||||
build, err := configureSeedJobs.GetLastSuccessfulBuild()
|
||||
assert.NotNil(t, build)
|
||||
|
||||
// WARNING this use case depends on changes in https://github.com/VirtusLab/jenkins-operator-e2e/tree/master/cicd
|
||||
seedJobName := "jenkins-operator-e2e-job-dsl-seed" // https://github.com/VirtusLab/jenkins-operator-e2e/blob/master/cicd/jobs/e2e_test_job.jenkins
|
||||
err = wait.Poll(time.Second*10, time.Minute*2, func() (bool, error) {
|
||||
t.Logf("Attempting to verify if seed job has been created '%v'", seedJobName)
|
||||
seedJob, err := client.GetJob(seedJobName)
|
||||
if err != nil || seedJob == nil {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
assert.NoError(t, err, "couldn't verify if seed job has been created")
|
||||
seedJobName := "jenkins-operator-configure-seed-job"
|
||||
t.Logf("Attempting to verify if seed job has been created '%v'", seedJobName)
|
||||
seedJob, err := client.GetJob(seedJobName)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, seedJob)
|
||||
build, err = seedJob.GetLastSuccessfulBuild()
|
||||
assert.NotNil(t, build)
|
||||
|
||||
// verify Jenkins.Status.Builds
|
||||
// WARNING this use case depends on changes in https://github.com/VirtusLab/jenkins-operator-e2e/tree/master/cicd
|
||||
err = framework.Global.Client.Get(context.TODO(), types.NamespacedName{Namespace: jenkins.Namespace, Name: jenkins.Name}, jenkins)
|
||||
assert.NoError(t, err, "couldn't get jenkins custom resource")
|
||||
|
||||
assert.NotNil(t, jenkins.Status.Builds)
|
||||
assert.NotEmpty(t, jenkins.Status.Builds)
|
||||
assert.Equal(t, len(jenkins.Status.Builds), 1)
|
||||
build := jenkins.Status.Builds[0]
|
||||
assert.Equal(t, build.JobName, seedjobs.ConfigureSeedJobsName)
|
||||
|
||||
jobCreatedByDSLPluginName := "build-jenkins-operator"
|
||||
err = wait.Poll(time.Second*10, time.Minute*2, func() (bool, error) {
|
||||
t.Logf("Attempting to verify if job '%s' has been created ", jobCreatedByDSLPluginName)
|
||||
seedJob, err := client.GetJob(jobCreatedByDSLPluginName)
|
||||
if err != nil || seedJob == nil {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
+5
-2
@@ -26,7 +26,7 @@ type checkConditionFunc func(*virtuslabv1alpha1.Jenkins) bool
|
||||
|
||||
func waitForJenkinsBaseConfigurationToComplete(t *testing.T, jenkins *virtuslabv1alpha1.Jenkins) {
|
||||
t.Log("Waiting for Jenkins base configuration to complete")
|
||||
_, err := WaitUntilJenkinsConditionTrue(retryInterval, 50, jenkins, func(jenkins *virtuslabv1alpha1.Jenkins) bool {
|
||||
_, err := WaitUntilJenkinsConditionTrue(retryInterval, 150, jenkins, func(jenkins *virtuslabv1alpha1.Jenkins) bool {
|
||||
t.Logf("Current Jenkins status '%+v'", jenkins.Status)
|
||||
return jenkins.Status.BaseConfigurationCompletedTime != nil
|
||||
})
|
||||
@@ -45,13 +45,16 @@ func waitForRecreateJenkinsMasterPod(t *testing.T, jenkins *virtuslabv1alpha1.Je
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(podList.Items) != 1 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return podList.Items[0].DeletionTimestamp == nil, nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("Jenkins pod has bee recreated")
|
||||
t.Log("Jenkins pod has been recreated")
|
||||
}
|
||||
|
||||
func waitForJenkinsUserConfigurationToComplete(t *testing.T, jenkins *virtuslabv1alpha1.Jenkins) {
|
||||
|
||||
Reference in New Issue
Block a user