mirror of
https://github.com/rancher/k3k.git
synced 2026-04-05 10:16:56 +00:00
* Refactor tests to their own directories (#723) * Move cli tests * Move e2e tests to their own directory * Move integration tests * Fix path within the cli tests * Move k3k-kubelet tests * Improve the various make test- options * Remove dead code from cli tests * Update development.md with the new make commands * Remove tests that didn't exist in v1.0
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"sync"
|
|
|
|
"k8s.io/utils/ptr"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
func NewNamespace() *v1.Namespace {
|
|
GinkgoHelper()
|
|
|
|
namespace := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{GenerateName: "ns-", Labels: map[string]string{"e2e": "true"}}}
|
|
namespace, err := k8s.CoreV1().Namespaces().Create(context.Background(), namespace, metav1.CreateOptions{})
|
|
Expect(err).To(Not(HaveOccurred()))
|
|
|
|
return namespace
|
|
}
|
|
|
|
func DeleteNamespaces(names ...string) {
|
|
GinkgoHelper()
|
|
|
|
if _, found := os.LookupEnv("KEEP_NAMESPACES"); found {
|
|
By(fmt.Sprintf("Keeping namespace %v", names))
|
|
return
|
|
}
|
|
|
|
wg := sync.WaitGroup{}
|
|
wg.Add(len(names))
|
|
|
|
for _, name := range names {
|
|
go func() {
|
|
defer wg.Done()
|
|
defer GinkgoRecover()
|
|
|
|
By(fmt.Sprintf("Deleting namespace %s", name))
|
|
|
|
err := k8s.CoreV1().Namespaces().Delete(context.Background(), name, metav1.DeleteOptions{
|
|
GracePeriodSeconds: ptr.To[int64](0),
|
|
})
|
|
Expect(client.IgnoreNotFound(err)).To(Not(HaveOccurred()))
|
|
}()
|
|
}
|
|
|
|
wg.Wait()
|
|
}
|