2022-03-12 18:06:39 +00:00
|
|
|
// package models
|
2022-02-23 12:07:09 +00:00
|
|
|
|
2022-03-12 18:06:39 +00:00
|
|
|
// import (
|
|
|
|
// "net/http"
|
|
|
|
// "testing"
|
2022-02-23 12:07:09 +00:00
|
|
|
|
2022-03-12 18:06:39 +00:00
|
|
|
// "git.technical.kiwi/go/otfe/misc/b64"
|
|
|
|
// "git.technical.kiwi/go/otfe/misc/helpers"
|
|
|
|
// "git.technical.kiwi/go/otfe/misc/rand"
|
|
|
|
// )
|
2022-02-23 12:07:09 +00:00
|
|
|
|
2022-03-12 18:06:39 +00:00
|
|
|
// func TestSessionCreate(t *testing.T) {
|
|
|
|
// var s1, s2 Session
|
|
|
|
// s1.ID, _ = rand.B64String(32)
|
|
|
|
// if s1.Create() != nil {
|
|
|
|
// t.Fail()
|
|
|
|
// }
|
|
|
|
// read("session", "_id", s1.ID, &s2)
|
2022-02-23 12:07:09 +00:00
|
|
|
|
2022-03-12 18:06:39 +00:00
|
|
|
// if s1.ID != s2.ID {
|
|
|
|
// t.Fail()
|
|
|
|
// }
|
|
|
|
// }
|
2022-02-23 12:07:09 +00:00
|
|
|
|
2022-03-12 18:06:39 +00:00
|
|
|
// func TestSessionRead(t *testing.T) {
|
|
|
|
// var s1, s2 Session
|
|
|
|
// s1.ID, _ = rand.B64String(32)
|
|
|
|
// if create("session", &s1) != nil {
|
|
|
|
// t.Fatal("Failed to create session")
|
|
|
|
// }
|
|
|
|
// if s2.Read(s1.ID) != nil {
|
|
|
|
// t.Fatal("Failed to read session")
|
|
|
|
// }
|
|
|
|
// if s1.ID != s2.ID {
|
|
|
|
// t.Fatal("Ids don't match")
|
|
|
|
// }
|
|
|
|
// }
|
2022-02-23 12:07:09 +00:00
|
|
|
|
2022-03-12 18:06:39 +00:00
|
|
|
// func TestGet(t *testing.T) {
|
|
|
|
// DBWipeCollection("session")
|
|
|
|
// var s1, s2 Session
|
|
|
|
// s1.ID, _ = rand.B64String(32)
|
|
|
|
// s1.Create()
|
|
|
|
// c := &http.Cookie{Name: "session",
|
|
|
|
// Value: b64.Encode(s1.ID)}
|
|
|
|
// request, err := http.NewRequest("GET", "/", nil)
|
|
|
|
// helpers.Ok(t, err)
|
|
|
|
// request.AddCookie(c)
|
|
|
|
// s2.Get(request)
|
|
|
|
// helpers.Equals(t, s1, s2)
|
|
|
|
// }
|