-
Notifications
You must be signed in to change notification settings - Fork 993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
moved some of admission e2e test cases as ut test cases #171
Merged
volcano-sh-bot
merged 2 commits into
volcano-sh:master
from
SrinivasChilveri:UTTestCases
May 16, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,291 @@ | ||
package admission | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"k8s.io/api/admission/v1beta1" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1" | ||
) | ||
|
||
func TestValidateExecution(t *testing.T) { | ||
|
||
namespace := "test" | ||
var invTtl int32 = -1 | ||
|
||
testCases := []struct { | ||
Name string | ||
Job v1alpha1.Job | ||
ExpectErr bool | ||
reviewResponse v1beta1.AdmissionResponse | ||
ret string | ||
}{ | ||
{ | ||
Name: "validate valid-job", | ||
Job: v1alpha1.Job{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "valid-Job", | ||
Namespace: namespace, | ||
}, | ||
Spec: v1alpha1.JobSpec{ | ||
MinAvailable: 1, | ||
Tasks: []v1alpha1.TaskSpec{ | ||
{ | ||
Name: "task-1", | ||
Replicas: 1, | ||
Template: v1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{"name": "test"}, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "fake-name", | ||
Image: "busybox:1.24", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
reviewResponse: v1beta1.AdmissionResponse{Allowed: true}, | ||
ret: "", | ||
ExpectErr: false, | ||
}, | ||
// duplicate task name | ||
{ | ||
Name: "duplicate-task-job", | ||
Job: v1alpha1.Job{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "duplicate-task-job", | ||
Namespace: namespace, | ||
}, | ||
Spec: v1alpha1.JobSpec{ | ||
MinAvailable: 1, | ||
Tasks: []v1alpha1.TaskSpec{ | ||
{ | ||
Name: "duplicated-task-1", | ||
Replicas: 1, | ||
Template: v1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{"name": "test"}, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "fake-name", | ||
Image: "busybox:1.24", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "duplicated-task-1", | ||
Replicas: 1, | ||
Template: v1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{"name": "test"}, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "fake-name", | ||
Image: "busybox:1.24", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
reviewResponse: v1beta1.AdmissionResponse{Allowed: true}, | ||
ret: "duplicated task name duplicated-task-1", | ||
ExpectErr: true, | ||
}, | ||
// Duplicated Policy Event | ||
{ | ||
Name: "job-policy-duplicated", | ||
Job: v1alpha1.Job{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "job-policy-duplicated", | ||
Namespace: namespace, | ||
}, | ||
Spec: v1alpha1.JobSpec{ | ||
MinAvailable: 1, | ||
Tasks: []v1alpha1.TaskSpec{ | ||
{ | ||
Name: "task-1", | ||
Replicas: 1, | ||
Template: v1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{"name": "test"}, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "fake-name", | ||
Image: "busybox:1.24", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Policies: []v1alpha1.LifecyclePolicy{ | ||
{ | ||
Event: v1alpha1.PodFailedEvent, | ||
Action: v1alpha1.AbortJobAction, | ||
}, | ||
{ | ||
Event: v1alpha1.PodFailedEvent, | ||
Action: v1alpha1.RestartJobAction, | ||
}, | ||
}, | ||
}, | ||
}, | ||
reviewResponse: v1beta1.AdmissionResponse{Allowed: true}, | ||
ret: "duplicate", | ||
ExpectErr: true, | ||
}, | ||
// Min Available illegal | ||
{ | ||
Name: "Min Available illegal", | ||
Job: v1alpha1.Job{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "job-min-illegal", | ||
Namespace: namespace, | ||
}, | ||
Spec: v1alpha1.JobSpec{ | ||
MinAvailable: 2, | ||
Tasks: []v1alpha1.TaskSpec{ | ||
{ | ||
Name: "task-1", | ||
Replicas: 1, | ||
Template: v1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{"name": "test"}, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "fake-name", | ||
Image: "busybox:1.24", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
reviewResponse: v1beta1.AdmissionResponse{Allowed: true}, | ||
ret: "'minAvailable' should not be greater than total replicas in tasks", | ||
ExpectErr: true, | ||
}, | ||
// Job Plugin illegal | ||
{ | ||
Name: "Job Plugin illegal", | ||
Job: v1alpha1.Job{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "job-plugin-illegal", | ||
Namespace: namespace, | ||
}, | ||
Spec: v1alpha1.JobSpec{ | ||
MinAvailable: 1, | ||
Tasks: []v1alpha1.TaskSpec{ | ||
{ | ||
Name: "task-1", | ||
Replicas: 1, | ||
Template: v1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{"name": "test"}, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "fake-name", | ||
Image: "busybox:1.24", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Plugins: map[string][]string{ | ||
"big_plugin": {}, | ||
}, | ||
}, | ||
}, | ||
reviewResponse: v1beta1.AdmissionResponse{Allowed: true}, | ||
ret: "unable to find job plugin: big_plugin", | ||
ExpectErr: true, | ||
}, | ||
// ttl-illegal | ||
{ | ||
Name: "job-ttl-illegal", | ||
Job: v1alpha1.Job{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "job-ttl-illegal", | ||
Namespace: namespace, | ||
}, | ||
Spec: v1alpha1.JobSpec{ | ||
MinAvailable: 1, | ||
Tasks: []v1alpha1.TaskSpec{ | ||
{ | ||
Name: "task-1", | ||
Replicas: 1, | ||
Template: v1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{"name": "test"}, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "fake-name", | ||
Image: "busybox:1.24", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
TTLSecondsAfterFinished: &invTtl, | ||
}, | ||
}, | ||
reviewResponse: v1beta1.AdmissionResponse{Allowed: true}, | ||
ret: "'ttlSecondsAfterFinished' cannot be less than zero", | ||
ExpectErr: true, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
|
||
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) | ||
} | ||
|
||
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) | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add header there.