test: reactions (#1081)

This commit is contained in:
Jonas Plum
2024-07-20 07:50:42 +02:00
committed by GitHub
parent e2c8f1d223
commit e9583a29fa
6 changed files with 198 additions and 35 deletions

View File

@@ -3,7 +3,6 @@ package testing
import (
"net/http"
"testing"
"time"
"github.com/stretchr/testify/require"
)
@@ -12,10 +11,9 @@ func TestWebhookReactions(t *testing.T) {
baseApp, adminToken, analystToken, baseAppCleanup := BaseApp(t)
defer baseAppCleanup()
server := testWebhookServer()
defer server.Close()
server := NewRecordingServer()
go server.ListenAndServe() //nolint:errcheck
go http.ListenAndServe("127.0.0.1:12345", server) //nolint:gosec,errcheck
testSets := []authMatrixText{
{
@@ -83,37 +81,6 @@ func TestWebhookReactions(t *testing.T) {
}
}
func testWebhookServer() *http.Server {
mux := http.NewServeMux()
mux.HandleFunc("/webhook", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"test":true}`)) //nolint:errcheck
})
return &http.Server{
Addr: "127.0.0.1:12345",
Handler: mux,
ReadHeaderTimeout: 3 * time.Second,
}
}
type RecordingServer struct {
Entries []string
}
func NewRecordingServer() *RecordingServer {
return &RecordingServer{}
}
func (s *RecordingServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.Entries = append(s.Entries, r.URL.Path)
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"test":true}`)) //nolint:errcheck
}
func TestHookReactions(t *testing.T) {
baseApp, _, analystToken, baseAppCleanup := BaseApp(t)
defer baseAppCleanup()