Skip to content

Commit 3dd6d68

Browse files
Stub the /v3/spaces/{guid}/features/{name} endpoint
The enpoint is stubbed to return when the feature name is ssh enabled false, otherwise `UnprocessableEntityError` Co-authored-by: Danail Branekov <[email protected]>
1 parent 4e93488 commit 3dd6d68

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

api/handlers/space.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package handlers
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
67
"net/url"
78
"time"
@@ -21,6 +22,7 @@ const (
2122
SpacesPath = "/v3/spaces"
2223
SpacePath = "/v3/spaces/{guid}"
2324
RoutesForSpacePath = "/v3/spaces/{guid}/routes"
25+
SpaceFeaturePath = "/v3/spaces/{guid}/features/{name}"
2426
IsolationSegmentsForSpacePath = "/v3/spaces/{guid}/relationships/isolation_segment"
2527
)
2628

@@ -202,6 +204,21 @@ func (h *Space) getIsolationSegments(r *http.Request) (*routing.Response, error)
202204
return routing.NewResponse(http.StatusOK).WithBody(presenter.ForIsolationSegment(h.apiBaseURL)), nil
203205
}
204206

207+
func (h *Space) getSpaceFeature(r *http.Request) (*routing.Response, error) {
208+
logger := logr.FromContextOrDiscard(r.Context()).WithName("handlers.space.get-feature")
209+
210+
featureName := routing.URLParam(r, "name")
211+
if featureName != "ssh" {
212+
return nil, apierrors.LogAndReturn(logger, apierrors.NewUnprocessableEntityError(nil, fmt.Sprintf("feature %q is not supported", featureName)), "feature not supported")
213+
}
214+
215+
return routing.NewResponse(http.StatusOK).WithBody(map[string]any{
216+
"name": "ssh",
217+
"description": "Enable SSHing into apps in the space.",
218+
"enabled": false,
219+
}), nil
220+
}
221+
205222
func (h *Space) UnauthenticatedRoutes() []routing.Route {
206223
return nil
207224
}
@@ -215,5 +232,6 @@ func (h *Space) AuthenticatedRoutes() []routing.Route {
215232
{Method: "GET", Pattern: SpacePath, Handler: h.get},
216233
{Method: "DELETE", Pattern: RoutesForSpacePath, Handler: h.deleteUnmappedRoutes},
217234
{Method: "GET", Pattern: IsolationSegmentsForSpacePath, Handler: h.getIsolationSegments},
235+
{Method: "GET", Pattern: SpaceFeaturePath, Handler: h.getSpaceFeature},
218236
}
219237
}

api/handlers/space_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,33 @@ var _ = Describe("Space", func() {
493493
})
494494
})
495495

496+
Describe("Get space feature", func() {
497+
BeforeEach(func() {
498+
requestMethod = http.MethodGet
499+
requestPath += "/the-space-guid/features/ssh"
500+
})
501+
502+
It("returns the correct response body", func() {
503+
Expect(rr).To(HaveHTTPStatus(http.StatusOK))
504+
Expect(rr).To(HaveHTTPHeaderWithValue("Content-Type", "application/json"))
505+
Expect(rr).To(HaveHTTPBody(SatisfyAll(
506+
MatchJSONPath("$.name", "ssh"),
507+
MatchJSONPath("$.description", "Enable SSHing into apps in the space."),
508+
MatchJSONPath("$.enabled", false),
509+
)))
510+
})
511+
512+
When("the feature is not ssh", func() {
513+
BeforeEach(func() {
514+
requestPath = "/v3/spaces/the-space-guid/features/invalid-feature"
515+
})
516+
517+
It("returns error", func() {
518+
expectUnprocessableEntityError("feature \"invalid-feature\" is not supported")
519+
})
520+
})
521+
})
522+
496523
Describe("Delete unmapped routes for a space", func() {
497524
BeforeEach(func() {
498525
requestMethod = http.MethodDelete

tests/e2e/spaces_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,31 @@ var _ = Describe("Spaces", func() {
447447
Expect(resp).To(HaveRestyStatusCode(http.StatusOK))
448448
})
449449
})
450+
451+
Describe("features", func() {
452+
var (
453+
spaceGUID string
454+
result resource
455+
)
456+
457+
BeforeEach(func() {
458+
spaceGUID = createSpace(generateGUID("space"), commonTestOrgGUID)
459+
})
460+
461+
JustBeforeEach(func() {
462+
var err error
463+
resp, err = adminClient.R().
464+
SetResult(&result).
465+
Get("/v3/spaces/" + spaceGUID + "/features/ssh")
466+
Expect(err).NotTo(HaveOccurred())
467+
})
468+
469+
It("returns StatusOK", func() {
470+
Expect(resp).To(HaveRestyStatusCode(http.StatusOK))
471+
472+
respUnmarshalled := map[string]interface{}{}
473+
Expect(json.Unmarshal(resp.Body(), &respUnmarshalled)).To(Succeed())
474+
Expect(respUnmarshalled).To(HaveKeyWithValue("enabled", BeFalse()))
475+
})
476+
})
450477
})

0 commit comments

Comments
 (0)