From 4748bfd869b2cb5c592ce46dfe8f7c97d3deda77 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 5515a3865..c9bd741f6 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 130835887..f6fa7b1be 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 929176225..52e65fa87 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 22e5dfea9..25b543118 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 {