Skip to content

Commit

Permalink
add session_id test
Browse files Browse the repository at this point in the history
  • Loading branch information
issueMel committed Mar 19, 2024
1 parent 7bc5370 commit 388e3ac
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions pkg/utils/session_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,39 @@ func TestGenerateSessionIdShouldEqual(t *testing.T) {
testCase := []struct {
a, b int64
c string
info string
}{
{100, 200, "100200"},
{-1, -1, "-1-1"},
{1<<63 - 1, 1<<63 - 1, "92233720368547758079223372036854775807"},
{1<<63 - 1, -1 << 63, "-92233720368547758089223372036854775807"},
{100, 200, "100200",
"GenerateSessionId with two positive numbers"},
{-1, -1, "-1-1",
"GenerateSessionId with two negative numbers"},
{1<<63 - 1, 1<<63 - 1, "92233720368547758079223372036854775807",
"GenerateSessionId with two MaxInt64"},
{1<<63 - 1, -1 << 63, "-92233720368547758089223372036854775807",
"GenerateSessionId with MaxInt64 and MinInt64"},
}

for _, tt := range testCase {
require.Equal(t, GenerateSessionId(tt.a, tt.b), tt.c)
require.Equal(t, GenerateSessionId(tt.a, tt.b), tt.c, tt.info)
}
}

func TestGenerateSessionIdShouldNotEqual(t *testing.T) {
testCase := []struct {
a, b int64
c string
info string
}{
{100, 200, "111222"},
{-1, -1, "-11"},
{-1, -1, "1-1"},
{1<<63 - 1, -1 << 63, "9223372036854775807-9223372036854775808"},
{100, 200, "111222",
"GenerateSessionId with two positive numbers"},
{-1, -1, "-11",
"GenerateSessionId with two negative numbers, case 1"},
{-1, -1, "1-1",
"GenerateSessionId with two negative numbers, case 2"},
{1<<63 - 1, -1 << 63, "9223372036854775807-9223372036854775808",
"GenerateSessionId with MaxInt64 and MinInt64"},
}

for _, tt := range testCase {
require.NotEqual(t, GenerateSessionId(tt.a, tt.b), tt.c)
require.NotEqual(t, GenerateSessionId(tt.a, tt.b), tt.c, tt.info)
}
}

0 comments on commit 388e3ac

Please sign in to comment.