Files
threshold/internal/scheduler/job/testing_test.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.4 KiB
Go
Raw Normal View History

2021-05-06 14:54:10 -07:00
// Copyright (c) HashiCorp, Inc.
2023-02-02 17:15:17 -08:00
// SPDX-License-Identifier: BUSL-1.1
2021-05-06 14:54:10 -07:00
package job
import (
"context"
"testing"
"time"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/iam"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_TestJob(t *testing.T) {
t.Parallel()
assert, require := assert.New(t), require.New(t)
conn, _ := db.TestSetup(t, "postgres")
wrapper := db.TestWrapper(t)
iam.TestRepo(t, conn, wrapper)
job := testJob(t, conn, "testJob", "testDescription", wrapper)
require.NotNil(job)
rw := db.New(conn)
var got Job
2022-10-25 18:29:38 -05:00
err := rw.LookupWhere(context.Background(), &got, "name = ?", []any{job.Name})
2021-05-06 14:54:10 -07:00
require.NoError(err)
assert.Equal("testJob", got.Name)
assert.Equal("testDescription", got.Description)
assert.Equal(defaultPluginId, got.PluginId)
assert.NotEmpty(got.NextScheduledRun)
job1 := testJob(t, conn, "testJob1", "testDescription1", wrapper, WithNextRunIn(time.Hour))
require.NotNil(job1)
var got1 Job
2022-10-25 18:29:38 -05:00
err = rw.LookupWhere(context.Background(), &got1, "name = ?", []any{job1.Name})
2021-05-06 14:54:10 -07:00
require.NoError(err)
assert.Equal("testJob1", got1.Name)
assert.Equal("testDescription1", got1.Description)
assert.Equal(defaultPluginId, got.PluginId)
assert.NotEmpty(got1.NextScheduledRun)
// The previous job next scheduled run should have been created with the current database time,
// while the current job should be an hour later
2021-06-11 11:36:14 -07:00
previousJobNextRun := got.NextScheduledRun.AsTime()
currentJobNextRun := got1.NextScheduledRun.AsTime()
assert.Equal(currentJobNextRun.Round(time.Minute), previousJobNextRun.Add(time.Hour).Round(time.Minute))
2021-05-06 14:54:10 -07:00
}
func Test_TestRun(t *testing.T) {
t.Parallel()
assert, require := assert.New(t), require.New(t)
conn, _ := db.TestSetup(t, "postgres")
wrapper := db.TestWrapper(t)
iam.TestRepo(t, conn, wrapper)
job := testJob(t, conn, "testJob", "testDescription", wrapper)
require.NotNil(job)
server := testController(t, conn, wrapper)
run, err := testRun(conn, job.PluginId, job.Name, server.PrivateId)
require.NoError(err)
require.NotNil(run)
rw := db.New(conn)
var got Run
2022-10-25 18:29:38 -05:00
err = rw.LookupWhere(context.Background(), &got, "private_id = ?", []any{run.PrivateId})
2021-05-06 14:54:10 -07:00
require.NoError(err)
assert.Equal(server.PrivateId, got.ControllerId)
2021-05-06 14:54:10 -07:00
assert.Equal(job.Name, got.JobName)
assert.Equal(job.PluginId, got.JobPluginId)
assert.NotEmpty(got.CreateTime)
assert.Equal(Running.string(), got.Status)
}