Skip to content

Commit

Permalink
Merge pull request volcano-sh#257 from Rajadeepan/utclijob
Browse files Browse the repository at this point in the history
Adding UT for cli job package
  • Loading branch information
volcano-sh-bot authored Jun 27, 2019
2 parents 3e670fd + f8f8258 commit 8ca8674
Show file tree
Hide file tree
Showing 6 changed files with 409 additions and 0 deletions.
65 changes: 65 additions & 0 deletions pkg/cli/job/delete_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

}
64 changes: 64 additions & 0 deletions pkg/cli/job/list_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

}
76 changes: 76 additions & 0 deletions pkg/cli/job/resume_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

}
63 changes: 63 additions & 0 deletions pkg/cli/job/run_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

}
76 changes: 76 additions & 0 deletions pkg/cli/job/suspend_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

}
Loading

0 comments on commit 8ca8674

Please sign in to comment.