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 <yusmen.zabanov@sap.com>
  • Loading branch information
danail-branekov and zabanov-lab committed Sep 13, 2024
1 parent 22e6d4c commit 2efcabb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 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
17 changes: 5 additions & 12 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 All @@ -36,7 +33,7 @@ var _ = Describe("Service Catalog", func() {
session := helpers.Cf("service-brokers")
Expect(session).To(Exit(0))

lines, _ := it.Collect2(it.LinesString(session.Out))
lines := it.MustCollect(it.LinesString(session.Out))
Expect(lines).To(ContainElement(
matchSubstrings(brokerName, helpers.GetInClusterURL(getAppGUID(brokerAppName)))))
})
Expand All @@ -50,7 +47,7 @@ var _ = Describe("Service Catalog", func() {
session = helpers.Cf("service-brokers")
Expect(session).To(Exit(0))

lines, _ := it.Collect2(it.LinesString(session.Out))
lines := it.MustCollect(it.LinesString(session.Out))
Expect(lines).NotTo(ContainElement(ContainSubstring(brokerName)))
})
})
Expand All @@ -60,7 +57,7 @@ var _ = Describe("Service Catalog", func() {
session := helpers.Cf("service-access", "-b", brokerName)
Expect(session).To(Exit(0))

lines, _ := it.Collect2(it.LinesString(session.Out))
lines := it.MustCollect(it.LinesString(session.Out))
Expect(lines).To(ContainElements(
matchSubstrings("sample-service", "sample", "none"),
))
Expand All @@ -75,7 +72,7 @@ var _ = Describe("Service Catalog", func() {
session = helpers.Cf("service-access")
Expect(session).To(Exit(0))

lines, _ := it.Collect2(it.LinesString(session.Out))
lines := it.MustCollect(it.LinesString(session.Out))
Expect(lines).To(ContainElements(
matchSubstrings("sample-service", "sample", "all"),
))
Expand All @@ -87,14 +84,10 @@ var _ = Describe("Service Catalog", func() {
session := helpers.Cf("marketplace", "-b", brokerName, "--show-unavailable")
Expect(session).To(Exit(0))

lines, _ := it.Collect2(it.LinesString(session.Out))
lines := it.MustCollect(it.LinesString(session.Out))
Expect(lines).To(ContainElement(
matchSubstrings("sample-service", "A sample service that does nothing", brokerName),
))
})
})
})

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.MustCollect(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 2efcabb

Please sign in to comment.