From b97b5da470de9bec624187da75ecea0402d28592 Mon Sep 17 00:00:00 2001 From: Jim Lambert Date: Tue, 16 Jun 2020 19:31:15 -0400 Subject: [PATCH] add testProj --- internal/iam/testing.go | 17 +++++++++++++++++ internal/iam/testing_test.go | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/internal/iam/testing.go b/internal/iam/testing.go index 1c046e20a2..ca3f417fc4 100644 --- a/internal/iam/testing.go +++ b/internal/iam/testing.go @@ -54,6 +54,23 @@ func testOrg(t *testing.T, conn *gorm.DB, name, description string) (org *Scope) return o } +func testProject(t *testing.T, conn *gorm.DB, orgId string, opt ...Option) *Scope { + t.Helper() + require := require.New(t) + rw := db.New(conn) + wrapper := db.TestWrapper(t) + repo, err := NewRepository(rw, rw, wrapper) + require.NoError(err) + + p, err := NewProject(orgId, opt...) + require.NoError(err) + p, err = repo.CreateScope(context.Background(), p) + require.NoError(err) + require.NotNil(p) + require.NotEmpty(p.GetPublicId()) + return p +} + func testId(t *testing.T) string { t.Helper() id, err := uuid.GenerateUUID() diff --git a/internal/iam/testing_test.go b/internal/iam/testing_test.go index d2923e0f24..d967931b6a 100644 --- a/internal/iam/testing_test.go +++ b/internal/iam/testing_test.go @@ -27,6 +27,24 @@ func Test_testOrg(t *testing.T) { assert.NotEmpty(org.PublicId) } +func Test_testProj(t *testing.T) { + assert := assert.New(t) + + cleanup, conn, _ := db.TestSetup(t, "postgres") + defer func() { + err := cleanup() + assert.NoError(err) + err = conn.Close() + assert.NoError(err) + }() + id := testId(t) + + org := testOrg(t, conn, id, id) + proj := testProject(t, conn, org.PublicId, WithName(id), WithDescription(id)) + assert.Equal(id, proj.Name) + assert.Equal(id, proj.Description) + assert.NotEmpty(proj.PublicId) +} func Test_testId(t *testing.T) { assert := assert.New(t) id := testId(t)