Fix some tests
This commit is contained in:
parent
7c4ecf0858
commit
1769fe468a
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/nomad/helper"
|
||||
"github.com/hashicorp/nomad/testutil"
|
||||
"github.com/kr/pretty"
|
||||
)
|
||||
|
||||
func TestJobs_Register(t *testing.T) {
|
||||
|
@ -107,6 +108,9 @@ func TestJobs_Canonicalize(t *testing.T) {
|
|||
VaultToken: helper.StringToPtr(""),
|
||||
Status: helper.StringToPtr(""),
|
||||
StatusDescription: helper.StringToPtr(""),
|
||||
Stop: helper.BoolToPtr(false),
|
||||
Stable: helper.BoolToPtr(false),
|
||||
Version: helper.Uint64ToPtr(0),
|
||||
CreateIndex: helper.Uint64ToPtr(0),
|
||||
ModifyIndex: helper.Uint64ToPtr(0),
|
||||
JobModifyIndex: helper.Uint64ToPtr(0),
|
||||
|
@ -162,6 +166,9 @@ func TestJobs_Canonicalize(t *testing.T) {
|
|||
Priority: helper.IntToPtr(50),
|
||||
AllAtOnce: helper.BoolToPtr(false),
|
||||
VaultToken: helper.StringToPtr(""),
|
||||
Stop: helper.BoolToPtr(false),
|
||||
Stable: helper.BoolToPtr(false),
|
||||
Version: helper.Uint64ToPtr(0),
|
||||
Status: helper.StringToPtr(""),
|
||||
StatusDescription: helper.StringToPtr(""),
|
||||
CreateIndex: helper.Uint64ToPtr(0),
|
||||
|
@ -277,6 +284,9 @@ func TestJobs_Canonicalize(t *testing.T) {
|
|||
Type: helper.StringToPtr("service"),
|
||||
AllAtOnce: helper.BoolToPtr(false),
|
||||
VaultToken: helper.StringToPtr(""),
|
||||
Stop: helper.BoolToPtr(false),
|
||||
Stable: helper.BoolToPtr(false),
|
||||
Version: helper.Uint64ToPtr(0),
|
||||
Status: helper.StringToPtr(""),
|
||||
StatusDescription: helper.StringToPtr(""),
|
||||
CreateIndex: helper.Uint64ToPtr(0),
|
||||
|
@ -379,6 +389,9 @@ func TestJobs_Canonicalize(t *testing.T) {
|
|||
Priority: helper.IntToPtr(50),
|
||||
AllAtOnce: helper.BoolToPtr(false),
|
||||
VaultToken: helper.StringToPtr(""),
|
||||
Stop: helper.BoolToPtr(false),
|
||||
Stable: helper.BoolToPtr(false),
|
||||
Version: helper.Uint64ToPtr(0),
|
||||
Status: helper.StringToPtr(""),
|
||||
StatusDescription: helper.StringToPtr(""),
|
||||
CreateIndex: helper.Uint64ToPtr(0),
|
||||
|
@ -399,6 +412,7 @@ func TestJobs_Canonicalize(t *testing.T) {
|
|||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc.input.Canonicalize()
|
||||
if !reflect.DeepEqual(tc.input, tc.expected) {
|
||||
t.Logf("Name: %v, Diffs:\n%v", tc.name, pretty.Diff(tc.expected, tc.input))
|
||||
t.Fatalf("Name: %v, expected:\n%#v\nactual:\n%#v", tc.name, tc.expected, tc.input)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1142,7 +1142,7 @@ func TestStateStore_JobsByScheduler(t *testing.T) {
|
|||
|
||||
func TestStateStore_JobsByGC(t *testing.T) {
|
||||
state := testStateStore(t)
|
||||
var gc, nonGc []*structs.Job
|
||||
gc, nonGc := make(map[string]struct{}), make(map[string]struct{})
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
var job *structs.Job
|
||||
|
@ -1151,21 +1151,30 @@ func TestStateStore_JobsByGC(t *testing.T) {
|
|||
} else {
|
||||
job = mock.PeriodicJob()
|
||||
}
|
||||
nonGc = append(nonGc, job)
|
||||
nonGc[job.ID] = struct{}{}
|
||||
|
||||
if err := state.UpsertJob(1000+uint64(i), job); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := 0; i < 20; i += 2 {
|
||||
job := mock.Job()
|
||||
job.Type = structs.JobTypeBatch
|
||||
gc = append(gc, job)
|
||||
gc[job.ID] = struct{}{}
|
||||
|
||||
if err := state.UpsertJob(2000+uint64(i), job); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Create an eval for it
|
||||
eval := mock.Eval()
|
||||
eval.JobID = job.ID
|
||||
eval.Status = structs.EvalStatusComplete
|
||||
if err := state.UpsertEvals(2000+uint64(i+1), []*structs.Evaluation{eval}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ws := memdb.NewWatchSet()
|
||||
|
@ -1174,9 +1183,10 @@ func TestStateStore_JobsByGC(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
var outGc []*structs.Job
|
||||
outGc := make(map[string]struct{})
|
||||
for i := iter.Next(); i != nil; i = iter.Next() {
|
||||
outGc = append(outGc, i.(*structs.Job))
|
||||
j := i.(*structs.Job)
|
||||
outGc[j.ID] = struct{}{}
|
||||
}
|
||||
|
||||
iter, err = state.JobsByGC(ws, false)
|
||||
|
@ -1184,16 +1194,12 @@ func TestStateStore_JobsByGC(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
var outNonGc []*structs.Job
|
||||
outNonGc := make(map[string]struct{})
|
||||
for i := iter.Next(); i != nil; i = iter.Next() {
|
||||
outNonGc = append(outNonGc, i.(*structs.Job))
|
||||
j := i.(*structs.Job)
|
||||
outNonGc[j.ID] = struct{}{}
|
||||
}
|
||||
|
||||
sort.Sort(JobIDSort(gc))
|
||||
sort.Sort(JobIDSort(nonGc))
|
||||
sort.Sort(JobIDSort(outGc))
|
||||
sort.Sort(JobIDSort(outNonGc))
|
||||
|
||||
if !reflect.DeepEqual(gc, outGc) {
|
||||
t.Fatalf("bad: %#v %#v", gc, outGc)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue