Skip to content

Commit

Permalink
Fix method 'event.Check'
Browse files Browse the repository at this point in the history
The text is no longer mandatory for event. While the rest of the code
already allowed for this the 'Check' method was returning an error.
  • Loading branch information
hush-hush committed Oct 27, 2021
1 parent 28e0fe0 commit bda5e85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ commands:
type: string
steps:
- checkout
# TODO: remove this once we have go.mod
- run: git config --global http.sslVerify false
- run: go get github.com/stretchr/testify
- run: go vet ./statsd/...
- run: go fmt ./statsd/...
Expand Down
3 changes: 0 additions & 3 deletions statsd/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ func (e Event) Check() error {
if len(e.Title) == 0 {
return fmt.Errorf("statsd.Event title is required")
}
if len(e.Text) == 0 {
return fmt.Errorf("statsd.Event text is required")
}
return nil
}

Expand Down
16 changes: 9 additions & 7 deletions statsd/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ func TestNewEventTitleMissing(t *testing.T) {
assert.Equal(t, "statsd.Event title is required", err.Error())
}

func TestNewEventTextMissing(t *testing.T) {
e := NewEvent("hi", "")
_, err := e.Encode()
require.Error(t, err)
assert.Equal(t, "statsd.Event text is required", err.Error())
}

func TestNewEvent(t *testing.T) {
e := NewEvent("hello", "world")
eventEncoded, err := e.Encode("tag1", "tag2")
Expand All @@ -70,3 +63,12 @@ func TestNewEventTags(t *testing.T) {
assert.Equal(t, "_e{5,5}:hello|world|#tag3,tag4,tag1,tag2", eventEncoded)
assert.Len(t, e.Tags, 2)
}

func TestNewEventEmptyText(t *testing.T) {
e := NewEvent("hello", "")
e.Tags = append(e.Tags, "tag1", "tag2")
eventEncoded, err := e.Encode()
require.NoError(t, err)
assert.Equal(t, "_e{5,0}:hello||#tag1,tag2", eventEncoded)
assert.Len(t, e.Tags, 2)
}

0 comments on commit bda5e85

Please sign in to comment.