mirror of
https://github.com/sablierapp/sablier.git
synced 2026-01-03 11:34:58 +01:00
* 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
64 lines
1.2 KiB
Go
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)
|
|
})
|
|
}
|
|
}
|