aboutsummaryrefslogtreecommitdiff
path: root/userapi
diff options
context:
space:
mode:
authorTill Faelligen <2353100+S7evinK@users.noreply.github.com>2022-12-05 16:00:02 +0100
committerTill Faelligen <2353100+S7evinK@users.noreply.github.com>2022-12-05 16:00:02 +0100
commitb99349b18c28a1c27b5bd5df30853a3b7c689d02 (patch)
treeb70b47e0b794a3327ec48fa23350ee18d07a4c60 /userapi
parent3dc06bea81d58d26a2d52ffb04ceb04a8c70e928 (diff)
Use test.WithAllDatabases
Diffstat (limited to 'userapi')
-rw-r--r--userapi/userapi_test.go55
1 files changed, 28 insertions, 27 deletions
diff --git a/userapi/userapi_test.go b/userapi/userapi_test.go
index 60dd730f..8a19af19 100644
--- a/userapi/userapi_test.go
+++ b/userapi/userapi_test.go
@@ -27,14 +27,13 @@ import (
"golang.org/x/crypto/bcrypt"
"github.com/matrix-org/dendrite/internal/httputil"
+ "github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/test"
"github.com/matrix-org/dendrite/test/testrig"
"github.com/matrix-org/dendrite/userapi"
- "github.com/matrix-org/dendrite/userapi/inthttp"
-
- "github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/dendrite/userapi/internal"
+ "github.com/matrix-org/dendrite/userapi/inthttp"
"github.com/matrix-org/dendrite/userapi/storage"
)
@@ -79,19 +78,6 @@ func MustMakeInternalAPI(t *testing.T, opts apiTestOpts, dbType test.DBType) (ap
func TestQueryProfile(t *testing.T) {
aliceAvatarURL := "mxc://example.com/alice"
aliceDisplayName := "Alice"
- // only one DBType, since userapi.AddInternalRoutes complains about multiple prometheus counters added
- userAPI, accountDB, close := MustMakeInternalAPI(t, apiTestOpts{}, test.DBTypeSQLite)
- defer close()
- _, err := accountDB.CreateAccount(context.TODO(), "alice", serverName, "foobar", "", api.AccountTypeUser)
- if err != nil {
- t.Fatalf("failed to make account: %s", err)
- }
- if _, _, err := accountDB.SetAvatarURL(context.TODO(), "alice", serverName, aliceAvatarURL); err != nil {
- t.Fatalf("failed to set avatar url: %s", err)
- }
- if _, _, err := accountDB.SetDisplayName(context.TODO(), "alice", serverName, aliceDisplayName); err != nil {
- t.Fatalf("failed to set display name: %s", err)
- }
testCases := []struct {
req api.QueryProfileRequest
@@ -142,19 +128,34 @@ func TestQueryProfile(t *testing.T) {
}
}
- t.Run("HTTP API", func(t *testing.T) {
- router := mux.NewRouter().PathPrefix(httputil.InternalPathPrefix).Subrouter()
- userapi.AddInternalRoutes(router, userAPI, false)
- apiURL, cancel := test.ListenAndServe(t, router, false)
- defer cancel()
- httpAPI, err := inthttp.NewUserAPIClient(apiURL, &http.Client{})
+ test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
+ userAPI, accountDB, close := MustMakeInternalAPI(t, apiTestOpts{}, dbType)
+ defer close()
+ _, err := accountDB.CreateAccount(context.TODO(), "alice", serverName, "foobar", "", api.AccountTypeUser)
if err != nil {
- t.Fatalf("failed to create HTTP client")
+ t.Fatalf("failed to make account: %s", err)
}
- runCases(httpAPI, true)
- })
- t.Run("Monolith", func(t *testing.T) {
- runCases(userAPI, false)
+ if _, _, err := accountDB.SetAvatarURL(context.TODO(), "alice", serverName, aliceAvatarURL); err != nil {
+ t.Fatalf("failed to set avatar url: %s", err)
+ }
+ if _, _, err := accountDB.SetDisplayName(context.TODO(), "alice", serverName, aliceDisplayName); err != nil {
+ t.Fatalf("failed to set display name: %s", err)
+ }
+
+ t.Run("HTTP API", func(t *testing.T) {
+ router := mux.NewRouter().PathPrefix(httputil.InternalPathPrefix).Subrouter()
+ userapi.AddInternalRoutes(router, userAPI, false)
+ apiURL, cancel := test.ListenAndServe(t, router, false)
+ defer cancel()
+ httpAPI, err := inthttp.NewUserAPIClient(apiURL, &http.Client{})
+ if err != nil {
+ t.Fatalf("failed to create HTTP client")
+ }
+ runCases(httpAPI, true)
+ })
+ t.Run("Monolith", func(t *testing.T) {
+ runCases(userAPI, false)
+ })
})
}