From 7ea6619928f49523a14465817866d2f51ef00e65 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 2 Feb 2016 13:50:30 -0800 Subject: [PATCH] Tests --- command/util_test.go | 6 +++++- nomad/mock/mock.go | 1 + nomad/structs/structs.go | 3 +-- nomad/structs/structs_test.go | 11 ++++++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/command/util_test.go b/command/util_test.go index 5515a386552..c9bd741f6d0 100644 --- a/command/util_test.go +++ b/command/util_test.go @@ -40,7 +40,11 @@ func testServer( func testJob(jobID string) *api.Job { task := api.NewTask("task1", "exec"). - Require(&api.Resources{MemoryMB: 256}) + Require(&api.Resources{ + MemoryMB: 256, + DiskMB: 20, + CPU: 100, + }) group := api.NewTaskGroup("group1", 1). AddTask(task) diff --git a/nomad/mock/mock.go b/nomad/mock/mock.go index 13083588744..f6fa7b1bebb 100644 --- a/nomad/mock/mock.go +++ b/nomad/mock/mock.go @@ -106,6 +106,7 @@ func Job() *structs.Job { Resources: &structs.Resources{ CPU: 500, MemoryMB: 256, + DiskMB: 100, Networks: []*structs.NetworkResource{ &structs.NetworkResource{ MBits: 50, diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 9291762254d..52e65fa8780 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1616,8 +1616,7 @@ func (t *Task) Validate() error { // Validate the resources. if t.Resources == nil { mErr.Errors = append(mErr.Errors, errors.New("Missing task resources")) - } - if err := t.Resources.MeetsMinResources(); err != nil { + } else if err := t.Resources.MeetsMinResources(); err != nil { mErr.Errors = append(mErr.Errors, err) } diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 22e5dfea914..25b54311894 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -252,9 +252,14 @@ func TestTask_Validate(t *testing.T) { } task = &Task{ - Name: "web", - Driver: "docker", - Resources: &Resources{}, + Name: "web", + Driver: "docker", + Resources: &Resources{ + CPU: 100, + DiskMB: 100, + MemoryMB: 100, + IOPS: 10, + }, } err = task.Validate() if err != nil {