@@ -556,10 +556,7 @@ func sendEventsToGateway(t *testing.T) {
556
556
}
557
557
]
558
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" ))
559
+ sendRETL (t , payloadRetlWebhook , "xxxyyyzzEaEurW247ad9WYZLUyk" , "xxxyyyzzP9kQfzOoKd1tuxchYAG" )
563
560
564
561
payloadRetlKafka := strings .NewReader (`{
565
562
"batch":
@@ -653,10 +650,7 @@ func sendEventsToGateway(t *testing.T) {
653
650
}
654
651
]
655
652
}` )
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" ))
653
+ sendRETL (t , payloadRetlKafka , "xxxyyyzzEaEurW247ad9WYZLUyk" , "xxxyyyzzhyrw8v0CrTMrDZ4ovej" )
660
654
}
661
655
662
656
func blockOnHold (t * testing.T ) {
@@ -722,20 +716,46 @@ func sendPixelEvents(t *testing.T, writeKey string) {
722
716
}
723
717
}
724
718
725
- func withHeader (key , value string ) func (r * http.Request ) {
726
- return func (req * http.Request ) {
727
- req .Header .Add (key , value )
719
+ func sendRETL (t * testing.T , payload * strings.Reader , sourceID , DestinationID string ) {
720
+ t .Helper ()
721
+ t .Logf ("Sending rETL Event" )
722
+
723
+ var (
724
+ httpClient = & http.Client {}
725
+ method = "POST"
726
+ url = fmt .Sprintf ("http://localhost:%s/internal/v1/retl" , httpPort )
727
+ )
728
+
729
+ req , err := http .NewRequest (method , url , payload )
730
+ if err != nil {
731
+ t .Logf ("sendEvent error: %v" , err )
732
+ return
728
733
}
729
- }
730
734
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
+ req .Header .Add ("Content-Type" , "application/json" )
736
+ req .Header .Add ("X-Rudder-Source-Id" , sourceID )
737
+ req .Header .Add ("X-Rudder-Destination-Id" , DestinationID )
738
+
739
+ res , err := httpClient .Do (req )
740
+ if err != nil {
741
+ t .Logf ("sendEvent error: %v" , err )
742
+ return
743
+ }
744
+ defer func () { httputil .CloseResponse (res ) }()
745
+
746
+ body , err := io .ReadAll (res .Body )
747
+ if err != nil {
748
+ t .Logf ("sendEvent error: %v" , err )
749
+ return
750
+ }
751
+ if res .Status != "200 OK" {
752
+ return
735
753
}
754
+
755
+ t .Logf ("Event Sent Successfully: (%s)" , body )
736
756
}
737
757
738
- func sendEvent (t * testing.T , payload * strings.Reader , callType , writeKey string , reqOptions ... func ( r * http. Request ) ) {
758
+ func sendEvent (t * testing.T , payload * strings.Reader , callType , writeKey string ) {
739
759
t .Helper ()
740
760
t .Logf ("Sending %s Event" , callType )
741
761
@@ -756,10 +776,6 @@ func sendEvent(t *testing.T, payload *strings.Reader, callType, writeKey string,
756
776
[]byte (fmt .Sprintf ("%s:" , writeKey )),
757
777
)))
758
778
759
- for _ , reqOption := range reqOptions {
760
- reqOption (req )
761
- }
762
-
763
779
res , err := httpClient .Do (req )
764
780
if err != nil {
765
781
t .Logf ("sendEvent error: %v" , err )
0 commit comments