add some docs for exported types and functions.

pull/347/head
Jim Lambert 6 years ago
parent c311419c3a
commit 970d769c0e

@ -7,8 +7,11 @@ import (
)
const (
// SessionPrefix for session PK ids
SessionPrefix = "s"
StatePrefix = "ss"
// StatePrefix for state PK ids
StatePrefix = "ss"
)
func newId() (string, error) {

@ -17,7 +17,7 @@ type Cloneable interface {
Clone() interface{}
}
// Repository is the target database repository
// Repository is the session database repository
type Repository struct {
reader db.Reader
writer db.Writer

@ -12,17 +12,26 @@ import (
)
const (
DefaultSessionTableName = "session"
defaultSessionTableName = "session"
)
// ComposedOf defines the boundary data that is referenced to compose a session.
type ComposedOf struct {
UserId string
HostId string
TargetId string
HostSetId string
// UserId of the session
UserId string
// HostId of the session
HostId string
// TargetId of the session
TargetId string
// HostSetId of the session
HostSetId string
// AuthTokenId of the session
AuthTokenId string
ScopeId string
// ScopeId of the session
ScopeId string
}
// Session contains information about a user's session with a target
type Session struct {
*store.Session
tableName string `gorm:"-"`
@ -110,7 +119,7 @@ func (s *Session) TableName() string {
if s.tableName != "" {
return s.tableName
}
return DefaultSessionTableName
return defaultSessionTableName
}
// SetTableName sets the tablename and satisfies the ReplayableMessage

@ -231,7 +231,7 @@ func TestSession_Clone(t *testing.T) {
func TestSession_SetTableName(t *testing.T) {
t.Parallel()
defaultTableName := DefaultSessionTableName
defaultTableName := defaultSessionTableName
tests := []struct {
name string
setNameTo string

@ -10,9 +10,10 @@ import (
)
const (
DefaultStateTableName = "session_state"
defaultStateTableName = "session_state"
)
// Status of the session's state
type Status string
const (
@ -22,10 +23,12 @@ const (
StatusClosed Status = "closed"
)
// String representation of the state's status
func (s Status) String() string {
return string(s)
}
// State of the session
type State struct {
*store.State
tableName string `gorm:"-"`
@ -79,7 +82,7 @@ func (s *State) TableName() string {
if s.tableName != "" {
return s.tableName
}
return DefaultStateTableName
return defaultStateTableName
}
// SetTableName sets the tablename and satisfies the ReplayableMessage

@ -185,7 +185,7 @@ func TestState_Clone(t *testing.T) {
func TestState_SetTableName(t *testing.T) {
t.Parallel()
defaultTableName := DefaultStateTableName
defaultTableName := defaultStateTableName
tests := []struct {
name string
setNameTo string

@ -6,6 +6,7 @@ import (
"github.com/hashicorp/boundary/internal/db"
)
// TerminationReason of the session
type TerminationReason string
const (
@ -17,6 +18,7 @@ const (
SystemError TerminationReason = "system error"
)
// String representation of the termination reason
func (r TerminationReason) String() string {
return string(r)
}

@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/require"
)
// TestState creates a test state for the sessionId in the repository.
func TestState(t *testing.T, conn *gorm.DB, sessionId string, state Status) *State {
t.Helper()
require := require.New(t)
@ -27,6 +28,7 @@ func TestState(t *testing.T, conn *gorm.DB, sessionId string, state Status) *Sta
return s
}
// TestSession creates a test session composed of c in the repository.
func TestSession(t *testing.T, conn *gorm.DB, c ComposedOf, opt ...Option) *Session {
t.Helper()
require := require.New(t)
@ -41,12 +43,15 @@ func TestSession(t *testing.T, conn *gorm.DB, c ComposedOf, opt ...Option) *Sess
return s
}
// TestDefaultSession creates a test session in the repository using defaults.
func TestDefaultSession(t *testing.T, conn *gorm.DB, wrapper wrapping.Wrapper, iamRepo *iam.Repository, opt ...Option) *Session {
t.Helper()
composedOf := TestSessionParams(t, conn, wrapper, iamRepo)
return TestSession(t, conn, composedOf)
}
// TestSessionParams returns an initialized ComposedOf which can be used to
// create a session in the repository.
func TestSessionParams(t *testing.T, conn *gorm.DB, wrapper wrapping.Wrapper, iamRepo *iam.Repository) ComposedOf {
t.Helper()
ctx := context.Background()

Loading…
Cancel
Save