bug(scheduler): Fix controller id length check (#2226)
* bug(scheduler): Fix controller id length check The job_run table has a foreign key to the server_controller private_id. While this column is called a prviate_id it does not implement the wt_private_id postgres domain type, and therefore does not have a minimum length of 10 characters.
This commit is contained in:
1 parent
86141ffb65
commit
4cacd0a605
8 files changed
+211
-5
No files matched your search
@@ -0,0 +1,83 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func TestRepository_UpsertController(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
testKms := kms.TestKms(t, conn, wrapper)
|
||||
testRepo, err := NewRepository(rw, rw, testKms)
|
||||
require.NoError(t, err)
|
||||
|
||||
iamRepo := iam.TestRepo(t, conn, wrapper)
|
||||
iam.TestScopes(t, iamRepo)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
controller *store.Controller
|
||||
wantCount int
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "nil-controller",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "empty-id",
|
||||
controller: &store.Controller{
|
||||
PrivateId: "",
|
||||
Address: "127.0.0.1",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "empty-address",
|
||||
controller: &store.Controller{
|
||||
PrivateId: "test-controller",
|
||||
Address: "",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "valid-controller",
|
||||
controller: &store.Controller{
|
||||
PrivateId: "test-controller",
|
||||
Address: "127.0.0.1",
|
||||
},
|
||||
wantCount: 1,
|
||||
},
|
||||
{
|
||||
name: "valid-controller-short-name",
|
||||
controller: &store.Controller{
|
||||
PrivateId: "test",
|
||||
Address: "127.0.0.1",
|
||||
},
|
||||
wantCount: 1,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
got, err := testRepo.UpsertController(ctx, tt.controller)
|
||||
if tt.wantErr {
|
||||
require.Error(err)
|
||||
assert.Equal(0, got)
|
||||
return
|
||||
}
|
||||
require.NoError(err)
|
||||
assert.Equal(tt.wantCount, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user