Skip to content

Commit

Permalink
endpoint function exporting reverted due to changing test source file…
Browse files Browse the repository at this point in the history
… package to the same as the endpoint functions.

Signed-off-by: Michael Valdron <mvaldron@redhat.com>
  • Loading branch information
michael-valdron committed Jul 29, 2022
1 parent 74366e7 commit a62e5ff
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
32 changes: 16 additions & 16 deletions index/server/pkg/server/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"gopkg.in/segmentio/analytics-go.v3"
)

// ServeRootEndpoint sets up the handler for the root (/) endpoint on the server
// serveRootEndpoint sets up the handler for the root (/) endpoint on the server
// If html is requested (i.e. from a web browser), the viewer is displayed, otherwise the devfile index is served.
func ServeRootEndpoint(c *gin.Context) {
func serveRootEndpoint(c *gin.Context) {
// Determine if text/html was requested by the client
acceptHeader := c.Request.Header.Values("Accept")
if util.IsHtmlRequested(acceptHeader) {
Expand All @@ -36,11 +36,11 @@ func ServeRootEndpoint(c *gin.Context) {
}
}

func ServeDevfileIndexV1(c *gin.Context) {
func serveDevfileIndexV1(c *gin.Context) {
serveDevfileIndex(c, true)
}

func ServeDevfileIndexV2(c *gin.Context) {
func serveDevfileIndexV2(c *gin.Context) {
serveDevfileIndex(c, false)
}

Expand All @@ -62,26 +62,26 @@ func serveDevfileIndex(c *gin.Context, wantV1Index bool) {
buildIndexAPIResponse(c, wantV1Index)
}

func ServeDevfileIndexV1WithType(c *gin.Context) {
func serveDevfileIndexV1WithType(c *gin.Context) {

// Serve the index with type
buildIndexAPIResponse(c, true)
}

func ServeDevfileIndexV2WithType(c *gin.Context) {
func serveDevfileIndexV2WithType(c *gin.Context) {

// Serve the index with type
buildIndexAPIResponse(c, false)
}

// ServeHealthCheck serves endpoint `/health` for registry health check
func ServeHealthCheck(c *gin.Context) {
// serveHealthCheck serves endpoint `/health` for registry health check
func serveHealthCheck(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "the server is up and running",
})
}

func ServeDevfileWithVersion(c *gin.Context) {
func serveDevfileWithVersion(c *gin.Context) {
name := c.Param("name")
version := c.Param("version")
bytes, devfileIndex := fetchDevfile(c, name, version)
Expand Down Expand Up @@ -111,21 +111,21 @@ func ServeDevfileWithVersion(c *gin.Context) {
}
}

// ServeDevfile returns the devfile content
func ServeDevfile(c *gin.Context) {
// serveDevfile returns the devfile content
func serveDevfile(c *gin.Context) {
// append the stack version, for endpoint /devfiles/name without version
c.Params = append(c.Params, gin.Param{Key: "version", Value: "default"})
ServeDevfileWithVersion(c)
serveDevfileWithVersion(c)
}

// ServeDevfileStarterProject returns the starter project content for the devfile using default version
func ServeDevfileStarterProject(c *gin.Context) {
// serveDevfileStarterProject returns the starter project content for the devfile using default version
func serveDevfileStarterProject(c *gin.Context) {
c.Params = append(c.Params, gin.Param{Key: "version", Value: "default"})
ServeDevfileStarterProjectWithVersion(c)
serveDevfileStarterProjectWithVersion(c)
}

// serveDevfileStarterProject returns the starter project content for the devfile using specified version
func ServeDevfileStarterProjectWithVersion(c *gin.Context) {
func serveDevfileStarterProjectWithVersion(c *gin.Context) {
devfileName := c.Param("name")
version := c.Param("version")
starterProjectName := c.Param("starterProjectName")
Expand Down
6 changes: 3 additions & 3 deletions index/server/pkg/server/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestServeHealthCheck(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)

ServeHealthCheck(c)
serveHealthCheck(c)

wantStatusCode := 200
if gotStatusCode := w.Code; !reflect.DeepEqual(gotStatusCode, wantStatusCode) {
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestServeDevfileIndexV1(t *testing.T) {

c.Params = test.params

ServeDevfileIndexV1(c)
serveDevfileIndexV1(c)

if gotStatusCode := w.Code; !reflect.DeepEqual(gotStatusCode, test.wantCode) {
t.Errorf("Did not get expected status code, Got: %v, Expected: %v", gotStatusCode, test.wantCode)
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestServeDevfileIndexV2(t *testing.T) {

c.Params = test.params

ServeDevfileIndexV2(c)
serveDevfileIndexV2(c)

if gotStatusCode := w.Code; !reflect.DeepEqual(gotStatusCode, test.wantCode) {
t.Errorf("Did not get expected status code, Got: %v, Expected: %v", gotStatusCode, test.wantCode)
Expand Down
20 changes: 10 additions & 10 deletions index/server/pkg/server/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ func CreateIndexServer() *gin.Engine {
router := gin.Default()

// Registry REST APIs
router.GET("/", ServeRootEndpoint)
router.GET("/index", ServeDevfileIndexV1)
router.GET("/index/:type", ServeDevfileIndexV1WithType)
router.GET("/health", ServeHealthCheck)
router.GET("/devfiles/:name", ServeDevfile)
router.GET("/devfiles/:name/:version", ServeDevfileWithVersion)
router.GET("/devfiles/:name/starter-projects/:starterProjectName", ServeDevfileStarterProject)
router.GET("/devfiles/:name/:version/starter-projects/:starterProjectName", ServeDevfileStarterProjectWithVersion)
router.GET("/", serveRootEndpoint)
router.GET("/index", serveDevfileIndexV1)
router.GET("/index/:type", serveDevfileIndexV1WithType)
router.GET("/health", serveHealthCheck)
router.GET("/devfiles/:name", serveDevfile)
router.GET("/devfiles/:name/:version", serveDevfileWithVersion)
router.GET("/devfiles/:name/starter-projects/:starterProjectName", serveDevfileStarterProject)
router.GET("/devfiles/:name/:version/starter-projects/:starterProjectName", serveDevfileStarterProjectWithVersion)

// Registry REST APIs for index v2
router.GET("/v2index", ServeDevfileIndexV2)
router.GET("/v2index/:type", ServeDevfileIndexV2WithType)
router.GET("/v2index", serveDevfileIndexV2)
router.GET("/v2index/:type", serveDevfileIndexV2WithType)

// Set up a simple proxy for /v2 endpoints
// Only allow HEAD and GET requests
Expand Down

0 comments on commit a62e5ff

Please sign in to comment.