@ -0,0 +1,21 @@ |
|||||
|
package api |
||||
|
|
||||
|
import ( |
||||
|
"net/http" |
||||
|
"regexp" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
func (a *API) noRoute(c *gin.Context) { |
||||
|
matched, _ := regexp.MatchString(`^/v[0-9]+/`, c.Request.URL.Path) |
||||
|
if !matched { |
||||
|
c.JSON(http.StatusNotFound, gin.H{ |
||||
|
"error": "Version not provided, please provide a valid version in the path such as v1", |
||||
|
}) |
||||
|
return |
||||
|
} |
||||
|
c.JSON(http.StatusNotFound, gin.H{ |
||||
|
"error": "404 page not found", |
||||
|
}) |
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
package api |
||||
|
|
||||
|
import ( |
||||
|
"testing" |
||||
|
|
||||
|
"github.com/stretchr/testify/assert" |
||||
|
) |
||||
|
|
||||
|
func TestNoRouteVersionNotProvided(t *testing.T) { |
||||
|
endpoint := apiIP + apiPort + "/" |
||||
|
// not using doGoodReq, bcs internally
|
||||
|
// there is a method FindRoute that checks route and returns error
|
||||
|
resp, err := doSimpleReq("GET", endpoint) |
||||
|
assert.NoError(t, err) |
||||
|
assert.Equal(t, |
||||
|
"{\"error\":\"Version not provided, please provide a valid version in the path such as v1\"}\n", |
||||
|
resp) |
||||
|
} |
||||
|
|
||||
|
func TestNoRoute(t *testing.T) { |
||||
|
endpoint := apiURL |
||||
|
// not using doGoodReq, bcs internally
|
||||
|
// there is a method FindRoute that checks route and returns error
|
||||
|
resp, err := doSimpleReq("GET", endpoint) |
||||
|
assert.NoError(t, err) |
||||
|
assert.Equal(t, |
||||
|
"{\"error\":\"404 page not found\"}\n", |
||||
|
resp) |
||||
|
} |