Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #64 from rob-sch1/events_group
Browse files Browse the repository at this point in the history
Add public NewEventsGroup function.
  • Loading branch information
a-feld authored Apr 22, 2021
2 parents 6b4cc11 + 61faae1 commit 2a3ac64
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

* Adds support for creating event groups for the request factory

## [0.7.0] - 2021-04-02

### Breaking Changes ⚠️
Expand Down
5 changes: 5 additions & 0 deletions telemetry/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ func (group *eventGroup) WriteDataEntry(buf *bytes.Buffer) *bytes.Buffer {
group.writeJSON(buf)
return buf
}

// NewEventGroup creates a new MapEntry representing a group of events in a batch.
func NewEventGroup(events []Event) MapEntry {
return &eventGroup{Events: events}
}
29 changes: 12 additions & 17 deletions telemetry/events_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ func TestEventsPayloadSplit(t *testing.T) {
t.Parallel()

// test len 0
ev := &eventGroup{}
split := ev.split()
ev := NewEventGroup([]Event{})
split := ev.(splittablePayloadEntry).split()
if split != nil {
t.Error(split)
}

// test len 1
ev = &eventGroup{Events: []Event{{EventType: "a"}}}
split = ev.split()
ev = NewEventGroup([]Event{{EventType: "a"}})
split = ev.(splittablePayloadEntry).split()
if split != nil {
t.Error(split)
}

// test len 2
ev = &eventGroup{Events: []Event{{EventType: "a"}, {EventType: "b"}}}
split = ev.split()
ev = NewEventGroup([]Event{{EventType: "a"}, {EventType: "b"}})
split = ev.(splittablePayloadEntry).split()
if len(split) != 2 {
t.Error("split into incorrect number of slices", len(split))
}
Expand All @@ -72,8 +72,8 @@ func TestEventsPayloadSplit(t *testing.T) {
testEventGroupJSON(t, []Batch{{split[1]}}, `[{"eventType":"b","timestamp":-6795364578871}]`)

// test len 3
ev = &eventGroup{Events: []Event{{EventType: "a"}, {EventType: "b"}, {EventType: "c"}}}
split = ev.split()
ev = NewEventGroup([]Event{{EventType: "a"}, {EventType: "b"}, {EventType: "c"}})
split = ev.(splittablePayloadEntry).split()
if len(split) != 2 {
t.Error("split into incorrect number of slices", len(split))
}
Expand All @@ -84,16 +84,16 @@ func TestEventsPayloadSplit(t *testing.T) {
func TestEventsJSON(t *testing.T) {
t.Parallel()

group1 := &eventGroup{Events: []Event{
group1 := NewEventGroup([]Event{
{}, // Empty
{ // with everything
EventType: "testEvent",
Timestamp: time.Date(2014, time.November, 28, 1, 1, 0, 0, time.UTC),
Attributes: map[string]interface{}{"zip": "zap"},
},
}}
group2 := &eventGroup{Events: []Event{{EventType: "a"}}}
group3 := &eventGroup{Events: []Event{{EventType: "b"}}}
})
group2 := NewEventGroup([]Event{{EventType: "a"}})
group3 := NewEventGroup([]Event{{EventType: "b"}})

testEventGroupJSON(t, []Batch{{group1, group2}, {group3}}, `[
{
Expand All @@ -115,8 +115,3 @@ func TestEventsJSON(t *testing.T) {
}
]`)
}

func TestEventGroupSplittable(t *testing.T) {
group := &eventGroup{Events: []Event{{EventType: "a"}}}
_ = splittablePayloadEntry(group)
}

0 comments on commit 2a3ac64

Please sign in to comment.