* 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 constraints, 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.
79 lines
2.3 KiB
Go
79 lines
2.3 KiB
Go
package session
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
"github.com/hashicorp/boundary/internal/db/timestamp"
|
|
"github.com/stretchr/testify/assert"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
// Test_GetOpts provides unit tests for GetOpts and all the options
|
|
func Test_GetOpts(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("WithLimit", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
// test default of 0
|
|
opts := getOpts()
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withLimit = 0
|
|
assert.Equal(opts, testOpts)
|
|
|
|
opts = getOpts(WithLimit(-1))
|
|
testOpts = getDefaultOptions()
|
|
testOpts.withLimit = -1
|
|
assert.Equal(opts, testOpts)
|
|
|
|
opts = getOpts(WithLimit(1))
|
|
testOpts = getDefaultOptions()
|
|
testOpts.withLimit = 1
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithScopeId", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithScopeIds([]string{"o_1234"}))
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withScopeIds = []string{"o_1234"}
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithOrderByCreateTime", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithOrderByCreateTime(db.AscendingOrderBy))
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withOrderByCreateTime = db.AscendingOrderBy
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithUserId", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithUserId("u_1234"))
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withUserId = "u_1234"
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithExpirationTime", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
now := timestamppb.Now()
|
|
opts := getOpts(WithExpirationTime(×tamp.Timestamp{Timestamp: now}))
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withExpirationTime = ×tamp.Timestamp{Timestamp: now}
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithTestTofu", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
tofu := TestTofu(t)
|
|
opts := getOpts(WithTestTofu(tofu))
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withTestTofu = make([]byte, len(tofu))
|
|
copy(testOpts.withTestTofu, tofu)
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithSessionIds", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithSessionIds("s_1", "s_2", "s_3"))
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withSessionIds = []string{"s_1", "s_2", "s_3"}
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
}
|