-
Notifications
You must be signed in to change notification settings - Fork 997
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rajadeepan D Ramesh
committed
Jun 26, 2019
1 parent
0c44e1a
commit 99c5496
Showing
6 changed files
with
313 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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) | ||
} | ||
} | ||
|
||
} |
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,48 @@ | ||
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) | ||
} | ||
} | ||
|
||
} |
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,60 @@ | ||
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) | ||
} | ||
} | ||
|
||
} |
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,47 @@ | ||
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) | ||
} | ||
} | ||
|
||
} |
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,60 @@ | ||
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) | ||
} | ||
} | ||
|
||
} |
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,49 @@ | ||
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) | ||
} | ||
} | ||
|
||
} |