-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Prokopenko Andrey
committed
Jul 2, 2021
1 parent
de01a56
commit 00a5bad
Showing
4 changed files
with
205 additions
and
8 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,36 @@ | ||
package sqlite | ||
|
||
import ( | ||
"crawshaw.io/sqlite/sqlitex" | ||
"github.com/gin-contrib/sessions" | ||
"github.com/terem42/sqlite3store" | ||
) | ||
|
||
type Store interface { | ||
sessions.Store | ||
} | ||
|
||
func NewStore(db_file_location string, db_pool_size int, db_table_name string, sessions_options *sessions.Options, keyPairs ...[]byte) (Store, error) { | ||
s, err := sqlite3store.NewSqliteStore(db_file_location, db_pool_size, db_table_name, sessions_options.ToGorillaOptions(), keyPairs...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &store{s}, nil | ||
} | ||
|
||
//NewSqliteStoreFromExistingPool(dbpool *sqlitex.Pool, tableName string, sessions_options sessions.Options, keyPairs ...[]byte) (*SqliteStore, error) { | ||
func NewStoreFromExistingPool(dbpool *sqlitex.Pool, tableName string, sessions_options *sessions.Options, keyPairs ...[]byte) (Store, error) { | ||
s, err := sqlite3store.NewSqliteStoreFromExistingPool(dbpool, tableName, sessions_options.ToGorillaOptions(), keyPairs...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &store{s}, nil | ||
} | ||
|
||
type store struct { | ||
*sqlite3store.SqliteStore | ||
} | ||
|
||
func (c *store) Options(options sessions.Options) { | ||
c.SqliteStore.Options = options.ToGorillaOptions() | ||
} |
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,63 @@ | ||
package sqlite | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
"testing" | ||
|
||
"github.com/gin-contrib/sessions" | ||
"github.com/gin-contrib/sessions/tester" | ||
) | ||
|
||
var session_options = sessions.Options{ | ||
Path: "/", | ||
Domain: "localhost", | ||
MaxAge: 600, | ||
Secure: false, | ||
HttpOnly: false, | ||
SameSite: http.SameSiteDefaultMode, | ||
} | ||
var newStore = func(t *testing.T) sessions.Store { | ||
store, err := NewStore("test.db", 10, "sessions", &session_options, []byte("secret-key")) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
return store | ||
} | ||
|
||
func TestSqlite_SessionGetSet(t *testing.T) { | ||
tester.GetSet(t, newStore) | ||
t.Cleanup(cleanup) | ||
} | ||
|
||
func TestSqlite_SessionDeleteKey(t *testing.T) { | ||
tester.DeleteKey(t, newStore) | ||
t.Cleanup(cleanup) | ||
} | ||
|
||
func TestSqlite_SessionFlashes(t *testing.T) { | ||
tester.Flashes(t, newStore) | ||
t.Cleanup(cleanup) | ||
} | ||
|
||
func TestSqlite_SessionClear(t *testing.T) { | ||
tester.Clear(t, newStore) | ||
t.Cleanup(cleanup) | ||
} | ||
|
||
func TestSqlite_SessionOptions(t *testing.T) { | ||
tester.Options(t, newStore) | ||
t.Cleanup(cleanup) | ||
} | ||
|
||
func TestSqlite_SessionMany(t *testing.T) { | ||
tester.Many(t, newStore) | ||
t.Cleanup(cleanup) | ||
} | ||
|
||
func cleanup() { | ||
os.Remove("test.db") | ||
os.Remove("test.db-shm") | ||
os.Remove("test.db-wal") | ||
} |