-
Notifications
You must be signed in to change notification settings - Fork 9
/
get_all_events_test.go
91 lines (80 loc) · 2.58 KB
/
get_all_events_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package rangedbapi_test
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"time"
"github.com/inklabs/rangedb"
"github.com/inklabs/rangedb/pkg/clock/provider/sequentialclock"
"github.com/inklabs/rangedb/pkg/jsontools"
"github.com/inklabs/rangedb/pkg/rangedbapi"
"github.com/inklabs/rangedb/provider/inmemorystore"
"github.com/inklabs/rangedb/rangedbtest"
)
func Example_getAllEvents() {
// Given
rangedbtest.SetRand(100)
inMemoryStore := inmemorystore.New(
inmemorystore.WithClock(sequentialclock.New()),
inmemorystore.WithUUIDGenerator(rangedbtest.NewSeededUUIDGenerator()),
)
api, err := rangedbapi.New(rangedbapi.WithStore(inMemoryStore))
PrintError(err)
server := httptest.NewServer(api)
defer server.Close()
serverURL, err := url.Parse(server.URL)
PrintError(err)
serverURL.Path = "/all-events.json"
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
streamNameA := "thing-605f20348fb940e386c171d51c877bf1"
streamNameB := "another-a095086e52bc4617a1763a62398cd645"
PrintError(IgnoreFirstNumber(inMemoryStore.Save(ctx, streamNameA,
&rangedb.EventRecord{Event: rangedbtest.ThingWasDone{ID: "605f20348fb940e386c171d51c877bf1", Number: 100}},
)))
PrintError(IgnoreFirstNumber(inMemoryStore.Save(ctx, streamNameB,
&rangedb.EventRecord{Event: rangedbtest.AnotherWasComplete{ID: "a095086e52bc4617a1763a62398cd645"}},
)))
// When
response, err := http.Get(serverURL.String())
PrintError(err)
defer Close(response.Body)
body, err := ioutil.ReadAll(response.Body)
PrintError(err)
fmt.Println(jsontools.PrettyJSON(body))
// Output:
// [
// {
// "streamName": "thing-605f20348fb940e386c171d51c877bf1",
// "aggregateType": "thing",
// "aggregateID": "605f20348fb940e386c171d51c877bf1",
// "globalSequenceNumber": 1,
// "streamSequenceNumber": 1,
// "insertTimestamp": 0,
// "eventID": "d2ba8e70072943388203c438d4e94bf3",
// "eventType": "ThingWasDone",
// "data": {
// "id": "605f20348fb940e386c171d51c877bf1",
// "number": 100
// },
// "metadata": null
// },
// {
// "streamName": "another-a095086e52bc4617a1763a62398cd645",
// "aggregateType": "another",
// "aggregateID": "a095086e52bc4617a1763a62398cd645",
// "globalSequenceNumber": 2,
// "streamSequenceNumber": 1,
// "insertTimestamp": 1,
// "eventID": "99cbd88bbcaf482ba1cc96ed12541707",
// "eventType": "AnotherWasComplete",
// "data": {
// "id": "a095086e52bc4617a1763a62398cd645"
// },
// "metadata": null
// }
// ]
}