-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI tests for the following commands: * `create-service-broker` * `delete-service-broker` * `service-access` * `enable-service-access` * `marketplace`
- Loading branch information
1 parent
873f63a
commit 32bb50a
Showing
6 changed files
with
235 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1" | ||
. "github.com/onsi/ginkgo/v2" //lint:ignore ST1001 this is a test file | ||
. "github.com/onsi/gomega" //lint:ignore ST1001 this is a test file | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"k8s.io/client-go/kubernetes/scheme" | ||
controllerruntime "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func GetInClusterURL(appGUID string) string { | ||
GinkgoHelper() | ||
|
||
config, err := controllerruntime.GetConfig() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
k8sClient, err := client.New(config, client.Options{Scheme: scheme.Scheme}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
services := &corev1.ServiceList{} | ||
Expect(k8sClient.List(context.Background(), services, client.MatchingLabels{ | ||
korifiv1alpha1.CFAppGUIDLabelKey: appGUID, | ||
})).To(Succeed()) | ||
Expect(services.Items).To(HaveLen(1)) | ||
|
||
appService := services.Items[0] | ||
return fmt.Sprintf("http://%s.%s:8080", appService.Name, appService.Namespace) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package broker | ||
|
||
import ( | ||
"context" | ||
|
||
korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1" | ||
. "github.com/onsi/ginkgo/v2" //lint:ignore ST1001 this is a test file | ||
. "github.com/onsi/gomega" //lint:ignore ST1001 this is a test file | ||
|
||
"k8s.io/client-go/kubernetes/scheme" | ||
controllerruntime "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type CatalogPurger struct { | ||
rootNamespace string | ||
catalogLabelSelector client.MatchingLabels | ||
} | ||
|
||
func NewCatalogPurger(rootNamespace string) *CatalogPurger { | ||
return &CatalogPurger{rootNamespace: rootNamespace} | ||
} | ||
|
||
func (p *CatalogPurger) ForBrokerGUID(brokerGUID string) *CatalogPurger { | ||
p.catalogLabelSelector = client.MatchingLabels{ | ||
korifiv1alpha1.RelServiceBrokerGUIDLabel: brokerGUID, | ||
} | ||
|
||
return p | ||
} | ||
|
||
func (p *CatalogPurger) ForBrokerName(brokerName string) *CatalogPurger { | ||
p.catalogLabelSelector = client.MatchingLabels{ | ||
korifiv1alpha1.RelServiceBrokerNameLabel: brokerName, | ||
} | ||
|
||
return p | ||
} | ||
|
||
func (p *CatalogPurger) Purge() { | ||
GinkgoHelper() | ||
|
||
ctx := context.Background() | ||
|
||
config, err := controllerruntime.GetConfig() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
k8sClient, err := client.New(config, client.Options{Scheme: scheme.Scheme}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
Expect(k8sClient.DeleteAllOf( | ||
ctx, | ||
&korifiv1alpha1.CFServiceOffering{}, | ||
client.InNamespace(p.rootNamespace), | ||
p.catalogLabelSelector, | ||
)).To(Succeed()) | ||
|
||
Expect(k8sClient.DeleteAllOf( | ||
ctx, | ||
&korifiv1alpha1.CFServicePlan{}, | ||
client.InNamespace(p.rootNamespace), | ||
p.catalogLabelSelector, | ||
)).To(Succeed()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package smoke_test | ||
|
||
import ( | ||
"strings" | ||
|
||
"code.cloudfoundry.org/korifi/tests/helpers" | ||
"code.cloudfoundry.org/korifi/tests/helpers/broker" | ||
|
||
"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() { | ||
var brokerName string | ||
|
||
BeforeEach(func() { | ||
brokerName = uuid.NewString() | ||
Expect(helpers.Cf( | ||
"create-service-broker", | ||
brokerName, | ||
"broker-user", | ||
"broker-password", | ||
helpers.GetInClusterURL(getAppGUID(brokerAppName)), | ||
)).To(Exit(0)) | ||
}) | ||
|
||
AfterEach(func() { | ||
cleanupBroker(brokerName) | ||
}) | ||
|
||
Describe("cf service-brokers", func() { | ||
It("lists service brokers", func() { | ||
session := helpers.Cf("service-brokers") | ||
Expect(session).To(Exit(0)) | ||
|
||
lines, _ := it.Collect2(it.LinesString(session.Out)) | ||
Expect(lines).To(ContainElement( | ||
matchSubstrings(brokerName, helpers.GetInClusterURL(getAppGUID(brokerAppName))))) | ||
}) | ||
}) | ||
|
||
Describe("cf delete-service-broker", func() { | ||
It("deletes the service broker", func() { | ||
session := helpers.Cf("delete-service-broker", "-f", brokerName) | ||
Expect(session).To(Exit(0)) | ||
|
||
session = helpers.Cf("service-brokers") | ||
Expect(session).To(Exit(0)) | ||
|
||
lines, _ := it.Collect2(it.LinesString(session.Out)) | ||
Expect(lines).NotTo(ContainElement(ContainSubstring(brokerName))) | ||
}) | ||
}) | ||
|
||
Describe("cf service-access", func() { | ||
It("lists service access settings", func() { | ||
session := helpers.Cf("service-access", "-b", brokerName) | ||
Expect(session).To(Exit(0)) | ||
|
||
lines, _ := it.Collect2(it.LinesString(session.Out)) | ||
Expect(lines).To(ContainElements( | ||
matchSubstrings("sample-service", "sample", "none"), | ||
)) | ||
}) | ||
}) | ||
|
||
Describe("cf enable-service-access", func() { | ||
It("enables the service access", func() { | ||
session := helpers.Cf("enable-service-access", "sample-service", "-b", brokerName) | ||
Expect(session).To(Exit(0)) | ||
|
||
session = helpers.Cf("service-access") | ||
Expect(session).To(Exit(0)) | ||
|
||
lines, _ := it.Collect2(it.LinesString(session.Out)) | ||
Expect(lines).To(ContainElements( | ||
matchSubstrings("sample-service", "sample", "all"), | ||
)) | ||
}) | ||
}) | ||
|
||
Describe("cf marketplace", func() { | ||
It("lists the service catalog", func() { | ||
session := helpers.Cf("marketplace", "-b", brokerName) | ||
Expect(session).To(Exit(0)) | ||
|
||
lines, _ := it.Collect2(it.LinesString(session.Out)) | ||
Expect(lines).To(ContainElement( | ||
matchSubstrings("sample-service", "A sample service that does nothing", brokerName), | ||
)) | ||
}) | ||
}) | ||
}) | ||
|
||
func getAppGUID(appName string) string { | ||
GinkgoHelper() | ||
|
||
session := helpers.Cf("app", appName, "--guid") | ||
Expect(session).To(Exit(0)) | ||
return string(session.Out.Contents()) | ||
} | ||
|
||
func cleanupBroker(brokerName string) { | ||
GinkgoHelper() | ||
|
||
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, ".*")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters