Skip to content

Commit

Permalink
add updated helm-locker
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Lamarre <[email protected]>
  • Loading branch information
alexandreLamarre committed Dec 27, 2024
1 parent 85a3608 commit b504cc4
Show file tree
Hide file tree
Showing 42 changed files with 4,160 additions and 0 deletions.
85 changes: 85 additions & 0 deletions internal/helm-locker/e2e_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package main_test

import (
"context"
"errors"
"os"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
lockerv1alpha1 "github.com/rancher/helm-locker/pkg/apis/helm.cattle.io/v1alpha1"
"github.com/rancher/wrangler/v3/pkg/kubeconfig"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

env "github.com/caarlos0/env/v11"
"github.com/kralicky/kmatch"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

func TestE2e(t *testing.T) {
SetDefaultEventuallyTimeout(60 * time.Second)
SetDefaultEventuallyPollingInterval(50 * time.Millisecond)
SetDefaultConsistentlyDuration(5 * time.Second)
SetDefaultConsistentlyPollingInterval(50 * time.Millisecond)
RegisterFailHandler(Fail)
RunSpecs(t, "E2e Suite")
}

var (
k8sClient client.Client
cfg *rest.Config
testCtx context.Context
clientSet *kubernetes.Clientset
clientCmdCfg clientcmd.ClientConfig
)

type TestSpec struct {
Kubeconfig string `env:"KUBECONFIG,required"`
}

func (t *TestSpec) Validate() error {
var errs []error
if _, err := os.Stat(t.Kubeconfig); err != nil {
errs = append(errs, err)
}

if len(errs) > 0 {
return errors.Join(errs...)
}
return nil
}

var _ = BeforeSuite(func() {
ts := TestSpec{}
Expect(env.Parse(&ts)).To(Succeed(), "Could not parse test spec from environment variables")
Expect(ts.Validate()).To(Succeed(), "Invalid input e2e test spec")

ctxCa, ca := context.WithCancel(context.Background())
DeferCleanup(func() {
ca()
})
clientCmdCfg = kubeconfig.GetNonInteractiveClientConfig(ts.Kubeconfig)

testCtx = ctxCa
newCfg, err := config.GetConfig()
Expect(err).NotTo(HaveOccurred(), "Could not initialize kubernetes client config")
cfg = newCfg
newClientset, err := kubernetes.NewForConfig(cfg)
Expect(err).To(Succeed(), "Could not initialize kubernetes clientset")
clientSet = newClientset

newK8sClient, err := client.New(cfg, client.Options{})
Expect(err).NotTo(HaveOccurred(), "Could not initialize kubernetes client")
k8sClient = newK8sClient

lockerv1alpha1.AddToScheme(k8sClient.Scheme())
apiextensionsv1.AddToScheme(k8sClient.Scheme())
kmatch.SetDefaultObjectClient(k8sClient)
})
Loading

0 comments on commit b504cc4

Please sign in to comment.