diff --git a/pkg/cli/job/delete_test.go b/pkg/cli/job/delete_test.go new file mode 100644 index 00000000000..03b98e112cd --- /dev/null +++ b/pkg/cli/job/delete_test.go @@ -0,0 +1,65 @@ +/* +Copyright 2019 The Volcano Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package job + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1" +) + +func TestDeleteJobJob(t *testing.T) { + response := v1alpha1.Job{} + response.Name = "testJob" + + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + val, err := json.Marshal(response) + if err == nil { + w.Write(val) + } + + }) + + server := httptest.NewServer(handler) + defer server.Close() + + deleteJobFlags.Master = server.URL + deleteJobFlags.Namespace = "test" + deleteJobFlags.JobName = "testJob" + + testCases := []struct { + Name string + ExpectValue error + }{ + { + Name: "DeleteJob", + ExpectValue: nil, + }, + } + + for i, testcase := range testCases { + err := DeleteJob() + if err != nil { + t.Errorf("case %d (%s): expected: %v, got %v ", i, testcase.Name, testcase.ExpectValue, err) + } + } + +} diff --git a/pkg/cli/job/list_test.go b/pkg/cli/job/list_test.go new file mode 100644 index 00000000000..c2086e285ff --- /dev/null +++ b/pkg/cli/job/list_test.go @@ -0,0 +1,64 @@ +/* +Copyright 2019 The Volcano Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package job + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1" +) + +func TestListJob(t *testing.T) { + response := v1alpha1.JobList{} + response.Items = append(response.Items, v1alpha1.Job{}) + + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + val, err := json.Marshal(response) + if err == nil { + w.Write(val) + } + + }) + + server := httptest.NewServer(handler) + defer server.Close() + + listJobFlags.Master = server.URL + listJobFlags.Namespace = "test" + + testCases := []struct { + Name string + ExpectValue error + }{ + { + Name: "ListJob", + ExpectValue: nil, + }, + } + + for i, testcase := range testCases { + err := ListJobs() + if err != nil { + t.Errorf("case %d (%s): expected: %v, got %v ", i, testcase.Name, testcase.ExpectValue, err) + } + } + +} diff --git a/pkg/cli/job/resume_test.go b/pkg/cli/job/resume_test.go new file mode 100644 index 00000000000..1b81621e298 --- /dev/null +++ b/pkg/cli/job/resume_test.go @@ -0,0 +1,76 @@ +/* +Copyright 2019 The Volcano Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package job + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "strings" + "testing" + + v1alpha1batch "volcano.sh/volcano/pkg/apis/batch/v1alpha1" + v1alpha1 "volcano.sh/volcano/pkg/apis/bus/v1alpha1" +) + +func TestResumeJob(t *testing.T) { + responsecommand := v1alpha1.Command{} + responsejob := v1alpha1batch.Job{} + + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if strings.HasSuffix(r.URL.Path, "command") { + w.Header().Set("Content-Type", "application/json") + val, err := json.Marshal(responsecommand) + if err == nil { + w.Write(val) + } + + } else { + w.Header().Set("Content-Type", "application/json") + val, err := json.Marshal(responsejob) + if err == nil { + w.Write(val) + } + + } + }) + + server := httptest.NewServer(handler) + defer server.Close() + + resumeJobFlags.Master = server.URL + resumeJobFlags.Namespace = "test" + resumeJobFlags.JobName = "testjob" + + testCases := []struct { + Name string + ExpectValue error + }{ + { + Name: "ResumeJob", + ExpectValue: nil, + }, + } + + for i, testcase := range testCases { + err := ResumeJob() + if err != nil { + t.Errorf("case %d (%s): expected: %v, got %v ", i, testcase.Name, testcase.ExpectValue, err) + } + } + +} diff --git a/pkg/cli/job/run_test.go b/pkg/cli/job/run_test.go new file mode 100644 index 00000000000..8594d734821 --- /dev/null +++ b/pkg/cli/job/run_test.go @@ -0,0 +1,63 @@ +/* +Copyright 2019 The Volcano Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package job + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1" +) + +func TestCreateJob(t *testing.T) { + response := v1alpha1.Job{} + + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + val, err := json.Marshal(response) + if err == nil { + w.Write(val) + } + + }) + + server := httptest.NewServer(handler) + defer server.Close() + + launchJobFlags.Master = server.URL + launchJobFlags.Namespace = "test" + + testCases := []struct { + Name string + ExpectValue error + }{ + { + Name: "CreateJob", + ExpectValue: nil, + }, + } + + for i, testcase := range testCases { + err := RunJob() + if err != nil { + t.Errorf("case %d (%s): expected: %v, got %v ", i, testcase.Name, testcase.ExpectValue, err) + } + } + +} diff --git a/pkg/cli/job/suspend_test.go b/pkg/cli/job/suspend_test.go new file mode 100644 index 00000000000..b25daac72a4 --- /dev/null +++ b/pkg/cli/job/suspend_test.go @@ -0,0 +1,76 @@ +/* +Copyright 2019 The Volcano Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package job + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "strings" + "testing" + + v1alpha1batch "volcano.sh/volcano/pkg/apis/batch/v1alpha1" + v1alpha1 "volcano.sh/volcano/pkg/apis/bus/v1alpha1" +) + +func TestSuspendJobJob(t *testing.T) { + responsecommand := v1alpha1.Command{} + responsejob := v1alpha1batch.Job{} + + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if strings.HasSuffix(r.URL.Path, "command") { + w.Header().Set("Content-Type", "application/json") + val, err := json.Marshal(responsecommand) + if err == nil { + w.Write(val) + } + + } else { + w.Header().Set("Content-Type", "application/json") + val, err := json.Marshal(responsejob) + if err == nil { + w.Write(val) + } + + } + }) + + server := httptest.NewServer(handler) + defer server.Close() + + suspendJobFlags.Master = server.URL + suspendJobFlags.Namespace = "test" + suspendJobFlags.JobName = "testjob" + + testCases := []struct { + Name string + ExpectValue error + }{ + { + Name: "SuspendJob", + ExpectValue: nil, + }, + } + + for i, testcase := range testCases { + err := SuspendJob() + if err != nil { + t.Errorf("case %d (%s): expected: %v, got %v ", i, testcase.Name, testcase.ExpectValue, err) + } + } + +} diff --git a/pkg/cli/job/view_test.go b/pkg/cli/job/view_test.go new file mode 100644 index 00000000000..9d279b8cb36 --- /dev/null +++ b/pkg/cli/job/view_test.go @@ -0,0 +1,65 @@ +/* +Copyright 2019 The Volcano Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package job + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1" +) + +func TestViewJob(t *testing.T) { + response := v1alpha1.Job{} + response.Name = "testJob" + + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + val, err := json.Marshal(response) + if err == nil { + w.Write(val) + } + + }) + + server := httptest.NewServer(handler) + defer server.Close() + + viewJobFlags.Master = server.URL + viewJobFlags.Namespace = "test" + viewJobFlags.JobName = "testJob" + + testCases := []struct { + Name string + ExpectValue error + }{ + { + Name: "viewJob", + ExpectValue: nil, + }, + } + + for i, testcase := range testCases { + err := ViewJob() + if err != nil { + t.Errorf("case %d (%s): expected: %v, got %v ", i, testcase.Name, testcase.ExpectValue, err) + } + } + +}