-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9e1d1d
commit 50bc865
Showing
4 changed files
with
417 additions
and
29 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,123 @@ | ||
/* | ||
Copyright 2023 Nutanix | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package controllers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
credentialTypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/cluster-api/util" | ||
|
||
infrav1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestControllerHelpers(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
_ = Describe("ControllerHelpers", func() { | ||
const ( | ||
fd1Name = "fd-1" | ||
fd2Name = "fd-2" | ||
) | ||
|
||
var ( | ||
ntnxCluster *infrav1.NutanixCluster | ||
ctx context.Context | ||
) | ||
|
||
BeforeEach(func() { | ||
ctx = context.Background() | ||
ntnxCluster = &infrav1.NutanixCluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test", | ||
Namespace: "default", | ||
}, | ||
Spec: infrav1.NutanixClusterSpec{ | ||
PrismCentral: &credentialTypes.NutanixPrismEndpoint{ | ||
// Adding port info to override default value (0) | ||
Port: 9440, | ||
}, | ||
}, | ||
} | ||
}) | ||
|
||
AfterEach(func() { | ||
err := k8sClient.Delete(ctx, ntnxCluster) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
Context("Get failure domains", func() { | ||
It("should error when passing empty failure domain name", func() { | ||
g.Expect(k8sClient.Create(ctx, ntnxCluster)).To(Succeed()) | ||
_, err := GetFailureDomain("", ntnxCluster) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
It("should error when passing nil cluster", func() { | ||
g.Expect(k8sClient.Create(ctx, ntnxCluster)).To(Succeed()) | ||
_, err := GetFailureDomain(fd1Name, nil) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
It("should error when no failure domain has been found", func() { | ||
g.Expect(k8sClient.Create(ctx, ntnxCluster)).To(Succeed()) | ||
_, err := GetFailureDomain(fd1Name, ntnxCluster) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
It("should return the correct failuredomain", func() { | ||
r := util.RandomString(10) | ||
fd1 := infrav1.NutanixFailureDomain{ | ||
Name: fd1Name, | ||
Cluster: infrav1.NutanixResourceIdentifier{ | ||
Type: infrav1.NutanixIdentifierName, | ||
Name: &r, | ||
}, | ||
Subnets: []infrav1.NutanixResourceIdentifier{ | ||
{ | ||
Type: infrav1.NutanixIdentifierName, | ||
Name: &r, | ||
}, | ||
}, | ||
} | ||
fd2 := infrav1.NutanixFailureDomain{ | ||
Name: fd2Name, | ||
Cluster: infrav1.NutanixResourceIdentifier{ | ||
Type: infrav1.NutanixIdentifierName, | ||
Name: &r, | ||
}, | ||
Subnets: []infrav1.NutanixResourceIdentifier{ | ||
{ | ||
Type: infrav1.NutanixIdentifierName, | ||
Name: &r, | ||
}, | ||
}, | ||
} | ||
ntnxCluster.Spec.FailureDomains = []infrav1.NutanixFailureDomain{ | ||
fd1, | ||
fd2, | ||
} | ||
g.Expect(k8sClient.Create(ctx, ntnxCluster)).To(Succeed()) | ||
fd, err := GetFailureDomain(fd2Name, ntnxCluster) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(*fd).To(Equal(fd2)) | ||
}) | ||
}) | ||
}) | ||
} |
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
Oops, something went wrong.