Skip to content

Commit

Permalink
test: update with FalcoSidekickURL case (#163)
Browse files Browse the repository at this point in the history
also adds with invalid case

Signed-off-by: Dwi Siswanto <[email protected]>
  • Loading branch information
dwisiswant0 authored Feb 25, 2024
1 parent d469b5d commit b2aee2a
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion teler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,47 @@ func TestNewWithFalcoSidekickURL(t *testing.T) {
t.Fatal(err)
}

_, err = client.Do(req)
for i := 0; i < 5; i++ {
_, err = client.Do(req)
if err != nil {
t.Fatal(err)
}
}

time.Sleep(5 * time.Second)
}

func TestNewWithInvalidFalcoSidekickURL(t *testing.T) {
// Initialize Falco Sidekick handler
falcoSidekickHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})

// Initialize Falco Sidekick server
falcoSidekickServer := httptest.NewServer(falcoSidekickHandler)
falcoSidekickServer.Close() // Close server early

// Initialize teler
telerMiddleware := New(Options{NoStderr: true, FalcoSidekickURL: falcoSidekickServer.URL})
wrappedHandler := telerMiddleware.Handler(handler)

// Create a test server with the wrapped handler
ts := httptest.NewServer(wrappedHandler)
defer ts.Close()

// Create a request to send to the test server
req, err := http.NewRequest("GET", ts.URL, nil)
if err != nil {
t.Fatal(err)
}

for i := 0; i < 5; i++ {
_, err = client.Do(req)
if err != nil {
t.Fatal(err)
}
}

time.Sleep(5 * time.Second)
}

Expand Down

0 comments on commit b2aee2a

Please sign in to comment.