2019-12-28 09:48:36 +01:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-04-20 13:50:28 +02:00
|
|
|
"time"
|
2019-12-28 09:48:36 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-04-20 13:50:28 +02:00
|
|
|
func TestSession_Create(t *testing.T) {
|
|
|
|
s := New(time.Hour, "testdata")
|
|
|
|
token := s.Create(23)
|
2019-12-28 09:48:36 +01:00
|
|
|
t.Logf("token: %s", token)
|
|
|
|
assert.Equal(t, 48, len(token))
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:50:28 +02:00
|
|
|
func TestSession_Delete(t *testing.T) {
|
|
|
|
s := New(time.Hour, "testdata")
|
|
|
|
s.Delete("abc")
|
2019-12-28 09:48:36 +01:00
|
|
|
}
|
|
|
|
|
2020-04-20 13:50:28 +02:00
|
|
|
func TestSession_Get(t *testing.T) {
|
|
|
|
s := New(time.Hour, "testdata")
|
|
|
|
token := s.Create(42)
|
2019-12-28 09:48:36 +01:00
|
|
|
t.Logf("token: %s", token)
|
|
|
|
assert.Equal(t, 48, len(token))
|
|
|
|
|
2020-04-20 13:50:28 +02:00
|
|
|
data, exists := s.Get(token)
|
2019-12-28 09:48:36 +01:00
|
|
|
|
|
|
|
assert.Equal(t, 42, data)
|
|
|
|
assert.True(t, exists)
|
|
|
|
|
2020-04-20 13:50:28 +02:00
|
|
|
s.Delete(token)
|
2019-12-28 09:48:36 +01:00
|
|
|
|
2020-04-20 13:50:28 +02:00
|
|
|
data, exists = s.Get(token)
|
2019-12-28 09:48:36 +01:00
|
|
|
|
|
|
|
assert.Nil(t, data)
|
2020-04-20 13:50:28 +02:00
|
|
|
assert.False(t, s.Exists(token))
|
2019-12-28 09:48:36 +01:00
|
|
|
}
|
|
|
|
|
2020-04-20 13:50:28 +02:00
|
|
|
func TestSession_Exists(t *testing.T) {
|
|
|
|
s := New(time.Hour, "testdata")
|
|
|
|
assert.False(t, s.Exists("xyz"))
|
|
|
|
token := s.Create(23)
|
2019-12-28 09:48:36 +01:00
|
|
|
t.Logf("token: %s", token)
|
|
|
|
assert.Equal(t, 48, len(token))
|
2020-04-20 13:50:28 +02:00
|
|
|
assert.True(t, s.Exists(token))
|
|
|
|
s.Delete(token)
|
|
|
|
assert.False(t, s.Exists(token))
|
2019-12-28 09:48:36 +01:00
|
|
|
}
|