mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
This PR adds e2e tests for the operator, following up #1539 (comment). This e2e testing enables to assert Kuberay resources, in a way that cannot be achieved with existing tests (envtest). The e2e tests execution output is post-processed using gotestfmt: The logs and events are gathered and uploaded are part of the workflow run:
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package support
|
|
|
|
import (
|
|
"github.com/onsi/gomega"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
func createTestNamespace(t Test, options ...Option[*corev1.Namespace]) *corev1.Namespace {
|
|
t.T().Helper()
|
|
namespace := &corev1.Namespace{
|
|
TypeMeta: metav1.TypeMeta{
|
|
APIVersion: corev1.SchemeGroupVersion.String(),
|
|
Kind: "Namespace",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
GenerateName: "test-ns-",
|
|
},
|
|
}
|
|
|
|
for _, option := range options {
|
|
t.Expect(option.applyTo(namespace)).To(gomega.Succeed())
|
|
}
|
|
|
|
namespace, err := t.Client().Core().CoreV1().Namespaces().Create(t.Ctx(), namespace, metav1.CreateOptions{})
|
|
t.Expect(err).NotTo(gomega.HaveOccurred())
|
|
|
|
return namespace
|
|
}
|
|
|
|
func deleteTestNamespace(t Test, namespace *corev1.Namespace) {
|
|
t.T().Helper()
|
|
propagationPolicy := metav1.DeletePropagationBackground
|
|
err := t.Client().Core().CoreV1().Namespaces().Delete(t.Ctx(), namespace.Name, metav1.DeleteOptions{
|
|
PropagationPolicy: &propagationPolicy,
|
|
})
|
|
t.Expect(err).NotTo(gomega.HaveOccurred())
|
|
}
|