Skip to content

Commit 49550b3

Browse files
committed
added integration tests
1 parent bf5f703 commit 49550b3

File tree

1 file changed

+145
-3
lines changed

1 file changed

+145
-3
lines changed

integration_test/docker_test/docker_test.go

+145-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestMainFlow(t *testing.T) {
9898
sendEventsToGateway(t)
9999
t.Run("webhook", func(t *testing.T) {
100100
require.Eventually(t, func() bool {
101-
return webhook.RequestsCount() == 10
101+
return webhook.RequestsCount() == 11
102102
}, time.Minute, 300*time.Millisecond)
103103

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

225225
var (
226226
msgCount = 0 // Count how many message processed
227-
expectedCount = 10
227+
expectedCount = 15
228228
timeout = time.After(2 * time.Minute)
229229
)
230230

@@ -532,6 +532,131 @@ func sendEventsToGateway(t *testing.T) {
532532
}`)
533533
sendEvent(t, payloadGroup, "group", writeKey)
534534
sendPixelEvents(t, writeKey)
535+
536+
payloadRetlWebhook := strings.NewReader(`{
537+
"batch":
538+
[
539+
{
540+
"userId": "identified_user_id",
541+
"anonymousId": "anonymousId_1",
542+
"type": "identify",
543+
"context":
544+
{
545+
"traits":
546+
{
547+
"trait1": "new-val"
548+
},
549+
"ip": "14.5.67.21",
550+
"library":
551+
{
552+
"name": "http"
553+
}
554+
},
555+
"timestamp": "2020-02-02T00:23:09.544Z"
556+
}
557+
]
558+
}`)
559+
sendEvent(t, payloadRetlWebhook, "retl", writeKey,
560+
withHeader("X-Rudder-Source-Id", "xxxyyyzzEaEurW247ad9WYZLUyk"),
561+
withHeader("X-Rudder-Destination-Id", "xxxyyyzzP9kQfzOoKd1tuxchYAG"),
562+
withUrlPath("/internal/v1/retl"))
563+
564+
payloadRetlKafka := strings.NewReader(`{
565+
"batch":
566+
[
567+
{
568+
"userId": "identified_user_id",
569+
"anonymousId": "anonymousId_1",
570+
"messageId":"messageId_11",
571+
"type": "identify",
572+
"context":
573+
{
574+
"traits":
575+
{
576+
"trait1": "new-val"
577+
},
578+
"ip": "14.5.67.21",
579+
"library":
580+
{
581+
"name": "http"
582+
}
583+
},
584+
"timestamp": "2020-02-02T00:23:09.544Z"
585+
},{
586+
"userId": "identified_user_id",
587+
"anonymousId": "anonymousId_1",
588+
"type": "identify",
589+
"context":
590+
{
591+
"traits":
592+
{
593+
"trait1": "new-val"
594+
},
595+
"ip": "14.5.67.21",
596+
"library":
597+
{
598+
"name": "http"
599+
}
600+
},
601+
"timestamp": "2020-02-02T00:23:09.544Z"
602+
},{
603+
"userId": "identified_user_id",
604+
"anonymousId": "anonymousId_1",
605+
"type": "identify",
606+
"context":
607+
{
608+
"traits":
609+
{
610+
"trait1": "new-val"
611+
},
612+
"ip": "14.5.67.21",
613+
"library":
614+
{
615+
"name": "http"
616+
}
617+
},
618+
"timestamp": "2020-02-02T00:23:09.544Z"
619+
},{
620+
"userId": "identified_user_id",
621+
"anonymousId": "anonymousId_1",
622+
"type": "identify",
623+
"context":
624+
{
625+
"traits":
626+
{
627+
"trait1": "new-val"
628+
},
629+
"ip": "14.5.67.21",
630+
"library":
631+
{
632+
"name": "http"
633+
}
634+
},
635+
"timestamp": "2020-02-02T00:23:09.544Z"
636+
},{
637+
"userId": "identified_user_id",
638+
"anonymousId": "anonymousId_1",
639+
"type": "identify",
640+
"context":
641+
{
642+
"traits":
643+
{
644+
"trait1": "new-val"
645+
},
646+
"ip": "14.5.67.21",
647+
"library":
648+
{
649+
"name": "http"
650+
}
651+
},
652+
"timestamp": "2020-02-02T00:23:09.544Z"
653+
}
654+
]
655+
}`)
656+
sendEvent(t, payloadRetlKafka, "retl", writeKey,
657+
withHeader("X-Rudder-Source-Id", "xxxyyyzzEaEurW247ad9WYZLUyk"),
658+
withHeader("X-Rudder-Destination-Id", "xxxyyyzzhyrw8v0CrTMrDZ4ovej"),
659+
withUrlPath("/internal/v1/retl"))
535660
}
536661

537662
func blockOnHold(t *testing.T) {
@@ -597,7 +722,20 @@ func sendPixelEvents(t *testing.T, writeKey string) {
597722
}
598723
}
599724

600-
func sendEvent(t *testing.T, payload *strings.Reader, callType, writeKey string) {
725+
func withHeader(key, value string) func(r *http.Request) {
726+
return func(req *http.Request) {
727+
req.Header.Add(key, value)
728+
}
729+
}
730+
731+
// withUrlPath will override the path of url in request
732+
func withUrlPath(urlPath string) func(r *http.Request) {
733+
return func(req *http.Request) {
734+
req.URL.Path = urlPath
735+
}
736+
}
737+
738+
func sendEvent(t *testing.T, payload *strings.Reader, callType, writeKey string, reqOptions ...func(r *http.Request)) {
601739
t.Helper()
602740
t.Logf("Sending %s Event", callType)
603741

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

759+
for _, reqOption := range reqOptions {
760+
reqOption(req)
761+
}
762+
621763
res, err := httpClient.Do(req)
622764
if err != nil {
623765
t.Logf("sendEvent error: %v", err)

0 commit comments

Comments
 (0)