Skip to content

Commit

Permalink
Change key representation (#738)
Browse files Browse the repository at this point in the history
Also:
* Fix flanky test
* Add a fast json parser for int and []int
  • Loading branch information
ostcar authored Aug 8, 2023
1 parent 9aceb63 commit 4025018
Show file tree
Hide file tree
Showing 57 changed files with 7,974 additions and 1,712 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ A request can have a body and the `k`-query parameter.
After the request is send, the values to the keys are returned as a json-object
without a newline:
```
{"user/1/name":"value","user/2/name":"value"}
{"user/1/username":"value","user/2/username":"value"}
```

With the query parameter `single` the server writes the first response and
Expand Down
20 changes: 10 additions & 10 deletions internal/autoupdate/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/OpenSlides/openslides-autoupdate-service/pkg/environment"
)

var userNameKey = dskey.MustKey("user/1/name")
var userNameKey = dskey.MustKey("user/1/username")

func TestConnect(t *testing.T) {
next, _, _ := getConnection()
Expand All @@ -25,7 +25,7 @@ func TestConnect(t *testing.T) {
}

if value, ok := data[userNameKey]; !ok || string(value) != `"Hello World"` {
t.Errorf("next() returned %v, expected map[user/1/name:\"Hello World\"", data)
t.Errorf("next() returned %v, expected map[user/1/username:\"Hello World\"", data)
}
}

Expand Down Expand Up @@ -75,15 +75,15 @@ func TestConnectionReadNewData(t *testing.T) {

func TestConnectionEmptyData(t *testing.T) {
var (
doesNotExistKey = dskey.MustKey("doesnot/1/exist")
doesExistKey = userNameKey
doesNotExistKey = dskey.MustKey("user/2/username")
doesExistKey = dskey.MustKey("user/1/username")
)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

ds := dsmock.NewFlow(dsmock.YAMLData(`---
user/1/name: Hello World
user/1/username: Hello World
`))

s, bg, _ := autoupdate.New(environment.ForTests{}, ds, RestrictAllowed)
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestConntectionFilterOnlyOneKey(t *testing.T) {
defer cancel()

ds := dsmock.NewFlow(dsmock.YAMLData(`---
user/1/name: Hello World
user/1/username: Hello World
`))

s, bg, _ := autoupdate.New(environment.ForTests{}, ds, RestrictAllowed)
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestConntectionFilterOnlyOneKey(t *testing.T) {
}

if _, ok := data[userNameKey]; !ok {
t.Errorf("Returned value does not have key `user/1/name`")
t.Errorf("Returned value does not have key `user/1/username`")
}

if got := string(data[userNameKey]); got != `"newname"` {
Expand All @@ -275,7 +275,7 @@ func TestConntectionFilterOnlyOneKey(t *testing.T) {

func TestNextNoReturnWhenDataIsRestricted(t *testing.T) {
ds := dsmock.NewFlow(dsmock.YAMLData(`---
user/1/name: Hello World
user/1/username: Hello World
`))

s, _, _ := autoupdate.New(environment.ForTests{}, ds, RestrictNotAllowed)
Expand Down Expand Up @@ -349,7 +349,7 @@ func TestKeyNotRequestedAnymore(t *testing.T) {
organization/1/organization_tag_ids: [1,2]
organization_tag/1/id: 1
organization_tag/2/id: 2
user/1/name: Hello World
user/1/username: Hello World
`))

s, bg, _ := autoupdate.New(environment.ForTests{}, datastore, RestrictAllowed)
Expand Down Expand Up @@ -420,7 +420,7 @@ func TestKeyRequestedAgain(t *testing.T) {
organization/1/organization_tag_ids: [1,2]
organization_tag/1/id: 1
organization_tag/2/id: 2
user/1/name: Hello World
user/1/username: Hello World
`))

s, bg, _ := autoupdate.New(environment.ForTests{}, datastore, RestrictAllowed)
Expand Down
268 changes: 0 additions & 268 deletions internal/autoupdate/feature_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions internal/autoupdate/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

var (
myKey1 = dskey.MustKey("collection/1/field")
myKey2 = dskey.MustKey("collection/2/field")
myKey1 = dskey.MustKey("user/1/username")
myKey2 = dskey.MustKey("user/2/username")
)

func TestFilterFirstCall(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/autoupdate/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func getConnection() (func(context.Context) (map[dskey.Key][]byte, error), *dsmock.Flow, func(context.Context, func(error))) {
datastore := dsmock.NewFlow(dsmock.YAMLData(`---
user/1/name: Hello World
user/1/username: Hello World
`))

lookup := environment.ForTests{}
Expand Down
Loading

0 comments on commit 4025018

Please sign in to comment.