From 6334649720a11d14abb2283bd221ea7edd891d90 Mon Sep 17 00:00:00 2001 From: Jim Lambert Date: Fri, 11 Sep 2020 07:24:02 -0400 Subject: [PATCH] export AllocSession --- internal/session/repository.go | 6 +++--- internal/session/repository_test.go | 10 +++++----- internal/session/session.go | 4 ++-- internal/session/session_test.go | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/session/repository.go b/internal/session/repository.go index 66021882c3..b79e58a3b9 100644 --- a/internal/session/repository.go +++ b/internal/session/repository.go @@ -148,7 +148,7 @@ func (r *Repository) LookupSession(ctx context.Context, sessionId string, opt .. if sessionId == "" { return nil, nil, fmt.Errorf("lookup session: missing sessionId id: %w", db.ErrInvalidParameter) } - session := allocSession() + session := AllocSession() session.PublicId = sessionId var states []*State _, err := r.writer.DoTx( @@ -200,7 +200,7 @@ func (r *Repository) DeleteSession(ctx context.Context, publicId string, opt ... if publicId == "" { return db.NoRowsAffected, fmt.Errorf("delete session: missing public id %w", db.ErrInvalidParameter) } - session := allocSession() + session := AllocSession() session.PublicId = publicId if err := r.reader.LookupByPublicId(ctx, &session); err != nil { return db.NoRowsAffected, fmt.Errorf("delete session: failed %w for %s", err, publicId) @@ -365,7 +365,7 @@ func (r *Repository) UpdateState(ctx context.Context, sessionId string, sessionV return nil, nil, fmt.Errorf("update session state: unable to get oplog wrapper: %w", err) } - updatedSession := allocSession() + updatedSession := AllocSession() var returnedStates []*State _, err = r.writer.DoTx( ctx, diff --git a/internal/session/repository_test.go b/internal/session/repository_test.go index a739920ea3..89b98fd98d 100644 --- a/internal/session/repository_test.go +++ b/internal/session/repository_test.go @@ -157,7 +157,7 @@ func TestRepository_ListSession(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { assert, require := assert.New(t), require.New(t) - require.NoError(conn.Where("1=1").Delete(allocSession()).Error) + require.NoError(conn.Where("1=1").Delete(AllocSession()).Error) testSessions := []*Session{} for i := 0; i < tt.createCnt; i++ { s := TestSession(t, conn, composedOf) @@ -175,7 +175,7 @@ func TestRepository_ListSession(t *testing.T) { } t.Run("withOrder", func(t *testing.T) { assert, require := assert.New(t), require.New(t) - require.NoError(conn.Where("1=1").Delete(allocSession()).Error) + require.NoError(conn.Where("1=1").Delete(AllocSession()).Error) wantCnt := 5 for i := 0; i < wantCnt; i++ { _ = TestSession(t, conn, composedOf) @@ -194,7 +194,7 @@ func TestRepository_ListSession(t *testing.T) { }) t.Run("withUserId", func(t *testing.T) { assert, require := assert.New(t), require.New(t) - require.NoError(conn.Where("1=1").Delete(allocSession()).Error) + require.NoError(conn.Where("1=1").Delete(AllocSession()).Error) wantCnt := 5 for i := 0; i < wantCnt; i++ { _ = TestSession(t, conn, composedOf) @@ -640,7 +640,7 @@ func TestRepository_UpdateSession(t *testing.T) { composedOf := TestSessionParams(t, conn, wrapper, iamRepo) s := TestSession(t, conn, composedOf) - updateSession := allocSession() + updateSession := AllocSession() updateSession.PublicId = s.PublicId if tt.args.publicId != nil { updateSession.PublicId = *tt.args.publicId @@ -742,7 +742,7 @@ func TestRepository_DeleteSession(t *testing.T) { name: "no-public-id", args: args{ session: func() *Session { - s := allocSession() + s := AllocSession() return &s }(), }, diff --git a/internal/session/session.go b/internal/session/session.go index d280eec1c4..11d9e37718 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -60,8 +60,8 @@ func New(c ComposedOf, opt ...Option) (*Session, error) { return &s, nil } -// allocSession will allocate a Session -func allocSession() Session { +// AllocSession will allocate a Session +func AllocSession() Session { return Session{ Session: &store.Session{}, } diff --git a/internal/session/session_test.go b/internal/session/session_test.go index d4d47a88a5..8970c67d4e 100644 --- a/internal/session/session_test.go +++ b/internal/session/session_test.go @@ -173,7 +173,7 @@ func TestSession_Delete(t *testing.T) { { name: "bad-id", session: func() *Session { - s := allocSession() + s := AllocSession() id, err := db.NewPublicId(SessionPrefix) require.NoError(t, err) s.PublicId = id @@ -186,7 +186,7 @@ func TestSession_Delete(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { assert, require := assert.New(t), require.New(t) - deleteSession := allocSession() + deleteSession := AllocSession() deleteSession.PublicId = tt.session.PublicId deletedRows, err := rw.Delete(context.Background(), &deleteSession) if tt.wantErr { @@ -199,7 +199,7 @@ func TestSession_Delete(t *testing.T) { return } assert.Equal(tt.wantRowsDeleted, deletedRows) - foundSession := allocSession() + foundSession := AllocSession() foundSession.PublicId = tt.session.PublicId err = rw.LookupById(context.Background(), &foundSession) require.Error(err) @@ -251,9 +251,9 @@ func TestSession_SetTableName(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { assert, require := assert.New(t), require.New(t) - def := allocSession() + def := AllocSession() require.Equal(defaultTableName, def.TableName()) - s := allocSession() + s := AllocSession() s.SetTableName(tt.setNameTo) assert.Equal(tt.want, s.TableName()) })