Skip to content

Commit

Permalink
Standardise entry points for Complement tests (#669)
Browse files Browse the repository at this point in the history
* Always use the helpers package for the entry point for tests

* Move test main/package to top-level complement package

This reads much more nicely and clearly shows the entry point for
testing with complement.

* Remove Deploy proxy function as it is useless

* Use complement.Deploy everywhere

This ensures consistency with in-repo and out-of-repo tests, which
need to refer to the complement package.

* Fix helpful error messages when TestMain isn't called
  • Loading branch information
kegsay authored Oct 12, 2023
1 parent b2863ec commit f5a143c
Show file tree
Hide file tree
Showing 98 changed files with 324 additions and 323 deletions.
5 changes: 4 additions & 1 deletion helpers/test_main.go → test_main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helpers
package complement

import (
"fmt"
Expand Down Expand Up @@ -37,5 +37,8 @@ func TestMain(m *testing.M, namespace string) {
// which tests can interact with.
func Deploy(t *testing.T, blueprint b.Blueprint) *docker.Deployment {
t.Helper()
if testPackage == nil {
t.Fatalf("Deploy: testPackage not set, did you forget to call complement.TestMain?")
}
return testPackage.Deploy(t, blueprint)
}
5 changes: 1 addition & 4 deletions helpers/test_package.go → test_package.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helpers
package complement

import (
"context"
Expand Down Expand Up @@ -60,9 +60,6 @@ func (tp *TestPackage) Cleanup() {
func (tp *TestPackage) Deploy(t *testing.T, blueprint b.Blueprint) *docker.Deployment {
t.Helper()
timeStartBlueprint := time.Now()
if tp.complementBuilder == nil {
t.Fatalf("complementBuilder not set, did you forget to call TestMain?")
}
if err := tp.complementBuilder.ConstructBlueprintIfNotExist(blueprint); err != nil {
t.Fatalf("Deploy: Failed to construct blueprint: %s", err)
}
Expand Down
5 changes: 3 additions & 2 deletions tests/csapi/account_change_password_pushers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ package csapi_tests
import (
"testing"

"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"

"github.com/tidwall/gjson"
)

func TestChangePasswordPushers(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
password1 := "superuser"
password2 := "my_new_password"
Expand Down
5 changes: 3 additions & 2 deletions tests/csapi/account_change_password_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"io/ioutil"
"testing"

"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/internal/docker"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
Expand All @@ -14,7 +15,7 @@ import (
)

func TestChangePassword(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
password1 := "superuser"
password2 := "my_new_password"
Expand Down
3 changes: 2 additions & 1 deletion tests/csapi/account_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package csapi_tests
import (
"testing"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

func TestAddAccountData(t *testing.T) {
deployment := Deploy(t, b.BlueprintOneToOneRoom)
deployment := complement.Deploy(t, b.BlueprintOneToOneRoom)
defer deployment.Destroy(t)

alice := deployment.Client(t, "hs1", "@alice:hs1")
Expand Down
5 changes: 3 additions & 2 deletions tests/csapi/account_deactivate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (

"github.com/tidwall/gjson"

"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

func TestDeactivateAccount(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
password := "superuser"
authedClient := deployment.RegisterUser(t, "hs1", "test_deactivate_user", password, false)
Expand Down
5 changes: 3 additions & 2 deletions tests/csapi/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/tidwall/gjson"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
Expand All @@ -16,14 +17,14 @@ import (
// Check if this homeserver supports Synapse-style admin registration.
// Not all images support this currently.
func TestCanRegisterAdmin(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
deployment.RegisterUser(t, "hs1", "admin", "adminpassword", true)
}

// Test if the implemented /_synapse/admin/v1/send_server_notice behaves as expected
func TestServerNotices(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
admin := deployment.RegisterUser(t, "hs1", "admin", "adminpassword", true)
alice := deployment.Client(t, "hs1", "@alice:hs1")
Expand Down
3 changes: 2 additions & 1 deletion tests/csapi/apidoc_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"bytes"
"testing"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/internal/data"
)

func TestContent(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)

alice := deployment.Client(t, "hs1", "@alice:hs1")
Expand Down
5 changes: 3 additions & 2 deletions tests/csapi/apidoc_device_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (

"github.com/tidwall/gjson"

"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

func TestDeviceManagement(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
unauthedClient := deployment.Client(t, "hs1", "")
authedClient := deployment.RegisterUser(t, "hs1", "test_device_management_user", "superuser", false)
Expand Down
3 changes: 2 additions & 1 deletion tests/csapi/apidoc_login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (

"github.com/tidwall/gjson"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

func TestLogin(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
unauthedClient := deployment.Client(t, "hs1", "")
_ = deployment.RegisterUser(t, "hs1", "test_login_user", "superuser", false)
Expand Down
3 changes: 2 additions & 1 deletion tests/csapi/apidoc_logout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (

"github.com/tidwall/gjson"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

func TestLogout(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)

password := "superuser"
Expand Down
5 changes: 3 additions & 2 deletions tests/csapi/apidoc_presence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (

"github.com/tidwall/gjson"

"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

func TestPresence(t *testing.T) {
deployment := Deploy(t, b.BlueprintOneToOneRoom)
deployment := complement.Deploy(t, b.BlueprintOneToOneRoom)
defer deployment.Destroy(t)

alice := deployment.Client(t, "hs1", "@alice:hs1")
Expand Down
5 changes: 3 additions & 2 deletions tests/csapi/apidoc_profile_avatar_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package csapi_tests
import (
"testing"

"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

func TestProfileAvatarURL(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
unauthedClient := deployment.Client(t, "hs1", "")
authedClient := deployment.Client(t, "hs1", "@alice:hs1")
Expand Down
5 changes: 3 additions & 2 deletions tests/csapi/apidoc_profile_displayname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package csapi_tests
import (
"testing"

"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

func TestProfileDisplayName(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
unauthedClient := deployment.Client(t, "hs1", "")
authedClient := deployment.Client(t, "hs1", "@alice:hs1")
Expand Down
3 changes: 2 additions & 1 deletion tests/csapi/apidoc_register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/tidwall/gjson"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
Expand All @@ -34,7 +35,7 @@ import (
// Can register using an email address

func TestRegistration(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
unauthedClient := deployment.Client(t, "hs1", "")
t.Run("parallel", func(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions tests/csapi/apidoc_request_encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (

"encoding/json"

"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

func TestRequestEncodingFails(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
unauthedClient := deployment.Client(t, "hs1", "")
testString := `{ "test":"a` + "\x81" + `" }`
Expand Down
7 changes: 4 additions & 3 deletions tests/csapi/apidoc_room_alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/tidwall/gjson"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
Expand Down Expand Up @@ -59,7 +60,7 @@ func mustSetCanonicalAlias(t *testing.T, c *client.CSAPI, roomID string, roomAli
}

func TestRoomAlias(t *testing.T) {
deployment := Deploy(t, b.BlueprintOneToOneRoom)
deployment := complement.Deploy(t, b.BlueprintOneToOneRoom)
defer deployment.Destroy(t)
alice := deployment.Client(t, "hs1", "@alice:hs1")
bob := deployment.Client(t, "hs1", "@bob:hs1")
Expand Down Expand Up @@ -185,7 +186,7 @@ func TestRoomAlias(t *testing.T) {
}

func TestRoomDeleteAlias(t *testing.T) {
deployment := Deploy(t, b.BlueprintOneToOneRoom)
deployment := complement.Deploy(t, b.BlueprintOneToOneRoom)
defer deployment.Destroy(t)
alice := deployment.Client(t, "hs1", "@alice:hs1")
bob := deployment.Client(t, "hs1", "@bob:hs1")
Expand Down Expand Up @@ -456,7 +457,7 @@ func TestRoomDeleteAlias(t *testing.T) {
}

func TestRoomCanonicalAlias(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
deployment := complement.Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)
alice := deployment.Client(t, "hs1", "@alice:hs1")

Expand Down
3 changes: 2 additions & 1 deletion tests/csapi/apidoc_room_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (

"github.com/tidwall/gjson"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

func TestRoomCreate(t *testing.T) {
deployment := Deploy(t, b.BlueprintOneToOneRoom)
deployment := complement.Deploy(t, b.BlueprintOneToOneRoom)
defer deployment.Destroy(t)

alice := deployment.Client(t, "hs1", "@alice:hs1")
Expand Down
3 changes: 2 additions & 1 deletion tests/csapi/apidoc_room_forget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/tidwall/gjson"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/match"
Expand All @@ -16,7 +17,7 @@ import (

// These tests ensure that forgetting about rooms works as intended
func TestRoomForget(t *testing.T) {
deployment := Deploy(t, b.BlueprintOneToOneRoom)
deployment := complement.Deploy(t, b.BlueprintOneToOneRoom)
defer deployment.Destroy(t)

alice := deployment.Client(t, "hs1", "@alice:hs1")
Expand Down
Loading

0 comments on commit f5a143c

Please sign in to comment.