open-nomad/internal/testing/apitests/util_test.go
Piotr Kazmierczak b63944b5c1
cleanup: replace TypeToPtr helper methods with pointer.Of (#14151)
Bumping compile time requirement to go 1.18 allows us to simplify our pointer helper methods.
2022-08-17 18:26:34 +02:00

64 lines
1.3 KiB
Go

package apitests
import (
"testing"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/helper/pointer"
)
func assertQueryMeta(t *testing.T, qm *api.QueryMeta) {
t.Helper()
if qm.LastIndex == 0 {
t.Fatalf("bad index: %d", qm.LastIndex)
}
if !qm.KnownLeader {
t.Fatalf("expected known leader, got none")
}
}
func assertWriteMeta(t *testing.T, wm *api.WriteMeta) {
t.Helper()
if wm.LastIndex == 0 {
t.Fatalf("bad index: %d", wm.LastIndex)
}
}
func testJob() *api.Job {
task := api.NewTask("task1", "exec").
SetConfig("command", "/bin/sleep").
Require(&api.Resources{
CPU: pointer.Of(100),
MemoryMB: pointer.Of(256),
}).
SetLogConfig(&api.LogConfig{
MaxFiles: pointer.Of(1),
MaxFileSizeMB: pointer.Of(2),
})
group := api.NewTaskGroup("group1", 1).
AddTask(task).
RequireDisk(&api.EphemeralDisk{
SizeMB: pointer.Of(25),
})
job := api.NewBatchJob("job1", "redis", "global", 1).
AddDatacenter("dc1").
AddTaskGroup(group)
return job
}
// conversions utils only used for testing
// added here to avoid linter warning
// int64ToPtr returns the pointer to an int
func int64ToPtr(i int64) *int64 {
return &i
}
// float64ToPtr returns the pointer to an float64
func float64ToPtr(f float64) *float64 {
return &f
}