mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-10-22 16:00:41 +00:00
5e9dce1c0c
* syncapi: Rename and split out tokens Previously we used the badly named `PaginationToken` which was used for both `/sync` and `/messages` requests. This quickly became confusing because named fields like `PDUPosition` meant different things depending on the token type. Instead, we now have two token types: `TopologyToken` and `StreamingToken`, both of which have fields which make more sense for their specific situations. Updated the codebase to use one or the other. `PaginationToken` still lives on as `syncToken`, an unexported type which both tokens rely on. This allows us to guarantee that the specific mappings of positions to a string remain solely under the control of the `types` package. This enables us to move high-level conceptual things like "decrement this topological token" to function calls e.g `TopologicalToken.Decrement()`. Currently broken because `/messages` seemingly used both stream and topological tokens, though I need to confirm this. * final tweaks/hacks * spurious logging * Review comments and linting
39 lines
769 B
Go
39 lines
769 B
Go
package types
|
|
|
|
import "testing"
|
|
|
|
func TestNewSyncTokenFromString(t *testing.T) {
|
|
shouldPass := map[string]syncToken{
|
|
"s4_0": NewStreamToken(4, 0).syncToken,
|
|
"s3_1": NewStreamToken(3, 1).syncToken,
|
|
"t3_1": NewTopologyToken(3, 1).syncToken,
|
|
}
|
|
|
|
shouldFail := []string{
|
|
"",
|
|
"s_1",
|
|
"s_",
|
|
"a3_4",
|
|
"b",
|
|
"b-1",
|
|
"-4",
|
|
"2",
|
|
}
|
|
|
|
for test, expected := range shouldPass {
|
|
result, err := newSyncTokenFromString(test)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if result.String() != expected.String() {
|
|
t.Errorf("%s expected %v but got %v", test, expected.String(), result.String())
|
|
}
|
|
}
|
|
|
|
for _, test := range shouldFail {
|
|
if _, err := newSyncTokenFromString(test); err == nil {
|
|
t.Errorf("input '%v' should have errored but didn't", test)
|
|
}
|
|
}
|
|
}
|