Skip to content

Commit

Permalink
fix ut
Browse files Browse the repository at this point in the history
  • Loading branch information
hzxuzhonghu committed Jul 20, 2019
1 parent 546383e commit 4953ef4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pkg/admission/admit_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"volcano.sh/volcano/pkg/controllers/job/plugins"
)

//KubeBatchClientSet is kube-batch clientset
// KubeBatchClientSet is kube-batch clientset
var KubeBatchClientSet versioned.Interface

// AdmitJobs is to admit jobs and return response
Expand Down Expand Up @@ -154,7 +154,7 @@ func validateJob(job v1alpha1.Job, reviewResponse *v1beta1.AdmissionResponse) st
// TODO: deprecate v1alpha1
if _, err := KubeBatchClientSet.SchedulingV1alpha1().Queues().Get(job.Spec.Queue, metav1.GetOptions{}); err != nil {
if _, err := KubeBatchClientSet.SchedulingV1alpha2().Queues().Get(job.Spec.Queue, metav1.GetOptions{}); err != nil {
msg = msg + fmt.Sprintf("Job queue not exist with error: %v", err)
msg = msg + fmt.Sprintf(" unable to find job queue: %v", err)
}
}

Expand Down
70 changes: 35 additions & 35 deletions pkg/admission/admit_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,49 +936,49 @@ func TestValidateExecution(t *testing.T) {
},
},
reviewResponse: v1beta1.AdmissionResponse{Allowed: true},
ret: "Job not created with error: ",
ret: "unable to find job queue",
ExpectErr: true,
},
}

for _, testCase := range testCases {
t.Run(testCase.Name, func(t *testing.T) {
defaultqueue := schedulingv1aplha2.Queue{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
Spec: schedulingv1aplha2.QueueSpec{
Weight: 1,
},
}
// create fake kube-batch clientset
KubeBatchClientSet = kubebatchclient.NewSimpleClientset()

defaultqueue := schedulingv1aplha2.Queue{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
Spec: schedulingv1aplha2.QueueSpec{
Weight: 1,
},
}
// create fake kube-batch clientset
KubeBatchClientSet = kubebatchclient.NewSimpleClientset()

//create default queue
_, err := KubeBatchClientSet.SchedulingV1alpha2().Queues().Create(&defaultqueue)
if err != nil {
t.Error("Queue Creation Failed")
}
//create default queue
_, err := KubeBatchClientSet.SchedulingV1alpha2().Queues().Create(&defaultqueue)
if err != nil {
t.Error("Queue Creation Failed")
}

ret := validateJob(testCase.Job, &testCase.reviewResponse)
//fmt.Printf("test-case name:%s, ret:%v testCase.reviewResponse:%v \n", testCase.Name, ret,testCase.reviewResponse)
if testCase.ExpectErr == true && ret == "" {
t.Errorf("%s: test case Expect error msg :%s, but got nil.", testCase.Name, testCase.ret)
}
if testCase.ExpectErr == true && testCase.reviewResponse.Allowed != false {
t.Errorf("%s: test case Expect Allowed as false but got true.", testCase.Name)
}
if testCase.ExpectErr == true && !strings.Contains(ret, testCase.ret) {
t.Errorf("%s: test case Expect error msg :%s, but got diff error %v", testCase.Name, testCase.ret, ret)
}
ret := validateJob(testCase.Job, &testCase.reviewResponse)
//fmt.Printf("test-case name:%s, ret:%v testCase.reviewResponse:%v \n", testCase.Name, ret,testCase.reviewResponse)
if testCase.ExpectErr == true && ret == "" {
t.Errorf("Expect error msg :%s, but got nil.", testCase.ret)
}
if testCase.ExpectErr == true && testCase.reviewResponse.Allowed != false {
t.Errorf("Expect Allowed as false but got true.")
}
if testCase.ExpectErr == true && !strings.Contains(ret, testCase.ret) {
t.Errorf("Expect error msg :%s, but got diff error %v", testCase.ret, ret)
}

if testCase.ExpectErr == false && ret != "" {
t.Errorf("%s: test case Expect no error, but got error %v", testCase.Name, ret)
}
if testCase.ExpectErr == false && testCase.reviewResponse.Allowed != true {
t.Errorf("%s: test case Expect Allowed as true but got false. %v", testCase.Name, testCase.reviewResponse)
}
if testCase.ExpectErr == false && ret != "" {
t.Errorf("Expect no error, but got error %v", ret)
}
if testCase.ExpectErr == false && testCase.reviewResponse.Allowed != true {
t.Errorf("Expect Allowed as true but got false. %v", testCase.reviewResponse)
}

})
}

}

0 comments on commit 4953ef4

Please sign in to comment.