forked from matrix-org/go-neb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoneb_services_test.go
56 lines (50 loc) · 1.21 KB
/
goneb_services_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"bytes"
"net/http"
"net/http/httptest"
"os"
"testing"
)
var mux = http.NewServeMux()
var mxTripper = newMatrixTripper()
func TestMain(m *testing.M) {
setup(envVars{
BaseURL: "http://go.neb",
DatabaseType: "sqlite3",
DatabaseURL: ":memory:",
}, mux, &http.Client{
Transport: mxTripper,
})
exitCode := m.Run()
os.Exit(exitCode)
}
func TestConfigureClient(t *testing.T) {
mxTripper.ClearHandlers()
mockWriter := httptest.NewRecorder()
syncChan := make(chan string)
mxTripper.HandlePOSTFilter("@link:hyrule")
mxTripper.Handle("GET", "/_matrix/client/r0/sync",
func(req *http.Request) (*http.Response, error) {
syncChan <- "sync"
return newResponse(200, `{
"next_batch":"11_22_33_44",
"rooms": {}
}`), nil
},
)
mockReq, _ := http.NewRequest("POST", "http://go.neb/admin/configureClient", bytes.NewBufferString(`
{
"UserID":"@link:hyrule",
"HomeserverURL":"http://hyrule.loz",
"AccessToken":"dangeroustogoalone",
"Sync":true,
"AutoJoinRooms":true
}`))
mux.ServeHTTP(mockWriter, mockReq)
expectCode := 200
if mockWriter.Code != expectCode {
t.Errorf("TestConfigureClient wanted HTTP status %d, got %d", expectCode, mockWriter.Code)
}
<-syncChan
}