-
Notifications
You must be signed in to change notification settings - Fork 66
Convert Sytest Name/topic keys are correct to Complement
#811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4468a3f
Convert Sytest `Name/topic keys are correct` to Complement
anoadragon453 835ba9a
Regenerate the list of converted sytests in the README
anoadragon453 320b79b
Merge branch 'main' of github.com:matrix-org/complement into anoa/syt…
anoadragon453 0ef2cf7
Update sytest coverage list
anoadragon453 f31eeff
Wait for `SyncUnitTimeout` instead of 15s arbitrarily
anoadragon453 2d2a8ab
Batch up all errors of a room before logging
anoadragon453 843789b
Use `GetFullyQualifiedHomeserverName`
anoadragon453 1f20acf
Print out unexpected rooms if we found any
anoadragon453 2d9a22c
foundRooms -> validatedRooms
anoadragon453 6958458
Convert to a separate test per room data config
anoadragon453 9e08bc7
Remove the room from the public rooms list at test's end
anoadragon453 e79b346
Mark `parsePublicRoomsResponse` as a test helper function
anoadragon453 c7ee1d8
Replace arbitrary timeout with `authedClient.SyncUntilTimeout`
anoadragon453 59f9f0e
hostname -> server_name
anoadragon453 a395212
Only log unexpected rooms if there are any
anoadragon453 d24405d
Remove duplicate `chunk` checks
anoadragon453 83723e7
Remove room at the end of "Can search public room list"
anoadragon453 9ab045c
unparallel public rooms tests
anoadragon453 ce9288f
`defer` right after creating the room
anoadragon453 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| package csapi_tests | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/tidwall/gjson" | ||
|
|
||
| "github.com/matrix-org/complement" | ||
| "github.com/matrix-org/complement/client" | ||
| "github.com/matrix-org/complement/helpers" | ||
| "github.com/matrix-org/complement/match" | ||
| "github.com/matrix-org/complement/must" | ||
| ) | ||
|
|
||
| func TestPublicRooms(t *testing.T) { | ||
| deployment := complement.Deploy(t, 1) | ||
| defer deployment.Destroy(t) | ||
|
|
||
| t.Run("parallel", func(t *testing.T) { | ||
| // sytest: Name/topic keys are correct | ||
| t.Run("Name/topic keys are correct", func(t *testing.T) { | ||
| t.Parallel() | ||
| authedClient := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) | ||
|
|
||
| // Define room configurations matching the Sytest | ||
| roomConfigs := []struct { | ||
| alias string | ||
| name string | ||
| topic string | ||
| }{ | ||
| {"publicroomalias_no_name", "", ""}, | ||
| {"publicroomalias_with_name", "name_1", ""}, | ||
| {"publicroomalias_with_topic", "", "topic_1"}, | ||
| {"publicroomalias_with_name_topic", "name_2", "topic_2"}, | ||
| {"publicroom_with_unicode_chars_name", "un nom français", ""}, | ||
| {"publicroom_with_unicode_chars_topic", "", "un topic à la française"}, | ||
| {"publicroom_with_unicode_chars_name_topic", "un nom français", "un topic à la française"}, | ||
| } | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Create all rooms with their configurations | ||
| createdRooms := make(map[string]struct { | ||
| roomID string | ||
| name string | ||
| topic string | ||
| }) | ||
|
|
||
| for _, config := range roomConfigs { | ||
| roomOptions := map[string]interface{}{ | ||
| "visibility": "public", | ||
| "room_alias_name": config.alias, | ||
| } | ||
|
|
||
| if config.name != "" { | ||
| roomOptions["name"] = config.name | ||
| } | ||
| if config.topic != "" { | ||
| roomOptions["topic"] = config.topic | ||
| } | ||
|
|
||
| roomID := authedClient.MustCreateRoom(t, roomOptions) | ||
| createdRooms[config.alias] = struct { | ||
| roomID string | ||
| name string | ||
| topic string | ||
| }{ | ||
| roomID: roomID, | ||
| name: config.name, | ||
| topic: config.topic, | ||
| } | ||
| t.Logf("Created room %s with alias %s", roomID, config.alias) | ||
| } | ||
|
|
||
| // Poll /publicRooms until all our rooms appear with correct data | ||
| authedClient.MustDo(t, "GET", []string{"_matrix", "client", "v3", "publicRooms"}, | ||
| client.WithRetryUntil(15*time.Second, func(res *http.Response) bool { | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| body := must.ParseJSON(t, res.Body) | ||
|
|
||
| must.MatchGJSON( | ||
| t, | ||
| body, | ||
| match.JSONKeyPresent("chunk"), | ||
| match.JSONKeyTypeEqual("chunk", gjson.JSON), | ||
| ) | ||
|
|
||
| chunk := body.Get("chunk") | ||
| if !chunk.IsArray() { | ||
| t.Logf("chunk is not an array") | ||
| return false | ||
| } | ||
|
|
||
| // Track which rooms we've correctly found | ||
| foundRooms := make(map[string]bool) | ||
|
|
||
| // Check each room in the public rooms list | ||
| for _, roomData := range chunk.Array() { | ||
| // Verify required keys are present | ||
| must.MatchGJSON( | ||
| t, | ||
| roomData, | ||
| match.JSONKeyPresent("world_readable"), | ||
| match.JSONKeyPresent("guest_can_join"), | ||
| match.JSONKeyPresent("num_joined_members"), | ||
| ) | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| canonicalAlias := roomData.Get("canonical_alias").Str | ||
| name := roomData.Get("name").Str | ||
| topic := roomData.Get("topic").Str | ||
| numMembers := roomData.Get("num_joined_members").Int() | ||
|
|
||
| // Skip rooms that aren't ours | ||
| if canonicalAlias == "" { | ||
| continue | ||
| } | ||
|
|
||
| // Find which of our rooms this matches | ||
| var matchedAlias string | ||
| for alias := range createdRooms { | ||
| expectedAlias := "#" + alias + ":hs1" | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if canonicalAlias == expectedAlias { | ||
| matchedAlias = alias | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if matchedAlias == "" { | ||
| continue // Not one of our rooms | ||
| } | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| roomConfig := createdRooms[matchedAlias] | ||
|
|
||
| // Verify member count | ||
| if numMembers != 1 { | ||
| t.Logf("Room %s has %d members, expected 1", matchedAlias, numMembers) | ||
| return false | ||
| } | ||
|
|
||
| // Verify name field | ||
| if roomConfig.name != "" { | ||
| if name != roomConfig.name { | ||
| t.Logf("Room %s has name '%s', expected '%s'", matchedAlias, name, roomConfig.name) | ||
| return false | ||
| } | ||
| } else { | ||
| if name != "" { | ||
| t.Logf("Room %s has unexpected name '%s', expected no name", matchedAlias, name) | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| // Verify topic field | ||
| if roomConfig.topic != "" { | ||
| if topic != roomConfig.topic { | ||
| t.Logf("Room %s has topic '%s', expected '%s'", matchedAlias, topic, roomConfig.topic) | ||
| return false | ||
| } | ||
| } else { | ||
| if topic != "" { | ||
| t.Logf("Room %s has unexpected topic '%s', expected no topic", matchedAlias, topic) | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| // Mark this room as correctly found | ||
| foundRooms[matchedAlias] = true | ||
| t.Logf("Successfully validated room %s", matchedAlias) | ||
| } | ||
|
|
||
| // Check if we found all our rooms | ||
| if len(foundRooms) != len(createdRooms) { | ||
| missing := []string{} | ||
| for alias := range createdRooms { | ||
| if !foundRooms[alias] { | ||
| missing = append(missing, alias) | ||
| } | ||
| } | ||
| t.Logf("Missing rooms in public list: %v (found %d/%d)", missing, len(foundRooms), len(createdRooms)) | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return false | ||
| } | ||
|
|
||
| t.Logf("All %d rooms found with correct name/topic data", len(foundRooms)) | ||
| return true | ||
| }), | ||
| ) | ||
| }) | ||
| }) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.