Skip to content

Commit

Permalink
added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mihir20 committed Jan 12, 2024
1 parent bf5f703 commit d5145af
Showing 1 changed file with 138 additions and 3 deletions.
141 changes: 138 additions & 3 deletions integration_test/docker_test/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestMainFlow(t *testing.T) {
sendEventsToGateway(t)
t.Run("webhook", func(t *testing.T) {
require.Eventually(t, func() bool {
return webhook.RequestsCount() == 10
return webhook.RequestsCount() == 11
}, time.Minute, 300*time.Millisecond)

i := -1
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestMainFlow(t *testing.T) {

var (
msgCount = 0 // Count how many message processed
expectedCount = 10
expectedCount = 15
timeout = time.After(2 * time.Minute)
)

Expand Down Expand Up @@ -532,6 +532,125 @@ func sendEventsToGateway(t *testing.T) {
}`)
sendEvent(t, payloadGroup, "group", writeKey)
sendPixelEvents(t, writeKey)

payloadRetlWebhook := strings.NewReader(`{
"batch":
[
{
"userId": "identified_user_id",
"anonymousId": "anonymousId_1",
"type": "identify",
"context":
{
"traits":
{
"trait1": "new-val"
},
"ip": "14.5.67.21",
"library":
{
"name": "http"
}
},
"timestamp": "2020-02-02T00:23:09.544Z"
}
]
}`)
sendEvent(t, payloadRetlWebhook, "retl", writeKey, withHeader("X-Rudder-Source-Id", "xxxyyyzzEaEurW247ad9WYZLUyk"), withHeader("X-Rudder-Destination-Id", "xxxyyyzzP9kQfzOoKd1tuxchYAG"), withInternalEndpoint())

payloadRetlKafka := strings.NewReader(`{
"batch":
[
{
"userId": "identified_user_id",
"anonymousId": "anonymousId_1",
"messageId":"messageId_11",
"type": "identify",
"context":
{
"traits":
{
"trait1": "new-val"
},
"ip": "14.5.67.21",
"library":
{
"name": "http"
}
},
"timestamp": "2020-02-02T00:23:09.544Z"
},{
"userId": "identified_user_id",
"anonymousId": "anonymousId_1",
"type": "identify",
"context":
{
"traits":
{
"trait1": "new-val"
},
"ip": "14.5.67.21",
"library":
{
"name": "http"
}
},
"timestamp": "2020-02-02T00:23:09.544Z"
},{
"userId": "identified_user_id",
"anonymousId": "anonymousId_1",
"type": "identify",
"context":
{
"traits":
{
"trait1": "new-val"
},
"ip": "14.5.67.21",
"library":
{
"name": "http"
}
},
"timestamp": "2020-02-02T00:23:09.544Z"
},{
"userId": "identified_user_id",
"anonymousId": "anonymousId_1",
"type": "identify",
"context":
{
"traits":
{
"trait1": "new-val"
},
"ip": "14.5.67.21",
"library":
{
"name": "http"
}
},
"timestamp": "2020-02-02T00:23:09.544Z"
},{
"userId": "identified_user_id",
"anonymousId": "anonymousId_1",
"type": "identify",
"context":
{
"traits":
{
"trait1": "new-val"
},
"ip": "14.5.67.21",
"library":
{
"name": "http"
}
},
"timestamp": "2020-02-02T00:23:09.544Z"
}
]
}`)
sendEvent(t, payloadRetlKafka, "retl", writeKey, withHeader("X-Rudder-Source-Id", "xxxyyyzzEaEurW247ad9WYZLUyk"), withHeader("X-Rudder-Destination-Id", "xxxyyyzzhyrw8v0CrTMrDZ4ovej"), withInternalEndpoint())
}

func blockOnHold(t *testing.T) {
Expand Down Expand Up @@ -597,7 +716,19 @@ func sendPixelEvents(t *testing.T, writeKey string) {
}
}

func sendEvent(t *testing.T, payload *strings.Reader, callType, writeKey string) {
func withHeader(key, value string) func(r *http.Request) {
return func(req *http.Request) {
req.Header.Add(key, value)
}
}

func withInternalEndpoint() func(r *http.Request) {
return func(req *http.Request) {
req.URL.Path = fmt.Sprintf("/internal%s", req.URL.Path)
}
}

func sendEvent(t *testing.T, payload *strings.Reader, callType, writeKey string, reqOptions ...func(r *http.Request)) {
t.Helper()
t.Logf("Sending %s Event", callType)

Expand All @@ -618,6 +749,10 @@ func sendEvent(t *testing.T, payload *strings.Reader, callType, writeKey string)
[]byte(fmt.Sprintf("%s:", writeKey)),
)))

for _, reqOption := range reqOptions {
reqOption(req)
}

res, err := httpClient.Do(req)
if err != nil {
t.Logf("sendEvent error: %v", err)
Expand Down

0 comments on commit d5145af

Please sign in to comment.