-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove errHandler in faver of http.Handler * See: https://www.maragu.dk/blog/structuring-and-testing-http-handlers-in-go/ * Use the json lib for decoding * Keysbuilder: No key generation on init
- Loading branch information
Showing
19 changed files
with
449 additions
and
474 deletions.
There are no files selected for viewing
This file contains 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 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 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,47 @@ | ||
package autoupdate_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/openslides/openslides-autoupdate-service/internal/autoupdate" | ||
"github.com/openslides/openslides-autoupdate-service/internal/test" | ||
) | ||
|
||
func TestLive(t *testing.T) { | ||
datastore := new(test.MockDatastore) | ||
closed := make(chan struct{}) | ||
defer close(closed) | ||
s := autoupdate.New(datastore, new(test.MockRestricter), closed) | ||
kb := test.KeysBuilder{K: []string{"foo", "bar"}} | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
cancel() | ||
|
||
w := new(mockWriter) | ||
s.Live(ctx, 1, w, kb) | ||
|
||
if len(w.lines) != 1 { | ||
t.Fatalf("Got %d lines, expected 1", len(w.lines)) | ||
} | ||
|
||
expect := `{"bar":"Hello World","foo":"Hello World"}` + "\n" | ||
if got := w.lines[0]; got != expect { | ||
t.Errorf("Got %s, expected %s", got, expect) | ||
} | ||
} | ||
|
||
type mockWriter struct { | ||
lines []string | ||
buf []byte | ||
} | ||
|
||
func (w *mockWriter) Write(p []byte) (int, error) { | ||
w.buf = append(w.buf, p...) | ||
return len(p), nil | ||
} | ||
|
||
func (w *mockWriter) Flush() { | ||
w.lines = append(w.lines, string(w.buf)) | ||
w.buf = nil | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,29 +1,15 @@ | ||
package autoupdate_test | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/openslides/openslides-autoupdate-service/internal/autoupdate" | ||
"github.com/openslides/openslides-autoupdate-service/internal/test" | ||
) | ||
|
||
type mockKeysBuilder struct { | ||
keys []string | ||
} | ||
|
||
func (m mockKeysBuilder) Update(context.Context) error { | ||
return nil | ||
} | ||
|
||
func (m mockKeysBuilder) Keys() []string { | ||
return m.keys | ||
} | ||
|
||
func getConnection(closed <-chan struct{}) (*autoupdate.Connection, *test.MockDatastore) { | ||
datastore := new(test.MockDatastore) | ||
s := autoupdate.New(datastore, new(test.MockRestricter), closed) | ||
kb := mockKeysBuilder{keys: test.Str("user/1/name")} | ||
c := s.Connect(1, kb, 0) | ||
kb := test.KeysBuilder{K: test.Str("user/1/name")} | ||
c := s.Connect(1, kb) | ||
|
||
return c, datastore | ||
} |
This file contains 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
Oops, something went wrong.