Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
Shared fuse tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sedroche committed Nov 22, 2018
1 parent 9e50714 commit ec3f80e
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/managedServicesBroker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
testapi "github.com/integr8ly/managed-service-broker/tests/apis"
brokerClient "github.com/integr8ly/managed-service-broker/tests/broker_client"
"github.com/integr8ly/managed-service-broker/tests/test_suites/broker"
"github.com/integr8ly/managed-service-broker/tests/test_suites/fuse"
"os"
"testing"
"time"
)

// https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#originating-identity
Expand Down Expand Up @@ -85,4 +87,16 @@ func TestManagedBroker(t *testing.T) {
for _, svc := range sc.Services {
broker.OperationsSuite(t, &testapi.TestCase{svc, TEST_NAMESPACE, true}, cCfg)
}

// Wait for cluster to clean up before continuing
time.Sleep(time.Second * 5)

// Shared fuse tests
if os.Getenv("MANAGED_SERVICE_NAMESPACE") == "true" {
for _, svc := range sc.Services {
if svc.Name == fuse.FUSE_NAME {
fuse.SharedServiceSuite(t, &testapi.TestCase{svc, TEST_NAMESPACE, true}, cCfg)
}
}
}
}
23 changes: 23 additions & 0 deletions tests/test_suites/fuse/managed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fuse

import (
testapi "github.com/integr8ly/managed-service-broker/tests/apis"
brokerClient "github.com/integr8ly/managed-service-broker/tests/broker_client"
"testing"
)

const (
FUSE_NAME = "fuse"
MANAGED_SERVICE_PROJECT = "managed-service-project"
)

func SharedServiceSuite(t *testing.T, tc *testapi.TestCase, cCfg *brokerClient.BrokerClientClientConfig) {
if tc.Service.Name != FUSE_NAME {
t.Fatal("This test suite is for fuse only")
}

sbc := brokerClient.NewServiceBrokerClient(cCfg)
for _, p := range tc.Service.Plans {
TestSharedFuse(t, tc, &p, MANAGED_SERVICE_PROJECT, sbc)
}
}
84 changes: 84 additions & 0 deletions tests/test_suites/fuse/tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package fuse

import (
"fmt"
integreatly "github.com/integr8ly/managed-service-broker/pkg/apis/integreatly/v1alpha1"
sndv1alpha1 "github.com/integr8ly/managed-service-broker/pkg/deploys/fuse/pkg/apis/syndesis/v1alpha1"
testapi "github.com/integr8ly/managed-service-broker/tests/apis"
brokerClient "github.com/integr8ly/managed-service-broker/tests/broker_client"
"github.com/operator-framework/operator-sdk/pkg/sdk"
"testing"
)

func TestSharedFuse(t *testing.T, tc *testapi.TestCase, svcp *brokerClient.ServicePlan, managedNamespace string, sbc *brokerClient.ServiceBrokerClient) {
svc1 := "fuse1"
svc2 := "fuse2"
svc1SliceAnnotation := integreatly.SLICE_ANNOTATION + svc1

_, csiRes1, err := sbc.CreateServiceInstance(tc.Namespace, svc1, tc.Service.ID, svcp.ID, tc.Async)
if err != nil {
t.Fatal(fmt.Sprintf("Unexpected error creating %s", svc1), err.Description)
}
// We need to wait for first Provision to succeed as the resource is being updated and makes any following updates fail on occasion.
sbc.PollLastOperation(svc1, tc.Service, svcp, csiRes1.Operation)

_, csiRes2, err := sbc.CreateServiceInstance(tc.Namespace, svc2, tc.Service.ID, svcp.ID, tc.Async)
if err != nil {
t.Fatal(fmt.Sprintf("Unexpected error creating %s", svc2), err.Description)
}

if csiRes1.DashboardURL != csiRes2.DashboardURL {
t.Fatal("Dashboard URLs were not the same")
}

// Assert that one custom resource exists in the Managed Namespace and it has the correct 2 annotations
fL := getFuseList(managedNamespace)
expectedNumFuseCustomResources := 1
if len(fL.Items) != expectedNumFuseCustomResources {
t.Fatal("There should be one fuse custom resource")
}
f := fL.Items[0]
expectedAnnotations := []string{svc1SliceAnnotation, integreatly.SLICE_ANNOTATION + svc2}
for _, v := range expectedAnnotations {
_, ok := f.Annotations[v]
if !ok {
t.Fatal(fmt.Sprintf("There should be an annotation of %s on the fuse custom resource", v))
}
}

_, dRes1, err := sbc.DeleteServiceInstance(svc1, tc.Service.ID, svcp.ID, tc.Async)
if err != nil {
t.Fatal(fmt.Sprintf("An error has occured deleting service instance %s", svc1), err.Description)
}
sbc.PollLastOperation(svc1, tc.Service, svcp, dRes1.Operation)

// Assert that custom resource still exists and now has only 1 annotation
fL2 := sndv1alpha1.NewSyndesisList()
sdk.List(managedNamespace, fL2)
if len(fL2.Items) != expectedNumFuseCustomResources {
t.Fatal("There should be one fuse custom resource")
}
f = fL2.Items[0]
_, ok := f.Annotations[svc1SliceAnnotation]
if ok {
t.Fatal(fmt.Sprintf("The annotation %s should be removed from the fuse custom resource", svc1SliceAnnotation))
}

_, dRes2, err := sbc.DeleteServiceInstance(svc2, tc.Service.ID, svcp.ID, tc.Async)
if err != nil {
t.Fatal(fmt.Sprintf("An error has occured deleting service instance %s", svc2), err.Description)
}
sbc.PollLastOperation(svc2, tc.Service, svcp, dRes2.Operation)

// Assert that custom resource is deleted
fl3 := getFuseList(managedNamespace)
if len(fl3.Items) != 0 {
t.Fatal("The fuse custom resource should be deleted")
}
}

func getFuseList(ns string) *sndv1alpha1.SyndesisList {
fL := sndv1alpha1.NewSyndesisList()
sdk.List(ns, fL)
return fL
}

0 comments on commit ec3f80e

Please sign in to comment.