Add e2e-test for delete runner route

This commit is contained in:
Jan-Eric Hellenberg
2021-05-07 10:12:42 +02:00
parent ba51956ec3
commit ec1968ecf5
2 changed files with 47 additions and 1 deletions

12
e2e_tests/helpers.go Normal file
View File

@ -0,0 +1,12 @@
package e2e_tests
import (
"io"
"net/http"
)
func httpDelete(url string, body io.Reader) (response *http.Response, err error) {
req, _ := http.NewRequest(http.MethodDelete, url, body)
client := &http.Client{}
return client.Do(req)
}

View File

@ -11,7 +11,8 @@ import (
)
func TestProvideRunnerRoute(t *testing.T) {
reader := strings.NewReader(`{"executionEnvironmentId":0}`)
runnerRequestString, _ := json.Marshal(dto.RunnerRequest{})
reader := strings.NewReader(string(runnerRequestString))
resp, err := http.Post(buildURL(api.RouteRunners), "application/json", reader)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode, "The response code should be ok")
@ -22,3 +23,36 @@ func TestProvideRunnerRoute(t *testing.T) {
assert.True(t, runnerResponse.Id != "", "The response contains a runner id")
}
func newRunnerId(t *testing.T) string {
runnerRequestString, _ := json.Marshal(dto.RunnerRequest{})
reader := strings.NewReader(string(runnerRequestString))
resp, err := http.Post(buildURL(api.RouteRunners), "application/json", reader)
assert.NoError(t, err)
runnerResponse := new(dto.RunnerResponse)
_ = json.NewDecoder(resp.Body).Decode(runnerResponse)
return runnerResponse.Id
}
func TestDeleteRunnerRoute(t *testing.T) {
runnerId := newRunnerId(t)
assert.NotEqual(t, "", runnerId)
t.Run("Deleting the runner returns NoContent", func(t *testing.T) {
resp, err := httpDelete(buildURL(api.RouteRunners, "/", runnerId), nil)
assert.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
})
t.Run("Deleting it again returns NotFound", func(t *testing.T) {
resp, err := httpDelete(buildURL(api.RouteRunners, "/", runnerId), nil)
assert.NoError(t, err)
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
})
t.Run("Deleting non-existing runner returns NotFound", func(t *testing.T) {
resp, err := httpDelete(buildURL(api.RouteRunners, "/", "n0n-3x1st1ng-1d"), nil)
assert.NoError(t, err)
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
})
}