@@ -53,3 +53,48 @@ func deleteTestNamespace(t Test, namespace *corev1.Namespace) {
53
53
})
54
54
t .Expect (err ).NotTo (gomega .HaveOccurred ())
55
55
}
56
+
57
+ func CreateTestNamespaceWithName (t Test , namespaceName string , options ... Option [* corev1.Namespace ]) * corev1.Namespace {
58
+ t .T ().Helper ()
59
+ namespace := & corev1.Namespace {
60
+ TypeMeta : metav1.TypeMeta {
61
+ APIVersion : corev1 .SchemeGroupVersion .String (),
62
+ Kind : "Namespace" ,
63
+ },
64
+ ObjectMeta : metav1.ObjectMeta {
65
+ Name : namespaceName ,
66
+ },
67
+ }
68
+
69
+ for _ , option := range options {
70
+ t .Expect (option .applyTo (namespace )).To (gomega .Succeed ())
71
+ }
72
+
73
+ namespace , err := t .Client ().Core ().CoreV1 ().Namespaces ().Create (t .Ctx (), namespace , metav1.CreateOptions {})
74
+ t .Expect (err ).NotTo (gomega .HaveOccurred ())
75
+
76
+ return namespace
77
+ }
78
+
79
+ func GetNamespaceWithName (t Test , namespaceName string ) * corev1.Namespace {
80
+ namespace , err := t .Client ().Core ().CoreV1 ().Namespaces ().Get (t .Ctx (), namespaceName , metav1.GetOptions {})
81
+ if err != nil {
82
+ t .T ().Errorf ("Failed to retrieve namespace with name %s: %v" , namespaceName , err )
83
+ }
84
+ return namespace
85
+ }
86
+
87
+ func DeleteTestNamespace (t Test , namespace * corev1.Namespace ) {
88
+ t .T ().Helper ()
89
+ propagationPolicy := metav1 .DeletePropagationBackground
90
+ StoreNamespaceLogs (t , namespace )
91
+ err := t .Client ().Core ().CoreV1 ().Namespaces ().Delete (t .Ctx (), namespace .Name , metav1.DeleteOptions {
92
+ PropagationPolicy : & propagationPolicy ,
93
+ })
94
+ t .Expect (err ).NotTo (gomega .HaveOccurred ())
95
+ }
96
+
97
+ func StoreNamespaceLogs (t Test , namespace * corev1.Namespace ) {
98
+ storeAllPodLogs (t , namespace )
99
+ storeEvents (t , namespace )
100
+ }
0 commit comments