add newConnectionId with unit test

jimlambrt-session-basics
Jim Lambert 6 years ago
parent f914de5bed
commit 253101980a

@ -12,6 +12,9 @@ const (
// StatePrefix for state PK ids
StatePrefix = "ss"
// ConnectionPrefix for connection PK ids
ConnectionPrefix = "sc"
)
func newId() (string, error) {
@ -29,3 +32,11 @@ func newStateId() (string, error) {
}
return id, nil
}
func newConnectionId() (string, error) {
id, err := db.NewPublicId(ConnectionPrefix)
if err != nil {
return "", fmt.Errorf("new session connection id: %w", err)
}
return id, nil
}

@ -20,4 +20,9 @@ func Test_Ids(t *testing.T) {
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, StatePrefix+"_"))
})
t.Run("sc", func(t *testing.T) {
id, err := newConnectionId()
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, ConnectionPrefix+"_"))
})
}

Loading…
Cancel
Save