* Remove the server_id from session table, change it to worker_id on session_connection This is step 1 in updating the worker table. The worker is becoming a public resource so it must have a public id. We drop the server_id column on the session_connection table and add the worker_id column so we can use the wt_public_key type. Since db migrations are applied while the controller is offline, it should be safe to assume all session connections are not in a running state, thus allowing us to null out all the worker ids in the session_connection table. For now we don't have very good enforcement of the wt_public_id contraints, since the id is currently defined in the worker config, but this will soon change and the worker's id will be generated by the controller. * Updating server_id references to controller_id. * Adding worker tag db writing test. * Move the server table back to the top. * Update comment for the worker object. * Update comment for the worker table. * Update the newWorkerId call to take a context and fix its error. * Correct comment for the wt_network_address domain.
77 lines
2.4 KiB
Go
77 lines
2.4 KiB
Go
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
|
|
err := rw.LookupWhere(context.Background(), &got, "name = ?", []interface{}{job.Name})
|
|
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
|
|
err = rw.LookupWhere(context.Background(), &got1, "name = ?", []interface{}{job1.Name})
|
|
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
|
|
previousJobNextRun := got.NextScheduledRun.AsTime()
|
|
currentJobNextRun := got1.NextScheduledRun.AsTime()
|
|
assert.Equal(currentJobNextRun.Round(time.Minute), previousJobNextRun.Add(time.Hour).Round(time.Minute))
|
|
}
|
|
|
|
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
|
|
err = rw.LookupWhere(context.Background(), &got, "private_id = ?", []interface{}{run.PrivateId})
|
|
require.NoError(err)
|
|
assert.Equal(server.PrivateId, got.ControllerId)
|
|
assert.Equal(job.Name, got.JobName)
|
|
assert.Equal(job.PluginId, got.JobPluginId)
|
|
assert.NotEmpty(got.CreateTime)
|
|
assert.Equal(Running.string(), got.Status)
|
|
}
|