Add tests for endpoints
This commit is contained in:
12
pkg/registrar/endpoints.go
Normal file
12
pkg/registrar/endpoints.go
Normal 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"}`))
|
||||||
|
}
|
||||||
20
pkg/registrar/endpoints_test.go
Normal file
20
pkg/registrar/endpoints_test.go
Normal 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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user