Skip to content

Commit c8c9882

Browse files
authored
fix(tests): remove test dependency (#256)
1 parent 07f9438 commit c8c9882

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

worker/deliverer/http_test.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,46 @@ import (
66
"errors"
77
"github.com/stretchr/testify/assert"
88
"github.com/webhookx-io/webhookx/config"
9+
"io"
10+
"net/http"
11+
"net/http/httptest"
912
"testing"
1013
"time"
1114
)
1215

1316
func Test(t *testing.T) {
17+
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
18+
time.Sleep(100 * time.Millisecond)
19+
body, err := io.ReadAll(r.Body)
20+
if err != nil {
21+
panic(err)
22+
}
23+
24+
headers := make(map[string]string)
25+
for k, v := range r.Header {
26+
if len(v) > 0 {
27+
headers[k] = v[0]
28+
}
29+
}
30+
31+
resp := map[string]interface{}{
32+
"data": string(body),
33+
"headers": headers,
34+
}
35+
w.Header().Set("Content-Type", "application/json")
36+
json.NewEncoder(w).Encode(resp)
37+
})
38+
server := httptest.NewServer(handler)
39+
defer server.Close()
40+
1441
t.Run("sanity", func(t *testing.T) {
1542
cfg := config.WorkerDeliverer{
1643
Timeout: 10 * 1000,
1744
}
1845
deliverer := NewHTTPDeliverer(&cfg)
1946

2047
req := &Request{
21-
URL: "http://localhost:9999/anything",
48+
URL: server.URL,
2249
Method: "POST",
2350
Payload: []byte(`{"foo": "bar"}`),
2451
Headers: map[string]string{
@@ -44,7 +71,7 @@ func Test(t *testing.T) {
4471
deliverer := NewHTTPDeliverer(&cfg)
4572

4673
req := &Request{
47-
URL: "http://localhost:9999/anything",
74+
URL: server.URL,
4875
Method: "GET",
4976
Timeout: time.Microsecond * 1,
5077
}

0 commit comments

Comments
 (0)