Files
sablier/pkg/strategy/dynamic_strategy_test.go
Alexis Couvreur b4f5eebaac feat: add blocking request (#12)
* feat: add blocking strategy

* docs: add examples for blocking strategy

* ci: run go tests recursively

* perf: wait for BlockCheckInterval for each request

* fix: use camel case instead of snake case for yaml config

* docs: add loading and error page customization as a feature

* fix: use errorPage

* fix: return json instead of html page

* set json key

* update development config

* docs: add comment about custom loading pages

* ci: add beta release
2021-12-11 15:46:56 +01:00

64 lines
1.2 KiB
Go

package strategy
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDynamicStrategy_ServeHTTP(t *testing.T) {
testCases := []struct {
desc string
status string
expected int
}{
{
desc: "service is starting",
status: "starting",
expected: 202,
},
{
desc: "service is started",
status: "started",
expected: 200,
},
{
desc: "ondemand service is in error",
status: "error",
expected: 500,
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, test.status)
}))
defer mockServer.Close()
dynamicStrategy := &DynamicStrategy{
Name: "whoami",
Request: mockServer.URL,
Next: next,
}
recorder := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "http://mydomain/whoami", nil)
dynamicStrategy.ServeHTTP(recorder, req)
assert.Equal(t, test.expected, recorder.Code)
})
}
}