Skip to content
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

Fix tests to not depend on unspecced room_id parameter for each child room. #422

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 38 additions & 36 deletions tests/room_hierarchy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ func eventKey(srcRoomID, dstRoomID, evType string) string {
return srcRoomID + "|" + dstRoomID + "|" + evType
}

// Shared mapper function to return a structure comparison string for JSONCheckOff.
func roomToChildrenMapper(r gjson.Result) interface{} {
roomId := r.Get("room_id").Str

result := ""
for i, res := range r.Get("children_state").Array() {
if i != 0 {
result += ";"
}
result += eventKey(roomId, res.Get("state_key").Str, res.Get("type").Str)
}

return result
}

// Tests that the CS API for MSC2946 works correctly. Creates a space directory like:
// Root
// |
Expand Down Expand Up @@ -228,12 +243,11 @@ func TestClientSpacesSummary(t *testing.T) {
return nil
}),
// Check that the links from Root down to other rooms and spaces exist.
match.JSONCheckOff("rooms.#.children_state|@flatten", []interface{}{
rootToR1, rootToR2, rootToSS1,
ss1ToSS2, ss2ToR3, ss2ToR4,
}, func(r gjson.Result) interface{} {
return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str)
}, nil),
match.JSONCheckOff(`rooms.#(room_type=="m.space")#")`, []interface{}{
rootToR1 + ";" + rootToSS1 + ";" + rootToR2,
ss1ToSS2,
ss2ToR3 + ";" + ss2ToR4,
}, roomToChildrenMapper, nil),
},
})
})
Expand All @@ -257,11 +271,9 @@ func TestClientSpacesSummary(t *testing.T) {
return r.Get("room_id").Str
}, nil),
// All of the links are still there.
match.JSONCheckOff("rooms.#.children_state|@flatten", []interface{}{
rootToR1, rootToR2, rootToSS1, ss1ToSS2,
}, func(r gjson.Result) interface{} {
return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str)
}, nil),
match.JSONCheckOff(`rooms.#(room_type=="m.space")#`, []interface{}{
rootToR1 + ";" + rootToSS1 + ";" + rootToR2, ss1ToSS2,
}, roomToChildrenMapper, nil),
},
})
})
Expand All @@ -285,11 +297,9 @@ func TestClientSpacesSummary(t *testing.T) {
return r.Get("room_id").Str
}, nil),
// All of the links are still there.
match.JSONCheckOff("rooms.#.children_state|@flatten", []interface{}{
rootToR1, rootToR2,
}, func(r gjson.Result) interface{} {
return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str)
}, nil),
match.JSONCheckOff(`rooms.#(room_type=="m.space")#`, []interface{}{
rootToR1 + ";" + rootToR2,
}, roomToChildrenMapper, nil),
},
})
})
Expand Down Expand Up @@ -350,11 +360,9 @@ func TestClientSpacesSummary(t *testing.T) {
}, func(r gjson.Result) interface{} {
return r.Get("room_id").Str
}, nil),
match.JSONCheckOff("rooms.#.children_state|@flatten", []interface{}{
rootToR1, rootToR2,
}, func(r gjson.Result) interface{} {
return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str)
}, nil),
match.JSONCheckOff(`rooms.#(room_type=="m.space")#`, []interface{}{
rootToR1 + ";" + rootToR2,
}, roomToChildrenMapper, nil),
},
})
})
Expand Down Expand Up @@ -464,11 +472,9 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) {
}, func(r gjson.Result) interface{} {
return r.Get("room_id").Str
}, nil),
match.JSONCheckOff("rooms.#.children_state|@flatten", []interface{}{
rootToR1, rootToSS1,
}, func(r gjson.Result) interface{} {
return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str)
}, nil),
match.JSONCheckOff(`rooms.#(room_type=="m.space")#`, []interface{}{
rootToR1 + ";" + rootToSS1,
}, roomToChildrenMapper, nil),
},
})

Expand All @@ -484,11 +490,9 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) {
}, func(r gjson.Result) interface{} {
return r.Get("room_id").Str
}, nil),
match.JSONCheckOff("rooms.#.children_state|@flatten", []interface{}{
rootToR1, rootToSS1,
}, func(r gjson.Result) interface{} {
return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str)
}, nil),
match.JSONCheckOff(`rooms.#(room_type=="m.space")#`, []interface{}{
rootToR1 + ";" + rootToSS1,
}, roomToChildrenMapper, nil),
},
})

Expand All @@ -503,11 +507,9 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) {
}, func(r gjson.Result) interface{} {
return r.Get("room_id").Str
}, nil),
match.JSONCheckOff("rooms.#.children_state|@flatten", []interface{}{
rootToR1, rootToSS1, ss1ToR2, ss1ToR3,
}, func(r gjson.Result) interface{} {
return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str)
}, nil),
match.JSONCheckOff(`rooms.#(room_type=="m.space")#`, []interface{}{
rootToR1 + ";" + rootToSS1, ss1ToR2 + ";" + ss1ToR3,
}, roomToChildrenMapper, nil),
},
})
}
Expand Down