@@ -23,6 +23,7 @@ import (
2323 "net/http/httptest"
2424 "net/url"
2525 "reflect"
26+ "strconv"
2627 "strings"
2728 "sync"
2829 "testing"
@@ -76,6 +77,9 @@ func TestRestSink_Apply(t *testing.T) {
7677 config : map [string ]interface {}{
7778 "method" : "post" ,
7879 //"url": "http://localhost/test", //set dynamically to the test server
80+ "headers" : map [string ]any {
81+ "Content-Type" : "application/vnd.microsoft.servicebus.json" ,
82+ },
7983 },
8084 data : []map [string ]interface {}{{
8185 "ab" : "hello1" ,
@@ -85,7 +89,7 @@ func TestRestSink_Apply(t *testing.T) {
8589 result : []request {{
8690 Method : "POST" ,
8791 Body : `[{"ab":"hello1"},{"ab":"hello2"}]` ,
88- ContentType : "application/json" ,
92+ ContentType : "application/vnd.microsoft.servicebus. json" ,
8993 }},
9094 }, {
9195 config : map [string ]interface {}{
@@ -202,28 +206,28 @@ func TestRestSink_Apply(t *testing.T) {
202206 tf , _ := transform .GenTransform ("" , "json" , "" , "" , "" , []string {})
203207 defer ts .Close ()
204208 for i , tt := range tests {
205- requests = nil
206- ss , ok := tt .config ["sendSingle" ]
207- if ! ok {
208- ss = false
209- }
210- s := & RestSink {}
211- tt .config ["url" ] = ts .URL
212- s .Configure (tt .config )
213- s .Open (ctx )
214- vCtx := context .WithValue (ctx , context .TransKey , tf )
215- if ss .(bool ) {
216- for _ , d := range tt .data {
217- s .Collect (vCtx , d )
209+ t .Run (strconv .Itoa (i ), func (t * testing.T ) {
210+ requests = nil
211+ ss , ok := tt .config ["sendSingle" ]
212+ if ! ok {
213+ ss = false
214+ }
215+ s := & RestSink {}
216+ tt .config ["url" ] = ts .URL
217+ s .Configure (tt .config )
218+ s .Open (ctx )
219+ vCtx := context .WithValue (ctx , context .TransKey , tf )
220+ if ss .(bool ) {
221+ for _ , d := range tt .data {
222+ s .Collect (vCtx , d )
223+ }
224+ } else {
225+ s .Collect (vCtx , tt .data )
218226 }
219- } else {
220- s .Collect (vCtx , tt .data )
221- }
222227
223- s .Close (ctx )
224- if ! reflect .DeepEqual (tt .result , requests ) {
225- t .Errorf ("%d \t result mismatch:\n \n exp=%#v\n \n got=%#v\n \n " , i , tt .result , requests )
226- }
228+ s .Close (ctx )
229+ assert .Equal (t , tt .result , requests )
230+ })
227231 }
228232}
229233
0 commit comments