Add tests for endpoints

This commit is contained in:
2023-07-03 09:18:48 -04:00
parent c2b09b3650
commit a43264189f
2 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package registrar
import (
"net/http"
)
func HandleRegister(resp http.ResponseWriter, req *http.Request) {
headers := resp.Header()
headers.Set("content-type", "application/json")
resp.WriteHeader(http.StatusOK)
resp.Write([]byte(`{"status": "registered"}`))
}

View File

@@ -0,0 +1,20 @@
package registrar
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestHandleRegister(t *testing.T) {
resp := httptest.NewRecorder()
req, err := http.NewRequest(http.MethodGet, "http://example.com/v1/register", nil)
require.NoError(t, err)
HandleRegister(resp, req)
assert.Equal(t, http.StatusBadRequest, resp.Code)
}