mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-07 21:48:18 -08:00
Merge pull request #19 from Ian-J-S/p1/ian-health_check_test
Health check test
This commit is contained in:
commit
4efad3b239
1 changed files with 35 additions and 0 deletions
|
|
@ -16,6 +16,8 @@ import (
|
||||||
"github.com/gabehf/koito/internal/db/psql"
|
"github.com/gabehf/koito/internal/db/psql"
|
||||||
"github.com/gabehf/koito/internal/utils"
|
"github.com/gabehf/koito/internal/utils"
|
||||||
"github.com/ory/dockertest/v3"
|
"github.com/ory/dockertest/v3"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var store *psql.Psql
|
var store *psql.Psql
|
||||||
|
|
@ -147,3 +149,36 @@ func TestMain(m *testing.M) {
|
||||||
func host() string {
|
func host() string {
|
||||||
return fmt.Sprintf("http://%s", cfg.ListenAddr())
|
return fmt.Sprintf("http://%s", cfg.ListenAddr())
|
||||||
}
|
}
|
||||||
|
func TestHealthEndpointNoAuth(t *testing.T) {
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s/apis/web/v1/health", host())
|
||||||
|
resp, err := client.Get(url)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, resp)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHealthEndpointMethodNotAllowed(t *testing.T) {
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s/apis/web/v1/health", host())
|
||||||
|
methods := []string{http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch}
|
||||||
|
|
||||||
|
for _, method := range methods {
|
||||||
|
req, err := http.NewRequest(method, url, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
assert.Equal(t, http.StatusMethodNotAllowed, resp.StatusCode, "method %s should return 405", method)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue