2021-02-08 11:57:14 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"go.mindeco.de/http/tester"
|
|
|
|
|
|
|
|
"github.com/ssb-ngi-pointer/gossb-rooms/admindb/mockdb"
|
|
|
|
"github.com/ssb-ngi-pointer/gossb-rooms/internal/repo"
|
|
|
|
"github.com/ssb-ngi-pointer/gossb-rooms/web/router"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
testMux *http.ServeMux
|
|
|
|
testClient *tester.Tester
|
|
|
|
testRouter = router.CompleteApp()
|
|
|
|
|
|
|
|
// mocked dbs
|
2021-02-08 16:47:42 +00:00
|
|
|
testAuthDB *mockdb.FakeAuthWithSSBService
|
|
|
|
testAuthFallbackDB *mockdb.FakeAuthFallbackService
|
2021-02-08 11:57:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func setup(t *testing.T) {
|
|
|
|
|
|
|
|
testRepoPath := filepath.Join("testrun", t.Name())
|
|
|
|
os.RemoveAll(testRepoPath)
|
|
|
|
testRepo := repo.New(testRepoPath)
|
|
|
|
|
2021-02-08 16:47:42 +00:00
|
|
|
testAuthDB = new(mockdb.FakeAuthWithSSBService)
|
|
|
|
testAuthFallbackDB = new(mockdb.FakeAuthFallbackService)
|
2021-02-08 11:57:14 +00:00
|
|
|
h, err := New(
|
|
|
|
testRouter,
|
|
|
|
testRepo,
|
|
|
|
testAuthDB,
|
|
|
|
testAuthFallbackDB,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(errors.Wrap(err, "setup: handler init failed"))
|
|
|
|
}
|
|
|
|
|
|
|
|
// log, _ := logtest.KitLogger("complete", t)
|
|
|
|
|
|
|
|
testMux = http.NewServeMux()
|
|
|
|
testMux.Handle("/", h)
|
|
|
|
testClient = tester.New(testMux, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func teardown() {
|
|
|
|
testMux = nil
|
|
|
|
testClient = nil
|
2021-02-08 16:47:42 +00:00
|
|
|
testAuthDB = nil
|
2021-02-08 11:57:14 +00:00
|
|
|
testAuthFallbackDB = nil
|
|
|
|
}
|