From 9c66ac7fce27e471892be65b6ab688eb6fe5cdaf Mon Sep 17 00:00:00 2001 From: Luke Winikates Date: Thu, 26 Oct 2023 13:58:10 -0700 Subject: [PATCH] add live tests --- internal/reporter.go | 18 ++---------------- senders/live_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/internal/reporter.go b/internal/reporter.go index 5f06ce0..a939cb5 100644 --- a/internal/reporter.go +++ b/internal/reporter.go @@ -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 diff --git a/senders/live_test.go b/senders/live_test.go index f911549..5294566 100644 --- a/senders/live_test.go +++ b/senders/live_test.go @@ -3,6 +3,7 @@ package senders import ( "os" "testing" + "time" "github.com/stretchr/testify/assert" ) @@ -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() +}