mock cache for rest tests

This commit is contained in:
Umputun
2018-01-15 01:06:34 -06:00
parent 4ec94b5f85
commit 33976f8225
2 changed files with 17 additions and 9 deletions
+4 -2
View File
@@ -69,9 +69,11 @@ func (s *Server) Run(port int) {
// auth routes for all providers
router.Route("/auth", func(r chi.Router) {
for _, provider := range s.AuthProviders {
r.Mount("/"+provider.Name, provider.Routes())
r.Mount("/"+provider.Name, provider.Routes()) // mount auth providers as /auth/{name}
}
if len(s.AuthProviders) > 0 {
r.Get("/logout", s.AuthProviders[0].LogoutHandler) // shortcut, can be any of providers, all logouts do the same
}
r.Get("/logout", s.AuthProviders[0].LogoutHandler) // shortcut, can be any of providers, all logouts do the same
})
// api routes
+13 -7
View File
@@ -17,7 +17,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/umputun/remark/app/migrator"
"github.com/umputun/remark/app/rest/auth"
"github.com/umputun/remark/app/store"
)
@@ -336,12 +335,11 @@ func prep(t *testing.T) (srv *Server, port int) {
dataStore, err := store.NewBoltDB(store.BoltSite{FileName: testDb, SiteID: "radio-t"})
require.Nil(t, err)
srv = &Server{
DataService: store.Service{Interface: dataStore, EditDuration: 5 * time.Minute},
DevMode: true,
AuthFacebook: &auth.Provider{},
AuthGithub: &auth.Provider{},
AuthGoogle: &auth.Provider{},
Exporter: &migrator.Remark{DataStore: dataStore},
DataService: store.Service{Interface: dataStore, EditDuration: 5 * time.Minute},
DevMode: true,
AuthProviders: nil,
Exporter: &migrator.Remark{DataStore: dataStore},
Cache: &mockCache{},
}
go func() {
port = rand.Intn(50000) + 1025
@@ -382,3 +380,11 @@ func cleanup(srv *Server) {
srv.httpServer.Shutdown(context.Background())
os.Remove(testDb)
}
type mockCache struct{}
func (mc *mockCache) Get(key string, ttl time.Duration, fn func() ([]byte, error)) (data []byte, err error) {
return fn()
}
func (mc *mockCache) Flush() {}