From 2efcabb1d4e5ee31c38a6410c70c1bda93b59450 Mon Sep 17 00:00:00 2001 From: Danail Branekov Date: Fri, 13 Sep 2024 08:51:43 +0000 Subject: [PATCH] Include service plan fields when listing service instances fixes #3291 Co-authored-by: Yusmen Zabanov --- api/payloads/service_instance.go | 8 ++++++++ api/payloads/service_instance_test.go | 8 ++++++++ tests/smoke/catalog_test.go | 17 +++++------------ tests/smoke/services_test.go | 23 ++++++++++++++++++++++- tests/smoke/suite_test.go | 4 ++++ 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/api/payloads/service_instance.go b/api/payloads/service_instance.go index a66dde974..f43cac410 100644 --- a/api/payloads/service_instance.go +++ b/api/payloads/service_instance.go @@ -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", @@ -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) @@ -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]", } } diff --git a/api/payloads/service_instance_test.go b/api/payloads/service_instance_test.go index f99ceb8ae..9e5aa2a4b 100644 --- a/api/payloads/service_instance_test.go +++ b/api/payloads/service_instance_test.go @@ -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"}), ) @@ -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() { diff --git a/tests/smoke/catalog_test.go b/tests/smoke/catalog_test.go index 9da1397a1..2c46e8776 100644 --- a/tests/smoke/catalog_test.go +++ b/tests/smoke/catalog_test.go @@ -1,8 +1,6 @@ package smoke_test import ( - "strings" - "code.cloudfoundry.org/korifi/tests/helpers" "github.com/BooleanCat/go-functional/v2/it" @@ -10,7 +8,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" - "github.com/onsi/gomega/types" ) var _ = Describe("Service Catalog", func() { @@ -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))))) }) @@ -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))) }) }) @@ -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"), )) @@ -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"), )) @@ -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, ".*")) -} diff --git a/tests/smoke/services_test.go b/tests/smoke/services_test.go index 24c8bb801..67c6de525 100644 --- a/tests/smoke/services_test.go +++ b/tests/smoke/services_test.go @@ -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" @@ -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), + )) + }) + }) }) diff --git a/tests/smoke/suite_test.go b/tests/smoke/suite_test.go index 332cf9acc..d4f0143e1 100644 --- a/tests/smoke/suite_test.go +++ b/tests/smoke/suite_test.go @@ -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, ".*")) +}