Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Sep 16, 2024
1 parent 366efdb commit ecca3e5
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions testdata/project-v4-multigroup/test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const metricsServiceName = "project-v4-multigroup-controller-manager-metrics-ser
const metricsRoleBindingName = "project-v4-multigroup-metrics-binding"

var _ = Describe("Manager", Ordered, func() {
var controllerPodName string

// Before running the tests, set up the environment by creating the namespace,
// installing CRDs, and deploying the controller.
BeforeAll(func() {
Expand Down Expand Up @@ -82,12 +84,51 @@ var _ = Describe("Manager", Ordered, func() {
_, _ = utils.Run(cmd)
})

AfterEach(func() {
specReport := CurrentSpecReport()
if specReport.Failed() {
By("Fetching controller manager pod logs")
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
controllerLogs, err := utils.Run(cmd)
if err == nil {
fmt.Println("Controller logs:\n", controllerLogs)
} else {
fmt.Println("Failed to get controller logs")
}

By("Fetching Kubernetes events")
cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp")
eventsOutput, err := utils.Run(cmd)
if err == nil {
fmt.Println("Kubernetes events:\n", eventsOutput)
} else {
fmt.Println("Failed to get Kubernetes events")
}

By("Fetching curl-metrics logs")
cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
metricsOutput, err := utils.Run(cmd)
if err == nil {
fmt.Println("Metrics logs:\n", metricsOutput)
} else {
fmt.Println("Failed to get curl-metrics logs")
}

By("Fetching controller manager pod description")
cmd = exec.Command("kubectl", "describe", "pod", controllerPodName, "-n", namespace)
podDescription, err := utils.Run(cmd)
if err == nil {
fmt.Println("Pod description:\n", podDescription)
} else {
fmt.Println("Failed to describe controller pod")
}
}
})

SetDefaultEventuallyTimeout(2 * time.Minute)
SetDefaultEventuallyPollingInterval(time.Second)

// The Context block contains the actual tests that validate the manager's behavior.
Context("Manager", func() {
var controllerPodName string
It("should run successfully", func() {
By("validating that the controller-manager pod is running as expected")
verifyControllerUp := func(g Gomega) {
Expand All @@ -108,7 +149,6 @@ var _ = Describe("Manager", Ordered, func() {
controllerPodName = podNames[0]
g.Expect(controllerPodName).To(ContainSubstring("controller-manager"))

// Validate the pod's status
cmd = exec.Command("kubectl", "get",
"pods", controllerPodName, "-o", "jsonpath={.status.phase}",
"-n", namespace,
Expand All @@ -117,7 +157,6 @@ var _ = Describe("Manager", Ordered, func() {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(string(output)).To(BeEquivalentTo("Running"), "Incorrect controller-manager pod status")
}
// Repeatedly check if the controller-manager pod is running until it succeeds or times out.
Eventually(verifyControllerUp).Should(Succeed())
})

Expand Down

0 comments on commit ecca3e5

Please sign in to comment.