Skip to content

Commit

Permalink
add live tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWinikates committed Oct 26, 2023
1 parent 4ed6c6d commit 9c66ac7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
18 changes: 2 additions & 16 deletions internal/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,14 @@ func (reporter reporter) reportEvent(event string) (*http.Response, error) {
}

apiURL := reporter.serverURL + eventEndpoint
var body io.Reader
if reporter.IsDirect() {
gzipBytes, err := linesToGzippedBytes(event)
if err != nil {
return nil, err
}
body = bytes.NewBuffer(gzipBytes)
} else {
body = strings.NewReader(event)
}

req, err := http.NewRequest("POST", apiURL, body)
req, err := http.NewRequest("POST", apiURL, strings.NewReader(event))
if err != nil {
return nil, err
}

req.Header.Set(contentType, applicationJSON)

if reporter.IsDirect() {
req.Header.Set(contentEncoding, gzipFormat)
req.Header.Set(contentType, applicationJSON)
}

err = reporter.tokenService.Authorize(req)
if err != nil {
return nil, err
Expand Down
28 changes: 28 additions & 0 deletions senders/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package senders
import (
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -57,3 +58,30 @@ func TestWF_API_TOKEN_LIVE(t *testing.T) {
assert.NoError(t, sender.Flush())
sender.Close()
}

func TestEventDirectSend_LIVE(t *testing.T) {
skipUnlessVarsAreSet(t)

sender, err := NewSender(
os.Getenv("LIVE_TEST_HOST"),
APIToken(os.Getenv("LIVE_TEST_WF_API_TOKEN")),
)
assert.NoError(t, err)
assert.NoError(t, sender.SendEvent("test.an-event", time.Now().Add(-30*time.Minute).UnixMilli(), time.Now().Add(5*time.Minute).UnixMilli(), "go test",
map[string]string{"scenario": "send-event-direct"}))
assert.NoError(t, sender.Flush())
sender.Close()
}

func TestEventProxySend_LIVE(t *testing.T) {
skipUnlessVarsAreSet(t)

sender, err := NewSender(
os.Getenv("LIVE_TEST_PROXY_HOST"),
)
assert.NoError(t, err)
assert.NoError(t, sender.SendEvent("test.an-event", time.Now().Add(-30*time.Minute).UnixMilli(), time.Now().Add(5*time.Minute).UnixMilli(), "go test",
map[string]string{"scenario": "send-event-proxy"}))
assert.NoError(t, sender.Flush())
sender.Close()
}

0 comments on commit 9c66ac7

Please sign in to comment.