From 93c3b6ad2e14dc4b1e5ef19fc1bd12e13c8a07d9 Mon Sep 17 00:00:00 2001 From: Jim Lambert Date: Sat, 12 Sep 2020 20:01:05 -0400 Subject: [PATCH] add newConnectionStateId with unit test --- internal/session/ids.go | 11 +++++++++++ internal/session/ids_test.go | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/internal/session/ids.go b/internal/session/ids.go index 5142503650..6f0fc76b86 100644 --- a/internal/session/ids.go +++ b/internal/session/ids.go @@ -15,6 +15,9 @@ const ( // ConnectionPrefix for connection PK ids ConnectionPrefix = "sc" + + // ConnectionStatePrefix for connection state PK ids + ConnectionStatePrefix = "scs" ) func newId() (string, error) { @@ -40,3 +43,11 @@ func newConnectionId() (string, error) { } return id, nil } + +func newConnectionStateId() (string, error) { + id, err := db.NewPublicId(ConnectionStatePrefix) + if err != nil { + return "", fmt.Errorf("new session connection state id: %w", err) + } + return id, nil +} diff --git a/internal/session/ids_test.go b/internal/session/ids_test.go index 4c83f2847f..0c49fc3129 100644 --- a/internal/session/ids_test.go +++ b/internal/session/ids_test.go @@ -25,4 +25,9 @@ func Test_Ids(t *testing.T) { require.NoError(t, err) assert.True(t, strings.HasPrefix(id, ConnectionPrefix+"_")) }) + t.Run("scs", func(t *testing.T) { + id, err := newConnectionStateId() + require.NoError(t, err) + assert.True(t, strings.HasPrefix(id, ConnectionStatePrefix+"_")) + }) }