tests for sync mode
This commit is contained in:
parent
bae41da6cb
commit
a418873901
@ -177,15 +177,56 @@ func TestCron(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSync(t *testing.T) {
|
func TestSync(t *testing.T) {
|
||||||
srv := testServer(t, runner.DefaultConfig(), map[string]server.Unit{
|
t.Run("wait with default timeout", func(t *testing.T) {
|
||||||
"hello": {
|
srv := testServer(t, runner.DefaultConfig(), map[string]server.Unit{
|
||||||
Command: "echo hello world",
|
"hello": {
|
||||||
},
|
Command: "echo hello world",
|
||||||
})
|
},
|
||||||
defer srv.Close()
|
})
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPut, "/api/hello/", bytes.NewBufferString("hello world"))
|
req := httptest.NewRequest(http.MethodPut, "/api/hello/", bytes.NewBufferString("hello world"))
|
||||||
res := httptest.NewRecorder()
|
res := httptest.NewRecorder()
|
||||||
srv.ServeHTTP(res, req)
|
srv.ServeHTTP(res, req)
|
||||||
assert.Equal(t, http.StatusSeeOther, res.Code)
|
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)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user