Skip to content

Commit

Permalink
add test for schema and builder
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Feb 23, 2024
1 parent 803af12 commit a62a727
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/closter/events/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (b *Builder) Release() {

func (b *Builder) Write(list *v1.List) arrow.Record {
ls := list.GetItems()
sort.Slice(ls, func(i, j int) bool {
sort.SliceStable(ls, func(i, j int) bool {
return ls[i].Timestamp < ls[j].Timestamp
})
b.r.Reserve(len(ls))
Expand Down
9 changes: 6 additions & 3 deletions internal/closter/events/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ func TestBuild(t *testing.T) {
b := New(memory.NewGoAllocator())
defer b.Release()

b.Write(&v1.List{
r := b.Write(&v1.List{
Items: []*v1.Data{
{Bounce: nil},
{Bounce: True},
{Bounce: False},
{Page: "/"},
},
})
r := b.NewRecord()
got, _ := r.MarshalJSON()
// os.WriteFile("testdata/record.json", got, 0600)
want, _ := os.ReadFile("testdata/record.json")
require.Equal(t, string(want), string(got))
require.JSONEq(t, string(want), string(got))
gotSchema := r.Schema().String()
// os.WriteFile("testdata/schema.txt", []byte(gotSchema), 0600)
wantSchema, _ := os.ReadFile("testdata/schema.txt")
require.Equal(t, string(wantSchema), gotSchema)
}
8 changes: 4 additions & 4 deletions internal/closter/events/testdata/record.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[{"bounce":null,"browser":null,"browser_version":null,"city":null,"country":null,"device":null,"domain":null,"duration":0,"entry_page":null,"event":null,"exit_page":null,"id":0,"os":null,"os_version":null,"page":null,"referrer":null,"region":null,"session":false,"source":null,"timestamp":0,"utm_campaign":null,"utm_content":null,"utm_medium":null,"utm_source":null,"utm_term":null,"view":false}
,{"bounce":true,"browser":null,"browser_version":null,"city":null,"country":null,"device":null,"domain":null,"duration":0,"entry_page":null,"event":null,"exit_page":null,"id":0,"os":null,"os_version":null,"page":null,"referrer":null,"region":null,"session":false,"source":null,"timestamp":0,"utm_campaign":null,"utm_content":null,"utm_medium":null,"utm_source":null,"utm_term":null,"view":false}
,{"bounce":false,"browser":null,"browser_version":null,"city":null,"country":null,"device":null,"domain":null,"duration":0,"entry_page":null,"event":null,"exit_page":null,"id":0,"os":null,"os_version":null,"page":null,"referrer":null,"region":null,"session":false,"source":null,"timestamp":0,"utm_campaign":null,"utm_content":null,"utm_medium":null,"utm_source":null,"utm_term":null,"view":false}
,{"bounce":null,"browser":null,"browser_version":null,"city":null,"country":null,"device":null,"domain":null,"duration":0,"entry_page":null,"event":null,"exit_page":null,"id":0,"os":null,"os_version":null,"page":"/","referrer":null,"region":null,"session":false,"source":null,"timestamp":0,"utm_campaign":null,"utm_content":null,"utm_medium":null,"utm_source":null,"utm_term":null,"view":false}
[{"bounce":null,"browser":null,"browser_version":null,"city":null,"country":null,"device":null,"domain":null,"duration":0,"entry_page":null,"event":null,"exit_page":null,"host":null,"id":0,"os":null,"os_version":null,"page":null,"referrer":null,"region":null,"session":false,"source":null,"timestamp":0,"utm_campaign":null,"utm_content":null,"utm_medium":null,"utm_source":null,"utm_term":null,"view":false}
,{"bounce":true,"browser":null,"browser_version":null,"city":null,"country":null,"device":null,"domain":null,"duration":0,"entry_page":null,"event":null,"exit_page":null,"host":null,"id":0,"os":null,"os_version":null,"page":null,"referrer":null,"region":null,"session":false,"source":null,"timestamp":0,"utm_campaign":null,"utm_content":null,"utm_medium":null,"utm_source":null,"utm_term":null,"view":false}
,{"bounce":false,"browser":null,"browser_version":null,"city":null,"country":null,"device":null,"domain":null,"duration":0,"entry_page":null,"event":null,"exit_page":null,"host":null,"id":0,"os":null,"os_version":null,"page":null,"referrer":null,"region":null,"session":false,"source":null,"timestamp":0,"utm_campaign":null,"utm_content":null,"utm_medium":null,"utm_source":null,"utm_term":null,"view":false}
,{"bounce":null,"browser":null,"browser_version":null,"city":null,"country":null,"device":null,"domain":null,"duration":0,"entry_page":null,"event":null,"exit_page":null,"host":null,"id":0,"os":null,"os_version":null,"page":"/","referrer":null,"region":null,"session":false,"source":null,"timestamp":0,"utm_campaign":null,"utm_content":null,"utm_medium":null,"utm_source":null,"utm_term":null,"view":false}
]
29 changes: 29 additions & 0 deletions internal/closter/events/testdata/schema.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
schema:
fields: 27
- timestamp: type=int64
- id: type=int64
- bounce: type=bool, nullable
- session: type=bool
- view: type=bool
- duration: type=float64
- event: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- page: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- entry_page: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- exit_page: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- source: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- referrer: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- utm_source: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- utm_medium: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- utm_campaign: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- utm_content: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- utm_term: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- device: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- browser: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- browser_version: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- os: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- os_version: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- country: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- region: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- domain: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- city: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable
- host: type=dictionary<values=utf8, indices=uint32, ordered=false>, nullable

0 comments on commit a62a727

Please sign in to comment.