Migrate Controller Repo Usage From Store To Server (#5609)
* Create Server Domain Package For Controller * Resolve Comments
This commit is contained in:
1 parent
f43f6e2788
commit
4cc5c07214
10 files changed
+119
-187
No files matched your search
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/server"
|
||||
"github.com/hashicorp/boundary/internal/server/store"
|
||||
"github.com/hashicorp/boundary/internal/session"
|
||||
"github.com/hashicorp/boundary/internal/target"
|
||||
"github.com/hashicorp/boundary/internal/target/tcp"
|
||||
@@ -49,10 +48,8 @@ func TestStatus(t *testing.T) {
|
||||
|
||||
serverRepo, err := server.NewRepository(ctx, rw, rw, kms)
|
||||
require.NoError(t, err)
|
||||
c := &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
|
||||
c := server.NewController("test_controller1", server.WithAddress("127.0.0.1"))
|
||||
_, err = serverRepo.UpsertController(ctx, c)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -483,10 +480,7 @@ func TestStatusSessionClosed(t *testing.T) {
|
||||
|
||||
serverRepo, err := server.NewRepository(ctx, rw, rw, kms)
|
||||
require.NoError(t, err)
|
||||
c := &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
c := server.NewController("test_controller1", server.WithAddress("127.0.0.1"))
|
||||
_, err = serverRepo.UpsertController(ctx, c)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -676,10 +670,7 @@ func TestStatusDeadConnection(t *testing.T) {
|
||||
serverRepo, err := server.NewRepository(ctx, rw, rw, kms)
|
||||
require.NoError(t, err)
|
||||
|
||||
c := &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
c := server.NewController("test_controller1", server.WithAddress("127.0.0.1"))
|
||||
_, err = serverRepo.UpsertController(ctx, c)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -831,10 +822,7 @@ func TestStatusWorkerWithKeyId(t *testing.T) {
|
||||
serverRepo, err := server.NewRepository(ctx, rw, rw, kms)
|
||||
require.NoError(t, err)
|
||||
|
||||
c := &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
c := server.NewController("test_controller1", server.WithAddress("127.0.0.1"))
|
||||
_, err = serverRepo.UpsertController(ctx, c)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -1034,10 +1022,7 @@ func TestStatusAuthorizedWorkers(t *testing.T) {
|
||||
serverRepo, err := server.NewRepository(ctx, rw, rw, kmsCache)
|
||||
require.NoError(t, err)
|
||||
|
||||
c := &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
c := server.NewController("test_controller1", server.WithAddress("127.0.0.1"))
|
||||
_, err = serverRepo.UpsertController(ctx, c)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -1240,10 +1225,7 @@ func TestWorkerOperationalStatus(t *testing.T) {
|
||||
serverRepo, err := server.NewRepository(ctx, rw, rw, kms)
|
||||
require.NoError(t, err)
|
||||
|
||||
c := &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
c := server.NewController("test_controller1", server.WithAddress("127.0.0.1"))
|
||||
_, err = serverRepo.UpsertController(ctx, c)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -1357,10 +1339,7 @@ func TestWorkerLocalStorageStateStatus(t *testing.T) {
|
||||
serverRepo, err := server.NewRepository(ctx, rw, rw, kms)
|
||||
require.NoError(t, err)
|
||||
|
||||
c := &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
c := server.NewController("test_controller1", server.WithAddress("127.0.0.1"))
|
||||
_, err = serverRepo.UpsertController(ctx, c)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/server"
|
||||
"github.com/hashicorp/boundary/internal/server/store"
|
||||
"github.com/hashicorp/boundary/internal/session"
|
||||
"github.com/hashicorp/boundary/internal/target"
|
||||
"github.com/hashicorp/boundary/internal/target/tcp"
|
||||
@@ -1015,10 +1014,7 @@ func TestSessionInfo(t *testing.T) {
|
||||
|
||||
serverRepo, err := server.NewRepository(ctx, rw, rw, testKms)
|
||||
require.NoError(err)
|
||||
c := &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
c := server.NewController("test_controller1", server.WithAddress("127.0.0.1"))
|
||||
_, err = serverRepo.UpsertController(ctx, c)
|
||||
require.NoError(err)
|
||||
|
||||
@@ -1158,10 +1154,7 @@ func TestRoutingInfo(t *testing.T) {
|
||||
_ = server.TestPkiWorker(t, conn, wrapper, server.WithTestPkiWorkerAuthorizedKeyId(&w2KeyId))
|
||||
w3 := server.TestKmsWorker(t, conn, wrapper, server.WithName("testworker3"))
|
||||
|
||||
c := &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "1.2.3.4",
|
||||
}
|
||||
c := server.NewController("test_controller1", server.WithAddress("1.2.3.4"))
|
||||
_, err = serverRepo.UpsertController(ctx, c)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/daemon/cluster"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/event"
|
||||
"github.com/hashicorp/boundary/internal/server/store"
|
||||
"github.com/hashicorp/boundary/internal/server"
|
||||
)
|
||||
|
||||
// In the future we could make this configurable
|
||||
@@ -46,10 +46,15 @@ func (c *Controller) startStatusTicking(cancelCtx context.Context) {
|
||||
|
||||
func (c *Controller) upsertController(ctx context.Context) error {
|
||||
const op = "controller.(Controller).upsertController"
|
||||
controller := &store.Controller{
|
||||
PrivateId: c.conf.RawConfig.Controller.Name,
|
||||
Address: c.conf.RawConfig.Controller.PublicClusterAddr,
|
||||
var opts []server.Option
|
||||
if c.conf.RawConfig.Controller.Description != "" {
|
||||
opts = append(opts, server.WithDescription(c.conf.RawConfig.Controller.Description))
|
||||
}
|
||||
if c.conf.RawConfig.Controller.PublicClusterAddr != "" {
|
||||
opts = append(opts, server.WithAddress(c.conf.RawConfig.Controller.PublicClusterAddr))
|
||||
}
|
||||
|
||||
controller := server.NewController(c.conf.RawConfig.Controller.Name, opts...)
|
||||
repo, err := c.ServersRepoFn()
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("error fetching repository for status upsert"))
|
||||
@@ -65,10 +70,14 @@ func (c *Controller) upsertController(ctx context.Context) error {
|
||||
|
||||
func (c *Controller) updateController(ctx context.Context) error {
|
||||
const op = "controller.(Controller).updateController"
|
||||
controller := &store.Controller{
|
||||
PrivateId: c.conf.RawConfig.Controller.Name,
|
||||
Address: c.conf.RawConfig.Controller.PublicClusterAddr,
|
||||
var opts []server.Option
|
||||
if c.conf.RawConfig.Controller.Description != "" {
|
||||
opts = append(opts, server.WithDescription(c.conf.RawConfig.Controller.Description))
|
||||
}
|
||||
if c.conf.RawConfig.Controller.PublicClusterAddr != "" {
|
||||
opts = append(opts, server.WithAddress(c.conf.RawConfig.Controller.PublicClusterAddr))
|
||||
}
|
||||
controller := server.NewController(c.conf.RawConfig.Controller.Name, opts...)
|
||||
repo, err := c.ServersRepoFn()
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("error fetching repository for status update"))
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/server/store"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/server"
|
||||
@@ -100,7 +98,7 @@ func testRunWithUpdateTime(conn *db.DB, pluginId, name, cId string, updateTime t
|
||||
return run, nil
|
||||
}
|
||||
|
||||
func testController(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...testOption) *store.Controller {
|
||||
func testController(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...testOption) *server.Controller {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
rw := db.New(conn)
|
||||
@@ -117,10 +115,7 @@ func testController(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...
|
||||
require.NoError(t, err)
|
||||
privateId = "test-job-server-" + id
|
||||
}
|
||||
controller := &store.Controller{
|
||||
PrivateId: privateId,
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
controller := server.NewController(privateId, server.WithAddress("127.0.0.1"))
|
||||
_, err = serversRepo.UpsertController(ctx, controller)
|
||||
require.NoError(t, err)
|
||||
return controller
|
||||
|
||||
@@ -5,12 +5,11 @@ package scheduler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/server/store"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
@@ -38,10 +37,8 @@ func TestScheduler(t testing.TB, conn *db.DB, wrapper wrapping.Wrapper, opt ...O
|
||||
|
||||
id, err := uuid.GenerateUUID()
|
||||
require.NoError(t, err)
|
||||
controller := &store.Controller{
|
||||
PrivateId: "test-job-server-" + id,
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
|
||||
controller := server.NewController(fmt.Sprintf("test-server-job%s", id), server.WithAddress("127.0.0.1"))
|
||||
_, err = serversRepo.UpsertController(ctx, controller)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package server
|
||||
|
||||
import "github.com/hashicorp/boundary/internal/server/store"
|
||||
|
||||
// Controller is a server that is responsible for understanding configuration,
|
||||
// authenticating and authorizing users, and serving user API requests (e.g. to
|
||||
// initiate a session). They also assign tasks to workers (session handling,
|
||||
// session recording parsing, etc.).
|
||||
type Controller struct {
|
||||
*store.Controller
|
||||
}
|
||||
|
||||
// NewController returns a new controller. Valid options are WithAddress and WithDescription.
|
||||
// All other options are ignored.
|
||||
func NewController(privateId string, opt ...Option) *Controller {
|
||||
opts := GetOpts(opt...)
|
||||
controller := &Controller{
|
||||
Controller: &store.Controller{
|
||||
PrivateId: privateId,
|
||||
Address: opts.withAddress,
|
||||
Description: opts.withDescription,
|
||||
},
|
||||
}
|
||||
|
||||
return controller
|
||||
}
|
||||
@@ -9,17 +9,16 @@ import (
|
||||
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/server/store"
|
||||
)
|
||||
|
||||
func (r *Repository) ListControllers(ctx context.Context, opt ...Option) ([]*store.Controller, error) {
|
||||
func (r *Repository) ListControllers(ctx context.Context, opt ...Option) ([]*Controller, error) {
|
||||
return r.listControllersWithReader(ctx, r.reader, opt...)
|
||||
}
|
||||
|
||||
// listControllersWithReader will return a listing of resources and honor the
|
||||
// WithLimit option or the repo defaultLimit. It accepts a reader, allowing it
|
||||
// to be used within a transaction or without.
|
||||
func (r *Repository) listControllersWithReader(ctx context.Context, reader db.Reader, opt ...Option) ([]*store.Controller, error) {
|
||||
func (r *Repository) listControllersWithReader(ctx context.Context, reader db.Reader, opt ...Option) ([]*Controller, error) {
|
||||
opts := GetOpts(opt...)
|
||||
liveness := opts.withLiveness
|
||||
if liveness == 0 {
|
||||
@@ -31,7 +30,7 @@ func (r *Repository) listControllersWithReader(ctx context.Context, reader db.Re
|
||||
where = fmt.Sprintf("update_time > now() - interval '%d seconds'", uint32(liveness.Seconds()))
|
||||
}
|
||||
|
||||
var controllers []*store.Controller
|
||||
var controllers []*Controller
|
||||
if err := reader.SearchWhere(
|
||||
ctx,
|
||||
&controllers,
|
||||
@@ -45,7 +44,7 @@ func (r *Repository) listControllersWithReader(ctx context.Context, reader db.Re
|
||||
return controllers, nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpsertController(ctx context.Context, controller *store.Controller) (int, error) {
|
||||
func (r *Repository) UpsertController(ctx context.Context, controller *Controller) (int, error) {
|
||||
const op = "server.(Repository).UpsertController"
|
||||
|
||||
if controller == nil {
|
||||
@@ -78,7 +77,7 @@ func (r *Repository) UpsertController(ctx context.Context, controller *store.Con
|
||||
return int(rowsUpdated), nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateController(ctx context.Context, controller *store.Controller) (int, error) {
|
||||
func (r *Repository) UpdateController(ctx context.Context, controller *Controller) (int, error) {
|
||||
const op = "server.(Repository).UpdateController"
|
||||
|
||||
if controller == nil {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/server/store"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -29,7 +28,7 @@ func TestRepository_UpsertController(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
controller *store.Controller
|
||||
controller *Controller
|
||||
wantCount int
|
||||
wantErr bool
|
||||
}{
|
||||
@@ -38,52 +37,34 @@ func TestRepository_UpsertController(t *testing.T) {
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "empty-id",
|
||||
controller: &store.Controller{
|
||||
PrivateId: "",
|
||||
Address: "127.0.0.1",
|
||||
},
|
||||
wantErr: true,
|
||||
name: "empty-id",
|
||||
controller: NewController("", WithAddress("127.0.0.1")),
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "empty-address",
|
||||
controller: &store.Controller{
|
||||
PrivateId: "test-controller",
|
||||
Address: "",
|
||||
},
|
||||
wantErr: true,
|
||||
name: "empty-address",
|
||||
controller: NewController("test-controller"),
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "valid-ipv4-controller",
|
||||
controller: &store.Controller{
|
||||
PrivateId: "test-ipv4-controller",
|
||||
Address: "127.0.0.1",
|
||||
},
|
||||
wantCount: 1,
|
||||
name: "valid-ipv4-controller",
|
||||
controller: NewController("ipv4-controller", WithAddress("127.0.0.1")),
|
||||
wantCount: 1,
|
||||
},
|
||||
{
|
||||
name: "valid-ipv6-controller",
|
||||
controller: &store.Controller{
|
||||
PrivateId: "test-ipv6-controller",
|
||||
Address: "[2001:4860:4860:0:0:0:0:8888]",
|
||||
},
|
||||
wantCount: 1,
|
||||
name: "valid-ipv6-controller",
|
||||
controller: NewController("test-ipv6-controller", WithAddress("[2001:4860:4860:0:0:0:0:8888]")),
|
||||
wantCount: 1,
|
||||
},
|
||||
{
|
||||
name: "valid-abbreviated-ipv6-controller",
|
||||
controller: &store.Controller{
|
||||
PrivateId: "test-abbreviated-ipv6-controller",
|
||||
Address: "[2001:4860:4860::8888]",
|
||||
},
|
||||
wantCount: 1,
|
||||
name: "valid-abbreviated-ipv6-controller",
|
||||
controller: NewController("test-abbreviated-ipv6-controller", WithAddress("[2001:4860:4860::8888]")),
|
||||
wantCount: 1,
|
||||
},
|
||||
{
|
||||
name: "valid-controller-short-name",
|
||||
controller: &store.Controller{
|
||||
PrivateId: "test",
|
||||
Address: "127.0.0.1",
|
||||
},
|
||||
wantCount: 1,
|
||||
name: "valid-controller-short-name",
|
||||
controller: NewController("test", WithAddress("127.0.0.1")),
|
||||
wantCount: 1,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -115,8 +96,8 @@ func TestRepository_UpdateController(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
originalController *store.Controller
|
||||
updatedController *store.Controller
|
||||
originalController *Controller
|
||||
updatedController *Controller
|
||||
wantCount int
|
||||
wantErr bool
|
||||
}{
|
||||
@@ -125,92 +106,50 @@ func TestRepository_UpdateController(t *testing.T) {
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "empty-id",
|
||||
updatedController: &store.Controller{
|
||||
PrivateId: "",
|
||||
Address: "127.0.0.1",
|
||||
},
|
||||
wantErr: true,
|
||||
name: "empty-id",
|
||||
updatedController: NewController("", WithAddress("127.0.0.1")),
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "empty-address",
|
||||
updatedController: &store.Controller{
|
||||
PrivateId: "test-controller",
|
||||
Address: "",
|
||||
},
|
||||
wantErr: true,
|
||||
name: "empty-address",
|
||||
updatedController: NewController("test-controller"),
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "controller-not-found",
|
||||
updatedController: &store.Controller{
|
||||
PrivateId: "test-new-ipv4-controller",
|
||||
Address: "127.0.0.1",
|
||||
Description: "new ipv4 description",
|
||||
},
|
||||
wantErr: true,
|
||||
name: "controller-not-found",
|
||||
updatedController: NewController("test-controller", WithAddress("127.0.0.1"), WithDescription("new ipv4 description")),
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "valid-ipv4-controller",
|
||||
originalController: &store.Controller{
|
||||
PrivateId: "ipv4-controller",
|
||||
Address: "127.0.0.1",
|
||||
Description: "ipv4 description",
|
||||
},
|
||||
updatedController: &store.Controller{
|
||||
PrivateId: "ipv4-controller",
|
||||
Address: "127.0.0.2",
|
||||
Description: "new ipv4 description",
|
||||
},
|
||||
wantCount: 1,
|
||||
name: "valid-ipv4-controller",
|
||||
originalController: NewController("ipv4-controller", WithAddress("127.0.0.1"), WithDescription("ipv4 description")),
|
||||
updatedController: NewController("ipv4-controller", WithAddress("127.0.0.2"), WithDescription("new ipv4 description")),
|
||||
wantCount: 1,
|
||||
},
|
||||
{
|
||||
name: "valid-ipv6-controller",
|
||||
originalController: &store.Controller{
|
||||
PrivateId: "test-ipv6-controller",
|
||||
Address: "[2001:4860:4860:0:0:0:0:8888]",
|
||||
Description: "ipv6 description",
|
||||
},
|
||||
updatedController: &store.Controller{
|
||||
PrivateId: "test-ipv6-controller",
|
||||
Address: "[2001:4860:4860:0:0:0:0:9999]",
|
||||
Description: "new ipv6 description",
|
||||
},
|
||||
wantCount: 1,
|
||||
name: "valid-ipv6-controller",
|
||||
originalController: NewController("test-ipv6-controller", WithAddress("[2001:4860:4860:0:0:0:0:8888]"), WithDescription("ipv6 description")),
|
||||
updatedController: NewController("test-ipv6-controller", WithAddress("[2001:4860:4860:0:0:0:0:9999]"), WithDescription("new ipv6 description")),
|
||||
wantCount: 1,
|
||||
},
|
||||
{
|
||||
name: "valid-abbreviated-ipv6-controller",
|
||||
originalController: &store.Controller{
|
||||
PrivateId: "test-abbreviated-ipv6-controller",
|
||||
Address: "[2001:4860:4860::8888]",
|
||||
Description: "abbreviated ipv6 description",
|
||||
},
|
||||
updatedController: &store.Controller{
|
||||
PrivateId: "test-abbreviated-ipv6-controller",
|
||||
Address: "[2001:4860:4860::9999]",
|
||||
Description: "new abbreviated ipv6 description",
|
||||
},
|
||||
wantCount: 1,
|
||||
name: "valid-abbreviated-ipv6-controller",
|
||||
originalController: NewController("test-abbreviated-ipv6-controller", WithAddress("[2001:4860:4860::8888]"), WithDescription("abbreviated ipv6 description")),
|
||||
updatedController: NewController("test-abbreviated-ipv6-controller", WithAddress("[2001:4860:4860::9999]"), WithDescription("new abbreviated ipv6 description")),
|
||||
wantCount: 1,
|
||||
},
|
||||
{
|
||||
name: "valid-controller-short-name",
|
||||
originalController: &store.Controller{
|
||||
PrivateId: "test",
|
||||
Address: "127.0.0.1",
|
||||
Description: "short name description",
|
||||
},
|
||||
updatedController: &store.Controller{
|
||||
PrivateId: "test",
|
||||
Address: "127.0.0.2",
|
||||
Description: "new short name description",
|
||||
},
|
||||
wantCount: 1,
|
||||
name: "valid-controller-short-name",
|
||||
originalController: NewController("test", WithAddress("127.0.0.1"), WithDescription("short name description")),
|
||||
updatedController: NewController("test", WithAddress("127.0.0.2"), WithDescription("new short name description")),
|
||||
wantCount: 1,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
|
||||
var originalControllerEntry, updatedControllerEntry *store.Controller
|
||||
var originalControllerEntry *Controller
|
||||
// Insert the original controller attributes if they exist
|
||||
if tt.originalController != nil {
|
||||
_, err := testRepo.UpsertController(ctx, tt.originalController)
|
||||
@@ -235,7 +174,7 @@ func TestRepository_UpdateController(t *testing.T) {
|
||||
// Retrieve the updated controller in the database and assert updated successfully
|
||||
controllerList, err := testRepo.ListControllers(ctx, []Option{}...)
|
||||
require.NoError(err)
|
||||
updatedControllerEntry = controllerList[len(controllerList)-1]
|
||||
updatedControllerEntry := controllerList[len(controllerList)-1]
|
||||
|
||||
assert.Equal(tt.updatedController.PrivateId, updatedControllerEntry.PrivateId)
|
||||
assert.Equal(tt.updatedController.Address, updatedControllerEntry.Address)
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/server"
|
||||
"github.com/hashicorp/boundary/internal/server/store"
|
||||
"github.com/hashicorp/boundary/internal/target"
|
||||
"github.com/hashicorp/boundary/internal/target/tcp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -32,10 +31,8 @@ func TestCloseOrphanedConnections(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
serverRepo, _ := server.NewRepository(context.Background(), rw, rw, testKms)
|
||||
_, err = serverRepo.UpsertController(context.Background(), &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
})
|
||||
c := server.NewController("test_controller1", server.WithAddress("127.0.0.1"))
|
||||
_, err = serverRepo.UpsertController(context.Background(), c)
|
||||
require.NoError(t, err)
|
||||
|
||||
cases := []struct {
|
||||
@@ -450,10 +447,8 @@ func TestUpdateConnectionBytesUpDown(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
serverRepo, _ := server.NewRepository(context.Background(), rw, rw, testKms)
|
||||
_, err = serverRepo.UpsertController(context.Background(), &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
})
|
||||
c := server.NewController("test_controller1", server.WithAddress("127.0.0.1"))
|
||||
_, err = serverRepo.UpsertController(context.Background(), c)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("nil connection repo", func(t *testing.T) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/server"
|
||||
"github.com/hashicorp/boundary/internal/server/store"
|
||||
"github.com/hashicorp/boundary/internal/session"
|
||||
"github.com/hashicorp/boundary/internal/target"
|
||||
"github.com/hashicorp/boundary/internal/target/tcp"
|
||||
@@ -30,10 +29,8 @@ func TestWorkerStatusReport(t *testing.T) {
|
||||
org, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
||||
|
||||
serverRepo, _ := server.NewRepository(ctx, rw, rw, kms)
|
||||
_, err := serverRepo.UpsertController(ctx, &store.Controller{
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
})
|
||||
c := server.NewController("test_controller1", server.WithAddress("127.0.0."))
|
||||
_, err := serverRepo.UpsertController(ctx, c)
|
||||
require.NoError(t, err)
|
||||
|
||||
repo, err := session.NewRepository(ctx, rw, rw, kms)
|
||||
|
||||
Reference in new issue
Block a user