2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2019-03-29 18:47:40 +00:00
|
|
|
package apitests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/api"
|
2022-08-17 16:26:34 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/pointer"
|
2019-03-29 18:47:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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{
|
2022-08-17 16:26:34 +00:00
|
|
|
CPU: pointer.Of(100),
|
|
|
|
MemoryMB: pointer.Of(256),
|
2019-03-29 18:47:40 +00:00
|
|
|
}).
|
|
|
|
SetLogConfig(&api.LogConfig{
|
2022-08-17 16:26:34 +00:00
|
|
|
MaxFiles: pointer.Of(1),
|
|
|
|
MaxFileSizeMB: pointer.Of(2),
|
2019-03-29 18:47:40 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
group := api.NewTaskGroup("group1", 1).
|
|
|
|
AddTask(task).
|
|
|
|
RequireDisk(&api.EphemeralDisk{
|
2022-08-17 16:26:34 +00:00
|
|
|
SizeMB: pointer.Of(25),
|
2019-03-29 18:47:40 +00:00
|
|
|
})
|
|
|
|
|
2019-05-02 20:00:21 +00:00
|
|
|
job := api.NewBatchJob("job1", "redis", "global", 1).
|
2019-03-29 18:47:40 +00:00
|
|
|
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
|
|
|
|
}
|