diff --git a/internal/host/static/host_set_member_test.go b/internal/host/static/host_set_member_test.go index 0272e6a7b..1d5b71037 100644 --- a/internal/host/static/host_set_member_test.go +++ b/internal/host/static/host_set_member_test.go @@ -20,13 +20,13 @@ func TestHostSetMember_New(t *testing.T) { cats := TestCatalogs(t, conn, prj.PublicId, 2) blueCat := cats[0] - blueSets := testSets(t, conn, blueCat.GetPublicId(), 2) + blueSets := TestSets(t, conn, blueCat.GetPublicId(), 2) blueHosts := TestHosts(t, conn, blueCat.GetPublicId(), 2) // TODO(mgaffney) 05/2020: // these will be needed when the repository code is done // greenCat := cats[1] - // greenSets := testSets(t, conn, greenCat.GetPublicId(), 2) + // greenSets := TestSets(t, conn, greenCat.GetPublicId(), 2) // greenHosts := TestHosts(t, conn, greenCat.GetPublicId(), 2) var tests = []struct { diff --git a/internal/host/static/host_set_test.go b/internal/host/static/host_set_test.go index 5ef60f6d3..05b7c84c8 100644 --- a/internal/host/static/host_set_test.go +++ b/internal/host/static/host_set_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/boundary/internal/db" "github.com/hashicorp/boundary/internal/host/static/store" "github.com/hashicorp/boundary/internal/iam" - "github.com/jinzhu/gorm" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -110,28 +109,6 @@ func TestHostSet_New(t *testing.T) { } } -func testSets(t *testing.T, conn *gorm.DB, catalogId string, count int) []*HostSet { - t.Helper() - assert := assert.New(t) - var sets []*HostSet - - for i := 0; i < count; i++ { - set, err := NewHostSet(catalogId) - assert.NoError(err) - assert.NotNil(set) - id, err := newHostSetId() - assert.NoError(err) - assert.NotEmpty(id) - set.PublicId = id - - w := db.New(conn) - err2 := w.Create(context.Background(), set) - assert.NoError(err2) - sets = append(sets, set) - } - return sets -} - func TestHostSet_SetTableName(t *testing.T) { defaultTableName := "static_host_set" tests := []struct { diff --git a/internal/host/static/immutable_fields_test.go b/internal/host/static/immutable_fields_test.go index e87374e3d..6808f538c 100644 --- a/internal/host/static/immutable_fields_test.go +++ b/internal/host/static/immutable_fields_test.go @@ -162,7 +162,7 @@ func TestStaticHostSet_ImmutableFields(t *testing.T) { ts := timestamp.Timestamp{Timestamp: ×tamppb.Timestamp{Seconds: 0, Nanos: 0}} _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) cat := testCatalog(t, conn, prj.PublicId) - sets := testSets(t, conn, cat.GetPublicId(), 1) + sets := TestSets(t, conn, cat.GetPublicId(), 1) new := sets[0] @@ -236,7 +236,7 @@ func TestStaticHostSetMember_ImmutableFields(t *testing.T) { _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) cat := testCatalog(t, conn, prj.PublicId) - sets := testSets(t, conn, cat.GetPublicId(), 1) + sets := TestSets(t, conn, cat.GetPublicId(), 1) hosts := TestHosts(t, conn, cat.GetPublicId(), 1) new, err := NewHostSetMember(sets[0].PublicId, hosts[0].PublicId) diff --git a/internal/host/static/repository_host_set_test.go b/internal/host/static/repository_host_set_test.go index fc0000f18..63628a2b5 100644 --- a/internal/host/static/repository_host_set_test.go +++ b/internal/host/static/repository_host_set_test.go @@ -517,7 +517,7 @@ func TestRepository_UpdateSet(t *testing.T) { name := "test-dup-name" _, prj := iam.TestScopes(t, iamRepo) catalog := TestCatalogs(t, conn, prj.PublicId, 1)[0] - ss := testSets(t, conn, catalog.PublicId, 2) + ss := TestSets(t, conn, catalog.PublicId, 2) sA, sB := ss[0], ss[1] @@ -593,8 +593,8 @@ func TestRepository_UpdateSet(t *testing.T) { catalogA, catalogB := catalogs[0], catalogs[1] - sA := testSets(t, conn, catalogA.PublicId, 1)[0] - sB := testSets(t, conn, catalogB.PublicId, 1)[0] + sA := TestSets(t, conn, catalogA.PublicId, 1)[0] + sB := TestSets(t, conn, catalogB.PublicId, 1)[0] assert.NotEqual(sA.CatalogId, sB.CatalogId) orig := sA.clone() @@ -621,7 +621,7 @@ func TestRepository_LookupSet(t *testing.T) { _, prj := iam.TestScopes(t, iamRepo) catalog := TestCatalogs(t, conn, prj.PublicId, 1)[0] - hostSet := testSets(t, conn, catalog.PublicId, 1)[0] + hostSet := TestSets(t, conn, catalog.PublicId, 1)[0] hostSetId, err := newHostSetId() require.NoError(t, err) @@ -676,7 +676,7 @@ func TestRepository_ListSets(t *testing.T) { catalogs := TestCatalogs(t, conn, prj.PublicId, 2) catalogA, catalogB := catalogs[0], catalogs[1] - hostSets := testSets(t, conn, catalogA.PublicId, 3) + hostSets := TestSets(t, conn, catalogA.PublicId, 3) var tests = []struct { name string @@ -734,7 +734,7 @@ func TestRepository_ListSets_Limits(t *testing.T) { _, prj := iam.TestScopes(t, iamRepo) catalog := TestCatalogs(t, conn, prj.PublicId, 1)[0] count := 10 - hostSets := testSets(t, conn, catalog.PublicId, count) + hostSets := TestSets(t, conn, catalog.PublicId, count) var tests = []struct { name string @@ -803,7 +803,7 @@ func TestRepository_DeleteSet(t *testing.T) { _, prj := iam.TestScopes(t, iamRepo) catalog := TestCatalogs(t, conn, prj.PublicId, 1)[0] - hostSet := testSets(t, conn, catalog.PublicId, 1)[0] + hostSet := TestSets(t, conn, catalog.PublicId, 1)[0] newHostSetId, err := newHostSetId() require.NoError(t, err) diff --git a/internal/host/static/testing.go b/internal/host/static/testing.go index 445a556b7..f928b69f1 100644 --- a/internal/host/static/testing.go +++ b/internal/host/static/testing.go @@ -59,3 +59,28 @@ func TestHosts(t *testing.T, conn *gorm.DB, catalogId string, count int) []*Host } return hosts } + +// TestSets creates count number of static host sets in the provided DB +// with the provided catalog id. The catalog must have been created +// previously. The test will fail if any errors are encountered. +func TestSets(t *testing.T, conn *gorm.DB, catalogId string, count int) []*HostSet { + t.Helper() + assert := assert.New(t) + var sets []*HostSet + + for i := 0; i < count; i++ { + set, err := NewHostSet(catalogId) + assert.NoError(err) + assert.NotNil(set) + id, err := newHostSetId() + assert.NoError(err) + assert.NotEmpty(id) + set.PublicId = id + + w := db.New(conn) + err2 := w.Create(context.Background(), set) + assert.NoError(err2) + sets = append(sets, set) + } + return sets +} diff --git a/internal/host/static/testing_test.go b/internal/host/static/testing_test.go index 535908549..23e736d46 100644 --- a/internal/host/static/testing_test.go +++ b/internal/host/static/testing_test.go @@ -44,3 +44,23 @@ func Test_TestHosts(t *testing.T) { assert.NotEmpty(a.GetPublicId()) } } + +func Test_TestSets(t *testing.T) { + t.Helper() + assert, require := assert.New(t), require.New(t) + conn, _ := db.TestSetup(t, "postgres") + wrapper := db.TestWrapper(t) + _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) + + require.NotNil(prj) + assert.NotEmpty(prj.GetPublicId()) + + c := TestCatalogs(t, conn, prj.GetPublicId(), 1)[0] + + count := 4 + sets := TestSets(t, conn, c.GetPublicId(), count) + assert.Len(sets, count) + for _, s := range sets { + assert.NotEmpty(s.GetPublicId()) + } +}