2024-07-02 11:57:45 +00:00
|
|
|
package render
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/gob"
|
|
|
|
"go-udemy-web-1/internal/config"
|
|
|
|
"go-udemy-web-1/internal/models"
|
2024-07-03 08:03:25 +00:00
|
|
|
"log"
|
2024-07-02 11:57:45 +00:00
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/alexedwards/scs/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
session *scs.SessionManager
|
|
|
|
testApp config.AppConfig
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
// what am I going to put in the session
|
|
|
|
gob.Register(models.Reservation{})
|
|
|
|
|
|
|
|
// change this to true when in production
|
|
|
|
testApp.InProduction = false
|
|
|
|
|
|
|
|
session = scs.New()
|
|
|
|
session.Lifetime = 24 * time.Hour
|
|
|
|
session.Cookie.Persist = true
|
|
|
|
session.Cookie.SameSite = http.SameSiteLaxMode
|
|
|
|
session.Cookie.Secure = testApp.InProduction
|
|
|
|
|
|
|
|
testApp.Session = session
|
|
|
|
|
2024-07-03 08:03:25 +00:00
|
|
|
infoLog := log.New(os.Stdout, "INFO\t", log.Ldate|log.Ltime)
|
|
|
|
testApp.InfoLog = infoLog
|
|
|
|
|
|
|
|
errorLog := log.New(os.Stdout, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile)
|
|
|
|
testApp.ErrorLog = errorLog
|
|
|
|
|
2024-07-02 11:57:45 +00:00
|
|
|
app = &testApp
|
|
|
|
|
|
|
|
os.Exit(m.Run())
|
|
|
|
}
|
|
|
|
|
|
|
|
type myWriter struct{}
|
|
|
|
|
|
|
|
func (tw *myWriter) Header() http.Header {
|
|
|
|
var h http.Header
|
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tw *myWriter) WriteHeader(i int) {}
|
|
|
|
|
|
|
|
func (tw *myWriter) Write(b []byte) (int, error) {
|
|
|
|
length := len(b)
|
|
|
|
return length, nil
|
|
|
|
}
|