2015-09-09 01:42:34 +00:00
|
|
|
package api
|
|
|
|
|
2017-02-06 19:48:28 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
2015-09-09 01:42:34 +00:00
|
|
|
|
|
|
|
func assertQueryMeta(t *testing.T, qm *QueryMeta) {
|
2018-03-21 17:13:26 +00:00
|
|
|
t.Helper()
|
2015-09-09 01:42:34 +00:00
|
|
|
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 *WriteMeta) {
|
2018-03-21 17:13:26 +00:00
|
|
|
t.Helper()
|
2015-09-09 01:42:34 +00:00
|
|
|
if wm.LastIndex == 0 {
|
|
|
|
t.Fatalf("bad index: %d", wm.LastIndex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testJob() *Job {
|
2015-09-16 18:42:08 +00:00
|
|
|
task := NewTask("task1", "exec").
|
2016-04-13 22:55:46 +00:00
|
|
|
SetConfig("command", "/bin/sleep").
|
2016-02-02 21:26:12 +00:00
|
|
|
Require(&Resources{
|
2019-01-18 18:28:35 +00:00
|
|
|
CPU: intToPtr(100),
|
|
|
|
MemoryMB: intToPtr(256),
|
2016-02-19 23:49:32 +00:00
|
|
|
}).
|
2016-02-10 21:36:47 +00:00
|
|
|
SetLogConfig(&LogConfig{
|
2019-01-18 18:28:35 +00:00
|
|
|
MaxFiles: intToPtr(1),
|
|
|
|
MaxFileSizeMB: intToPtr(2),
|
2016-02-19 23:49:32 +00:00
|
|
|
})
|
2015-09-16 18:42:08 +00:00
|
|
|
|
|
|
|
group := NewTaskGroup("group1", 1).
|
2016-08-26 03:10:25 +00:00
|
|
|
AddTask(task).
|
2016-09-14 22:43:42 +00:00
|
|
|
RequireDisk(&EphemeralDisk{
|
2019-01-18 18:28:35 +00:00
|
|
|
SizeMB: intToPtr(25),
|
2016-08-26 03:10:25 +00:00
|
|
|
})
|
2015-09-16 18:42:08 +00:00
|
|
|
|
|
|
|
job := NewBatchJob("job1", "redis", "region1", 1).
|
|
|
|
AddDatacenter("dc1").
|
|
|
|
AddTaskGroup(group)
|
|
|
|
|
|
|
|
return job
|
2015-09-09 01:42:34 +00:00
|
|
|
}
|
2016-01-13 18:19:53 +00:00
|
|
|
|
|
|
|
func testPeriodicJob() *Job {
|
|
|
|
job := testJob().AddPeriodicConfig(&PeriodicConfig{
|
2019-01-18 18:28:35 +00:00
|
|
|
Enabled: boolToPtr(true),
|
|
|
|
Spec: stringToPtr("*/30 * * * *"),
|
|
|
|
SpecType: stringToPtr("cron"),
|
2016-01-13 18:19:53 +00:00
|
|
|
})
|
|
|
|
return job
|
|
|
|
}
|
2017-09-07 23:56:15 +00:00
|
|
|
|
|
|
|
func testNamespace() *Namespace {
|
|
|
|
return &Namespace{
|
|
|
|
Name: "test-namespace",
|
|
|
|
Description: "Testing namespaces",
|
|
|
|
}
|
|
|
|
}
|
2017-10-13 21:36:02 +00:00
|
|
|
|
|
|
|
func testQuotaSpec() *QuotaSpec {
|
|
|
|
return &QuotaSpec{
|
|
|
|
Name: "test-namespace",
|
|
|
|
Description: "Testing namespaces",
|
|
|
|
Limits: []*QuotaLimit{
|
|
|
|
{
|
|
|
|
Region: "global",
|
|
|
|
RegionLimit: &Resources{
|
2019-01-18 18:28:35 +00:00
|
|
|
CPU: intToPtr(2000),
|
|
|
|
MemoryMB: intToPtr(2000),
|
2017-10-13 21:36:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2019-01-18 18:28:35 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|