Skip to content

Commit

Permalink
Include service plan fields when listing service instances
Browse files Browse the repository at this point in the history
fixes #3291

Co-authored-by: Yusmen Zabanov <[email protected]>
  • Loading branch information
danail-branekov and zabanov-lab committed Sep 9, 2024
1 parent 2696091 commit c13f55f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
8 changes: 8 additions & 0 deletions api/payloads/service_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ func (l ServiceInstanceList) Validate() error {

relationshipsPath := strings.Join(rule.RelationshipPath, ".")
switch relationshipsPath {
case "service_plan":
return jellidation.Each(validation.OneOf(
"guid",
"name",
"relationships.service_offering",
)).Validate(rule.Fields)
case "service_plan.service_offering":
return jellidation.Each(validation.OneOf(
"guid",
Expand All @@ -191,6 +197,7 @@ func (l ServiceInstanceList) Validate() error {
}

return validation.OneOf(
"service_plan",
"service_plan.service_offering",
"service_plan.service_offering.service_broker",
).Validate(relationshipsPath)
Expand All @@ -216,6 +223,7 @@ func (l *ServiceInstanceList) SupportedKeys() []string {
"label_selector",
"fields[service_plan.service_offering]",
"fields[service_plan.service_offering.service_broker]",
"fields[service_plan]",
}
}

Expand Down
8 changes: 8 additions & 0 deletions api/payloads/service_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ var _ = Describe("ServiceInstanceList", func() {
RelationshipPath: []string{"service_plan", "service_offering"},
Fields: []string{"guid", "name", "relationships.service_broker"},
}}}),

Entry("fields[service_plan]",
"fields[service_plan]=guid,name,relationships.service_offering",
payloads.ServiceInstanceList{IncludeResourceRules: []params.IncludeResourceRule{{
RelationshipPath: []string{"service_plan"},
Fields: []string{"guid", "name", "relationships.service_offering"},
}}}),
Entry("label_selector=foo", "label_selector=foo", payloads.ServiceInstanceList{LabelSelector: "foo"}),
)

Expand All @@ -54,6 +61,7 @@ var _ = Describe("ServiceInstanceList", func() {
Entry("invalid fields", "fields[foo]=bar", "unsupported query parameter: fields[foo]"),
Entry("invalid service offering fields", "fields[service_plan.service_offering]=foo", "value must be one of"),
Entry("invalid service broker fields", "fields[service_plan.service_offering.service_broker]=foo", "value must be one of"),
Entry("invalid service plan fields", "fields[service_plan]=foo", "value must be one of"),
)

Describe("ToMessage", func() {
Expand Down
7 changes: 0 additions & 7 deletions tests/smoke/catalog_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package smoke_test

import (
"strings"

"code.cloudfoundry.org/korifi/tests/helpers"

"github.com/BooleanCat/go-functional/v2/it"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
"github.com/onsi/gomega/types"
)

var _ = Describe("Service Catalog", func() {
Expand Down Expand Up @@ -94,7 +91,3 @@ var _ = Describe("Service Catalog", func() {
})
})
})

func matchSubstrings(substrings ...string) types.GomegaMatcher {
return MatchRegexp(strings.Join(substrings, ".*"))
}
23 changes: 22 additions & 1 deletion tests/smoke/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package smoke_test
import (
"code.cloudfoundry.org/korifi/tests/helpers"

"github.com/BooleanCat/go-functional/v2/it"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -29,8 +30,28 @@ var _ = Describe("Services", func() {

Describe("cf create-service", func() {
It("creates a managed service", func() {
session := helpers.Cf("create-service", "sample-service", "sample", "-b", brokerName, uuid.NewString())
session := helpers.Cf("create-service", "sample-service", "sample", uuid.NewString(), "-b", brokerName)
Expect(session).To(Exit(0))
})
})

Describe("cf services", func() {
var serviceName string

BeforeEach(func() {
serviceName = uuid.NewString()
session := helpers.Cf("create-service", "sample-service", "sample", serviceName, "-b", brokerName)
Expect(session).To(Exit(0))
})

It("lists services", func() {
session := helpers.Cf("services")
Expect(session).To(Exit(0))

lines, _ := it.Collect2(it.LinesString(session.Out))
Expect(lines).To(ContainElement(
matchSubstrings(serviceName, "sample-service", brokerName),
))
})
})
})
4 changes: 4 additions & 0 deletions tests/smoke/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,7 @@ func cleanupBroker(brokerName string) {
Expect(helpers.Cf("delete-service-broker", "-f", brokerName)).To(Exit(0))
broker.NewCatalogPurger(rootNamespace).ForBrokerName(brokerName).Purge()
}

func matchSubstrings(substrings ...string) types.GomegaMatcher {
return MatchRegexp(strings.Join(substrings, ".*"))
}

0 comments on commit c13f55f

Please sign in to comment.