Skip to content

Commit

Permalink
Add deleteBastion envTest
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbooth committed Jul 1, 2022
1 parent 459bd00 commit b490b44
Showing 1 changed file with 28 additions and 42 deletions.
70 changes: 28 additions & 42 deletions controllers/openstackcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import (
"context"
"fmt"

"github.com/go-logr/logr"
"github.com/golang/mock/gomock"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -33,6 +36,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha6"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/clients"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/scope"
)

Expand Down Expand Up @@ -179,48 +183,30 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(result).To(Equal(reconcile.Result{}))
})

// TODO: This test is set to pending (PIt instead of It) since it is not working.
PIt("should be able to reconcile when basition disabled", func() {
// verify := false
// cloud := clientconfig.Cloud{
// Cloud: "test",
// RegionName: "test",
// Verify: &verify,
// AuthInfo: &clientconfig.AuthInfo{
// AuthURL: "https://example.com:5000",
// Username: "testuser",
// Password: "secret",
// ProjectName: "test",
// DomainName: "test",
// UserDomainName: "test",
// },
// }
// // TODO: Can we fake the client in some way?
// providerClient, clientOpts, _, err := provider.NewClient(cloud, nil)
// Expect(err).To(BeNil())
// scope := &scope.Scope{
// ProviderClient: providerClient,
// ProviderClientOpts: clientOpts,
// }

// TODO: This won't work without filling in proper values.
// scope := &scope.Scope{
// ProviderClient: &gophercloud.ProviderClient{},
// ProviderClientOpts: &clientconfig.ClientOpts{},
// }
// testCluster.SetName("no-bastion")
// testCluster.Spec = infrav1.OpenStackClusterSpec{
// Bastion: &infrav1.Bastion{
// Enabled: false,
// },
// }
// err := k8sClient.Create(ctx, testCluster)
// Expect(err).To(BeNil())
// err = k8sClient.Create(ctx, capiCluster)
// Expect(err).To(BeNil())
//
// err = deleteBastion(scope, capiCluster, testCluster)
// Expect(err).To(BeNil())
It("should be able to reconcile when basition is disabled and does not exist", func() {
testCluster.SetName("no-bastion")
testCluster.Spec = infrav1.OpenStackClusterSpec{
Bastion: &infrav1.Bastion{
Enabled: false,
},
}
err := k8sClient.Create(ctx, testCluster)
Expect(err).To(BeNil())
err = k8sClient.Create(ctx, capiCluster)
Expect(err).To(BeNil())
scope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, logr.Discard())
Expect(err).To(BeNil())

computeClientRecorder := mockScopeFactory.ComputeClient.EXPECT()
computeClientRecorder.ListServers(servers.ListOpts{
Name: "^capi-cluster-bastion$",
}).Return([]clients.ServerExt{}, nil)

networkClientRecorder := mockScopeFactory.NetworkClient.EXPECT()
networkClientRecorder.ListSecGroup(gomock.Any()).Return([]groups.SecGroup{}, nil)

err = deleteBastion(scope, capiCluster, testCluster)
Expect(err).To(BeNil())
})
})

Expand Down

0 comments on commit b490b44

Please sign in to comment.