mirror of
https://github.com/matrix-org/dendrite
synced 2024-07-01 02:38:24 +02:00
49f760a30b
* Merge forward * Tidy up a bit * TODO: What to do with NextBatch here? * Replace SyncPosition with PaginationToken throughout syncapi * Fix PaginationTokens * Fix lint errors * Add a couple of missing functions into the syncapi external storage interface * Some updates based on review comments from @babolivier * Some updates based on review comments from @babolivier * argh whitespacing * Fix opentracing span * Remove dead code * Don't overshadow err (fix lint issue) * Handle extremities after inserting event into topology * Try insert event topology as ON CONFLICT DO NOTHING * Prevent OOB error in addRoomDeltaToResponse * Thwarted by gocyclo again * Fix NewPaginationTokenFromString, define unit test for it * Update pagination token test * Update sytest-whitelist * Hopefully fix some of the sync batch tokens * Remove extraneous sync position func * Revert to topology tokens in addRoomDeltaToResponse etc * Fix typo * Remove prevPDUPos as dead now that backwardTopologyPos is used instead * Fix selectEventsWithEventIDsSQL * Update sytest-blacklist * Update sytest-whitelist
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package types
|
|
|
|
import "testing"
|
|
|
|
func TestNewPaginationTokenFromString(t *testing.T) {
|
|
shouldPass := map[string]PaginationToken{
|
|
"2": PaginationToken{
|
|
Type: PaginationTokenTypeStream,
|
|
PDUPosition: 2,
|
|
},
|
|
"s4": PaginationToken{
|
|
Type: PaginationTokenTypeStream,
|
|
PDUPosition: 4,
|
|
},
|
|
"s3_1": PaginationToken{
|
|
Type: PaginationTokenTypeStream,
|
|
PDUPosition: 3,
|
|
EDUTypingPosition: 1,
|
|
},
|
|
"t3_1_4": PaginationToken{
|
|
Type: PaginationTokenTypeTopology,
|
|
PDUPosition: 3,
|
|
EDUTypingPosition: 1,
|
|
},
|
|
}
|
|
|
|
shouldFail := []string{
|
|
"",
|
|
"s_1",
|
|
"s_",
|
|
"a3_4",
|
|
"b",
|
|
"b-1",
|
|
"-4",
|
|
}
|
|
|
|
for test, expected := range shouldPass {
|
|
result, err := NewPaginationTokenFromString(test)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if *result != expected {
|
|
t.Errorf("expected %v but got %v", expected.String(), result.String())
|
|
}
|
|
}
|
|
|
|
for _, test := range shouldFail {
|
|
if _, err := NewPaginationTokenFromString(test); err == nil {
|
|
t.Errorf("input '%v' should have errored but didn't", test)
|
|
}
|
|
}
|
|
}
|