2021-09-13 00:39:09 +02:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
2022-07-29 02:07:53 +02:00
|
|
|
|
|
|
|
"github.com/TwiN/gatus/v4/config"
|
2021-09-13 00:39:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFavIcon(t *testing.T) {
|
2022-07-29 02:07:53 +02:00
|
|
|
router := CreateRouter("../../web/static", &config.Config{})
|
2021-09-13 00:39:09 +02:00
|
|
|
type Scenario struct {
|
|
|
|
Name string
|
|
|
|
Path string
|
|
|
|
ExpectedCode int
|
|
|
|
}
|
|
|
|
scenarios := []Scenario{
|
|
|
|
{
|
|
|
|
Name: "favicon",
|
|
|
|
Path: "/favicon.ico",
|
|
|
|
ExpectedCode: http.StatusOK,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, scenario := range scenarios {
|
|
|
|
t.Run(scenario.Name, func(t *testing.T) {
|
2021-11-11 06:14:00 +01:00
|
|
|
request, _ := http.NewRequest("GET", scenario.Path, http.NoBody)
|
2021-09-13 00:39:09 +02:00
|
|
|
responseRecorder := httptest.NewRecorder()
|
|
|
|
router.ServeHTTP(responseRecorder, request)
|
|
|
|
if responseRecorder.Code != scenario.ExpectedCode {
|
|
|
|
t.Errorf("%s %s should have returned %d, but returned %d instead", request.Method, request.URL, scenario.ExpectedCode, responseRecorder.Code)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|