tests for sync mode

This commit is contained in:
Alexander Baryshnikov 2020-11-10 02:03:52 +08:00
parent bae41da6cb
commit a418873901

View File

@ -177,6 +177,7 @@ func TestCron(t *testing.T) {
}
func TestSync(t *testing.T) {
t.Run("wait with default timeout", func(t *testing.T) {
srv := testServer(t, runner.DefaultConfig(), map[string]server.Unit{
"hello": {
Command: "echo hello world",
@ -188,4 +189,44 @@ func TestSync(t *testing.T) {
res := httptest.NewRecorder()
srv.ServeHTTP(res, req)
assert.Equal(t, http.StatusSeeOther, res.Code)
})
t.Run("wait with custom timeout", func(t *testing.T) {
srv := testServer(t, runner.DefaultConfig(), map[string]server.Unit{
"hello": {
Command: "echo hello world",
},
})
defer srv.Close()
req := httptest.NewRequest(http.MethodPut, "/api/hello/?wait=1h", bytes.NewBufferString("hello world"))
res := httptest.NewRecorder()
srv.ServeHTTP(res, req)
assert.Equal(t, http.StatusSeeOther, res.Code)
})
t.Run("fail on malformed timeout", func(t *testing.T) {
srv := testServer(t, runner.DefaultConfig(), map[string]server.Unit{
"hello": {
Command: "echo hello world",
},
})
defer srv.Close()
req := httptest.NewRequest(http.MethodPut, "/api/hello/?wait=10000", bytes.NewBufferString("hello world"))
res := httptest.NewRecorder()
srv.ServeHTTP(res, req)
assert.Equal(t, http.StatusBadRequest, res.Code)
})
t.Run("fail on invalid timeout", func(t *testing.T) {
srv := testServer(t, runner.DefaultConfig(), map[string]server.Unit{
"hello": {
Command: "echo hello world",
},
})
defer srv.Close()
req := httptest.NewRequest(http.MethodPut, "/api/hello/?wait=-10s", bytes.NewBufferString("hello world"))
res := httptest.NewRecorder()
srv.ServeHTTP(res, req)
assert.Equal(t, http.StatusBadRequest, res.Code)
})
}