From 253101980a4a332d6bf655057d039bf211c94c1a Mon Sep 17 00:00:00 2001 From: Jim Lambert Date: Sat, 12 Sep 2020 19:54:56 -0400 Subject: [PATCH] add newConnectionId 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 4b32cd84d8..5142503650 100644 --- a/internal/session/ids.go +++ b/internal/session/ids.go @@ -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 +} diff --git a/internal/session/ids_test.go b/internal/session/ids_test.go index 44d48d323c..4c83f2847f 100644 --- a/internal/session/ids_test.go +++ b/internal/session/ids_test.go @@ -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+"_")) + }) }