Files
sablier/ondemand_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

66 lines
1.2 KiB
Go

package traefik_ondemand_plugin
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewOndemand(t *testing.T) {
testCases := []struct {
desc string
config *Config
expectedError bool
}{
{
desc: "invalid Config",
config: &Config{
ServiceUrl: "",
Timeout: "1m",
},
expectedError: true,
},
{
desc: "valid Dynamic Config",
config: &Config{
Name: "whoami",
ServiceUrl: "http://ondemand:1000",
WaitUi: true,
Timeout: "1m",
},
expectedError: false,
},
{
desc: "valid Blocking Config",
config: &Config{
Name: "whoami",
ServiceUrl: "http://ondemand:1000",
WaitUi: false,
BlockDelay: "1m",
Timeout: "1m",
},
expectedError: false,
},
}
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) {})
ondemand, err := New(context.Background(), next, test.config, "traefikTest")
if test.expectedError {
assert.Error(t, err)
} else {
require.NoError(t, err)
assert.NotNil(t, ondemand)
}
})
}
}