-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sessiondata: introduce sessiondata.Stack
This stack keeps a track of SessionData objects for use in transaction-scoped variables. Release justification: low risk, high pri change Release note: None
- Loading branch information
Showing
3 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package sessiondata | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestStack(t *testing.T) { | ||
initialElem := &SessionData{ | ||
SessionData: sessiondatapb.SessionData{ | ||
ApplicationName: "bob", | ||
}, | ||
} | ||
secondElem := &SessionData{ | ||
SessionData: sessiondatapb.SessionData{ | ||
ApplicationName: "jane", | ||
}, | ||
} | ||
thirdElem := &SessionData{ | ||
SessionData: sessiondatapb.SessionData{ | ||
ApplicationName: "t-marts", | ||
}, | ||
} | ||
s := NewStack(initialElem) | ||
require.Equal(t, s.Top(), initialElem) | ||
require.EqualError(t, s.Pop(), "there must always be at least one element in the SessionData stack") | ||
|
||
s.Push(secondElem) | ||
require.Equal(t, s.Top(), secondElem) | ||
s.Push(thirdElem) | ||
require.Equal(t, s.Top(), thirdElem) | ||
|
||
require.NoError(t, s.Pop()) | ||
require.Equal(t, s.Top(), secondElem) | ||
require.NoError(t, s.Pop()) | ||
require.Equal(t, s.Top(), initialElem) | ||
require.EqualError(t, s.Pop(), "there must always be at least one element in the SessionData stack") | ||
} |