Skip to content

Commit c7e7dd2

Browse files
committed
Add unstable feature checking capability to skip a test that would not be supported
1 parent 5d4714f commit c7e7dd2

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

client/client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,17 @@ func (c *CSAPI) GetDefaultRoomVersion(t ct.TestLike) gomatrixserverlib.RoomVersi
520520
return gomatrixserverlib.RoomVersion(defaultVersion.Str)
521521
}
522522

523+
// GetVersions queries the server's client versions
524+
func (c *CSAPI) GetVersions(t ct.TestLike) []byte {
525+
t.Helper()
526+
res := c.MustDo(t, "GET", []string{"_matrix", "client", "versions"})
527+
body, err := io.ReadAll(res.Body)
528+
if err != nil {
529+
ct.Fatalf(t, "unable to read response body: %v", err)
530+
}
531+
return body
532+
}
533+
523534
// MustUploadKeys uploads device and/or one time keys to the server, returning the current OTK counts.
524535
// Both device keys and one time keys are optional. Fails the test if the upload fails.
525536
func (c *CSAPI) MustUploadKeys(t ct.TestLike, deviceKeys map[string]interface{}, oneTimeKeys map[string]interface{}) (otkCounts map[string]int) {

tests/msc3911/cs_api_restricted_media_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func TestRestrictedMediaUnstable(t *testing.T) {
3535

3636
alice.LoginUser(t, alice.UserID, "password")
3737

38+
// gjson look ups that have periods need to be escaped or it thinks it is a path to another object
39+
SkipTestIfNotCapable(t, alice, `org\.matrix\.msc3911`)
40+
3841
// Let's give alice a profile avatar
3942
aliceGlobalProfileAvatarMxcUri := alice.MustUploadContentRestricted(t, data.MatrixSvg, "alice_avatar.svg", "img/svg")
4043
alice.MustSetProfileAvatar(t, aliceGlobalProfileAvatarMxcUri)

tests/msc3911/federation_restricted_media_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func TestFederationRestrictedMediaUnstable(t *testing.T) {
4444

4545
alice.LoginUser(t, alice.UserID, "password")
4646

47+
// gjson look ups that have periods need to be escaped or it thinks it is a path to another object
48+
SkipTestIfNotCapable(t, alice, `org\.matrix\.msc3911`)
49+
4750
// Let's give alice a profile avatar
4851
aliceGlobalProfileAvatarMxcUri := alice.MustUploadContentRestricted(t, data.MatrixSvg, "alice_avatar.svg", "img/svg")
4952
alice.MustSetProfileAvatar(t, aliceGlobalProfileAvatarMxcUri)

tests/msc3911/main_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/matrix-org/complement/b"
88
"github.com/matrix-org/complement/client"
99
"github.com/matrix-org/complement/internal/data"
10+
"github.com/tidwall/gjson"
1011
)
1112

1213
func TestMain(m *testing.M) {
@@ -68,3 +69,15 @@ func MustUploadMediaAttachToMembershipEventAndSendIntoRoom(t *testing.T, sending
6869
event_id := sendingUser.SendEventWithAttachedMediaSynced(t, roomID, picture_message, mxcUri)
6970
return mxcUri, event_id
7071
}
72+
73+
// Check the server's client version endpoint for an unstable feature to be enabled. If it is not found, skip the test
74+
func SkipTestIfNotCapable(t *testing.T, client *client.CSAPI, feature string) {
75+
versionsObject := client.GetVersions(t)
76+
unstableFeatures := gjson.GetBytes(versionsObject, "unstable_features")
77+
78+
thingEnabled := unstableFeatures.Get(feature)
79+
if thingEnabled.Type != gjson.True {
80+
t.Skipf("%s not supported on this homeserver", feature)
81+
}
82+
83+
}

0 commit comments

Comments
 (0)