Skip to content

Commit 77ff686

Browse files
claude[bot]mxpv
andcommitted
Fix flaky CI test by replacing external dependency with local test server
The TestExecuteHook_CurlWebhook test was failing intermittently in CI with 'signal: killed' errors due to external dependency on httpbin.org. This fix replaces the external HTTP request with a local httptest.Server to eliminate network-related flakiness and make the test deterministic. Changes: - Replace httpbin.org with httptest.NewServer for reliable testing - Add request verification to ensure the webhook functionality works - Maintain the same test coverage while eliminating external dependency Co-authored-by: Maksym Pavlenko <[email protected]>
1 parent 189e807 commit 77ff686

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

pkg/feed/hooks_test.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package feed
22

33
import (
4+
"fmt"
5+
"io"
6+
"net/http"
7+
"net/http/httptest"
48
"os"
59
"path/filepath"
610
"testing"
@@ -93,8 +97,28 @@ func TestExecuteHook_CornerCases(t *testing.T) {
9397
}
9498

9599
func TestExecuteHook_CurlWebhook(t *testing.T) {
100+
// Create a local test server to avoid external dependencies
101+
receivedData := ""
102+
receivedHeaders := make(map[string]string)
103+
104+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
105+
// Capture the request data for verification
106+
body, err := io.ReadAll(r.Body)
107+
if err == nil {
108+
receivedData = string(body)
109+
}
110+
receivedHeaders["Content-Type"] = r.Header.Get("Content-Type")
111+
receivedHeaders["User-Agent"] = r.Header.Get("User-Agent")
112+
113+
// Return a simple response
114+
w.WriteHeader(http.StatusOK)
115+
fmt.Fprintln(w, `{"status": "ok"}`)
116+
}))
117+
defer server.Close()
118+
119+
// Use the local test server URL instead of external httpbin.org
96120
hook := &ExecHook{
97-
Command: []string{"curl -s -X POST -d \"$EPISODE_TITLE\" httpbin.org/post"},
121+
Command: []string{fmt.Sprintf("curl -s -X POST -d \"$EPISODE_TITLE\" %s", server.URL)},
98122
Timeout: 10,
99123
}
100124

@@ -106,4 +130,8 @@ func TestExecuteHook_CurlWebhook(t *testing.T) {
106130

107131
err := hook.Invoke(env)
108132
assert.NoError(t, err, "Curl webhook should execute successfully")
133+
134+
// Verify that the request was actually made and data was received
135+
assert.Equal(t, "Test Episode for Webhook", receivedData, "Server should receive the episode title")
136+
assert.Contains(t, receivedHeaders["User-Agent"], "curl", "Request should be made by curl")
109137
}

0 commit comments

Comments
 (0)