Skip to content

Commit

Permalink
Merge pull request #273 from Rajadeepan/utclijob
Browse files Browse the repository at this point in the history
Additional UT in cli, queue,jo info pkg
  • Loading branch information
volcano-sh-bot authored Jul 2, 2019
2 parents 8c2067a + 411fea0 commit ae619b4
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/cli/job/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package job

import (
"encoding/json"
"github.com/spf13/cobra"
"net/http"
"net/http/httptest"
"testing"

v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

func TestDeleteJobJob(t *testing.T) {
Expand Down Expand Up @@ -63,3 +64,16 @@ func TestDeleteJobJob(t *testing.T) {
}

}

func TestInitDeleteFlags(t *testing.T) {
var cmd cobra.Command
InitDeleteFlags(&cmd)

if cmd.Flag("namespace") == nil {
t.Errorf("Could not find the flag namespace")
}
if cmd.Flag("name") == nil {
t.Errorf("Could not find the flag name")
}

}
14 changes: 14 additions & 0 deletions pkg/cli/job/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package job

import (
"encoding/json"
"github.com/spf13/cobra"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -62,3 +63,16 @@ func TestListJob(t *testing.T) {
}

}

func TestInitListFlags(t *testing.T) {
var cmd cobra.Command
InitListFlags(&cmd)

if cmd.Flag("namespace") == nil {
t.Errorf("Could not find the flag namespace")
}
if cmd.Flag("scheduler") == nil {
t.Errorf("Could not find the flag scheduler")
}

}
14 changes: 14 additions & 0 deletions pkg/cli/job/resume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package job

import (
"encoding/json"
"github.com/spf13/cobra"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -74,3 +75,16 @@ func TestResumeJob(t *testing.T) {
}

}

func TestInitResumeFlags(t *testing.T) {
var cmd cobra.Command
InitResumeFlags(&cmd)

if cmd.Flag("namespace") == nil {
t.Errorf("Could not find the flag namespace")
}
if cmd.Flag("name") == nil {
t.Errorf("Could not find the flag scheduler")
}

}
33 changes: 33 additions & 0 deletions pkg/cli/job/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package job

import (
"encoding/json"
"github.com/spf13/cobra"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -42,6 +43,7 @@ func TestCreateJob(t *testing.T) {

launchJobFlags.Master = server.URL
launchJobFlags.Namespace = "test"
launchJobFlags.Requests = "cpu=1000m,memory=100Mi"

testCases := []struct {
Name string
Expand All @@ -61,3 +63,34 @@ func TestCreateJob(t *testing.T) {
}

}

func TestInitRunFlags(t *testing.T) {
var cmd cobra.Command
InitRunFlags(&cmd)

if cmd.Flag("namespace") == nil {
t.Errorf("Could not find the flag namespace")
}
if cmd.Flag("scheduler") == nil {
t.Errorf("Could not find the flag scheduler")
}
if cmd.Flag("image") == nil {
t.Errorf("Could not find the flag image")
}
if cmd.Flag("replicas") == nil {
t.Errorf("Could not find the flag replicas")
}
if cmd.Flag("name") == nil {
t.Errorf("Could not find the flag name")
}
if cmd.Flag("min") == nil {
t.Errorf("Could not find the flag min")
}
if cmd.Flag("requests") == nil {
t.Errorf("Could not find the flag requests")
}
if cmd.Flag("limits") == nil {
t.Errorf("Could not find the flag limits")
}

}
14 changes: 14 additions & 0 deletions pkg/cli/job/suspend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package job

import (
"encoding/json"
"github.com/spf13/cobra"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -74,3 +75,16 @@ func TestSuspendJobJob(t *testing.T) {
}

}

func TestInitSuspendFlags(t *testing.T) {
var cmd cobra.Command
InitSuspendFlags(&cmd)

if cmd.Flag("namespace") == nil {
t.Errorf("Could not find the flag namespace")
}
if cmd.Flag("name") == nil {
t.Errorf("Could not find the flag name")
}

}
14 changes: 14 additions & 0 deletions pkg/cli/job/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package job

import (
"encoding/json"
"github.com/spf13/cobra"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -63,3 +64,16 @@ func TestViewJob(t *testing.T) {
}

}

func TestInitViewFlags(t *testing.T) {
var cmd cobra.Command
InitViewFlags(&cmd)

if cmd.Flag("namespace") == nil {
t.Errorf("Could not find the flag namespace")
}
if cmd.Flag("name") == nil {
t.Errorf("Could not find the flag name")
}

}
90 changes: 90 additions & 0 deletions pkg/controllers/apis/job_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vkbatchv1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

Expand Down Expand Up @@ -224,3 +225,92 @@ func TestUpdatePod(t *testing.T) {
}
}
}

func TestClone(t *testing.T) {

testCases := []struct {
Name string
jobinfo JobInfo

ExpectValue v1.PodPhase
}{
{
Name: "Clone",
jobinfo: JobInfo{
Name: "testjobInfo",
Pods: make(map[string]map[string]*v1.Pod),
},
},
}

for i, testcase := range testCases {
newjobinfo := testcase.jobinfo.Clone()

if newjobinfo.Name != testcase.jobinfo.Name {
t.Errorf("case %d (%s): expected: %v, got %v ", i, testcase.Name, testcase.jobinfo.Name, newjobinfo.Name)
}
}
}

func TestSetJob(t *testing.T) {

testCases := []struct {
Name string
job v1alpha1.Job
jobinfo JobInfo

ExpectValue v1.PodPhase
}{
{
Name: "Clone",
jobinfo: JobInfo{
Name: "testjobInfo",
Pods: make(map[string]map[string]*v1.Pod),
},
job: v1alpha1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "testjob",
},
},
},
}

for i, testcase := range testCases {
testcase.jobinfo.SetJob(&testcase.job)

if testcase.jobinfo.Job.Name != testcase.jobinfo.Name {
t.Errorf("case %d (%s): expected: %v, got %v ", i, testcase.Name, testcase.job.Name, testcase.jobinfo.Job.Name)
}
}
}

func TestRequest_String(t *testing.T) {
testCases := []struct {
Name string
req Request
ExpectedValue string
}{
{
Name: "RequestToString",
req: Request{
Namespace: "testnamespace",
JobName: "testjobname",
TaskName: "testtaskname",
Event: v1alpha1.AnyEvent,
ExitCode: 0,
Action: v1alpha1.SyncJobAction,
JobVersion: 0,
},
ExpectedValue: "Job: testnamespace/testjobname, Task:testtaskname, Event:*, ExitCode:0, Action:SyncJob, JobVersion: 0",
},
}

for i, testcase := range testCases {
reqString := testcase.req.String()

if reqString != testcase.ExpectedValue {
t.Errorf("case %d (%s): expected: %v, got %v ", i, testcase.Name, testcase.ExpectedValue, reqString)
}
}

}
23 changes: 23 additions & 0 deletions pkg/controllers/queue/queue_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package queue

import (
"fmt"
"testing"

kbv1alpha1 "github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1"
Expand Down Expand Up @@ -277,3 +278,25 @@ func TestSyncQueue(t *testing.T) {
}

}

func TestProcessNextWorkItem(t *testing.T) {
testCases := []struct {
Name string
ExpectValue int32
}{
{
Name: "processNextWorkItem",
ExpectValue: 0,
},
}

for i, testcase := range testCases {
c := newFakeController()
c.queue.Add("test")
bVal := c.processNextWorkItem()
fmt.Println("The value of boolean is ", bVal)
if c.queue.Len() != 0 {
t.Errorf("case %d (%s): expected: %v, got %v ", i, testcase.Name, testcase.ExpectValue, c.queue.Len())
}
}
}

0 comments on commit ae619b4

Please sign in to comment.