aboutsummaryrefslogtreecommitdiff
path: root/appservice
diff options
context:
space:
mode:
authorTill Faelligen <2353100+S7evinK@users.noreply.github.com>2022-12-05 15:09:59 +0100
committerTill Faelligen <2353100+S7evinK@users.noreply.github.com>2022-12-05 15:09:59 +0100
commit07e8ed13f61fb04f6cac5a6d42263a9ddba49d32 (patch)
tree8bdc84c92010e985c9b9c8b0cd89d7f7ffa11f78 /appservice
parente245a26f6bcb4d134015f49f621b6d639a78707f (diff)
Fix CI and test.WithAllDatabases
Diffstat (limited to 'appservice')
-rw-r--r--appservice/appservice_test.go81
1 files changed, 40 insertions, 41 deletions
diff --git a/appservice/appservice_test.go b/appservice/appservice_test.go
index 5a3a9aef..72910d8d 100644
--- a/appservice/appservice_test.go
+++ b/appservice/appservice_test.go
@@ -77,32 +77,6 @@ func TestAppserviceInternalAPI(t *testing.T) {
}
}))
- // TODO: use test.WithAllDatabases
- // only one DBType, since appservice.AddInternalRoutes complains about multiple prometheus counters added
- base, closeBase := testrig.CreateBaseDendrite(t, test.DBTypeSQLite)
- defer closeBase()
-
- // Create a dummy application service
- base.Cfg.AppServiceAPI.Derived.ApplicationServices = []config.ApplicationService{
- {
- ID: "someID",
- URL: srv.URL,
- ASToken: "",
- HSToken: "",
- SenderLocalpart: "senderLocalPart",
- NamespaceMap: map[string][]config.ApplicationServiceNamespace{
- "users": {{RegexpObject: regexp.MustCompile("as-.*")}},
- "aliases": {{RegexpObject: regexp.MustCompile("asroom-.*")}},
- },
- Protocols: []string{existingProtocol},
- },
- }
-
- // Create required internal APIs
- rsAPI := roomserver.NewInternalAPI(base)
- usrAPI := userapi.NewInternalAPI(base, &base.Cfg.UserAPI, nil, nil, rsAPI, nil)
- asAPI := appservice.NewInternalAPI(base, usrAPI, rsAPI)
-
// The test cases to run
runCases := func(t *testing.T, testAPI api.AppServiceInternalAPI) {
t.Run("UserIDExists", func(t *testing.T) {
@@ -133,24 +107,49 @@ func TestAppserviceInternalAPI(t *testing.T) {
})
}
- // Finally execute the tests
- t.Run("HTTP API", func(t *testing.T) {
- router := mux.NewRouter().PathPrefix(httputil.InternalPathPrefix).Subrouter()
- appservice.AddInternalRoutes(router, asAPI)
- apiURL, cancel := test.ListenAndServe(t, router, false)
- defer cancel()
-
- asHTTPApi, err := inthttp.NewAppserviceClient(apiURL, &http.Client{})
- if err != nil {
- t.Fatalf("failed to create HTTP client: %s", err)
+ test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
+ base, closeBase := testrig.CreateBaseDendrite(t, test.DBTypeSQLite)
+ defer closeBase()
+
+ // Create a dummy application service
+ base.Cfg.AppServiceAPI.Derived.ApplicationServices = []config.ApplicationService{
+ {
+ ID: "someID",
+ URL: srv.URL,
+ ASToken: "",
+ HSToken: "",
+ SenderLocalpart: "senderLocalPart",
+ NamespaceMap: map[string][]config.ApplicationServiceNamespace{
+ "users": {{RegexpObject: regexp.MustCompile("as-.*")}},
+ "aliases": {{RegexpObject: regexp.MustCompile("asroom-.*")}},
+ },
+ Protocols: []string{existingProtocol},
+ },
}
- runCases(t, asHTTPApi)
- })
- t.Run("Monolith", func(t *testing.T) {
- runCases(t, asAPI)
- })
+ // Create required internal APIs
+ rsAPI := roomserver.NewInternalAPI(base)
+ usrAPI := userapi.NewInternalAPI(base, &base.Cfg.UserAPI, nil, nil, rsAPI, nil)
+ asAPI := appservice.NewInternalAPI(base, usrAPI, rsAPI)
+
+ // Finally execute the tests
+ t.Run("HTTP API", func(t *testing.T) {
+ router := mux.NewRouter().PathPrefix(httputil.InternalPathPrefix).Subrouter()
+ appservice.AddInternalRoutes(router, asAPI, base.EnableMetrics)
+ apiURL, cancel := test.ListenAndServe(t, router, false)
+ defer cancel()
+
+ asHTTPApi, err := inthttp.NewAppserviceClient(apiURL, &http.Client{})
+ if err != nil {
+ t.Fatalf("failed to create HTTP client: %s", err)
+ }
+ runCases(t, asHTTPApi)
+ })
+ t.Run("Monolith", func(t *testing.T) {
+ runCases(t, asAPI)
+ })
+ })
}
func testUserIDExists(t *testing.T, asAPI api.AppServiceInternalAPI, userID string, wantExists bool) {