export AllocSession

jimlambrt-session-basics
Jim Lambert 6 years ago
parent 970d769c0e
commit 6334649720

@ -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,

@ -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
}(),
},

@ -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{},
}

@ -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())
})

Loading…
Cancel
Save