From e7e1bf8f5b2cc7d6cb2cbcb1f26c3164a92ee24b Mon Sep 17 00:00:00 2001 From: Jabar Asadi Date: Tue, 17 Oct 2023 18:12:43 +0200 Subject: [PATCH] feat: consider working directory --- apptests/environment/environment.go | 8 +-- apptests/environment/environment_test.go | 63 ++---------------------- 2 files changed, 7 insertions(+), 64 deletions(-) diff --git a/apptests/environment/environment.go b/apptests/environment/environment.go index c2c49f6f5e..bd818a068e 100644 --- a/apptests/environment/environment.go +++ b/apptests/environment/environment.go @@ -51,7 +51,7 @@ type Env struct { func (e *Env) Provision(ctx context.Context) error { var err error - kustomizePath, err := AbsolutePathToBase() + kustomizePath, err := AbsolutePathToBase(".") if err != nil { return err } @@ -233,7 +233,7 @@ func (e *Env) ApplyKustomizations(ctx context.Context, path string, substitution return nil } -// AbsolutePathToBase returns the absolute path to common/base directory. -func AbsolutePathToBase() (string, error) { - return filepath.Abs("../../common/base") +// AbsolutePathToBase returns the absolute path to common/base directory from the given working directory. +func AbsolutePathToBase(workingDRI string) (string, error) { + return filepath.Abs(filepath.Join(workingDRI, "common/base")) } diff --git a/apptests/environment/environment_test.go b/apptests/environment/environment_test.go index 35ebafea45..3e6d924631 100644 --- a/apptests/environment/environment_test.go +++ b/apptests/environment/environment_test.go @@ -2,18 +2,12 @@ package environment import ( "context" - "fmt" "testing" - "time" "github.com/fluxcd/flux2/v2/pkg/manifestgen" - sourcev1beta2 "github.com/fluxcd/source-controller/api/v1beta2" - "github.com/mesosphere/kommander-applications/apptests/flux" "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/util/wait" - genericCLient "sigs.k8s.io/controller-runtime/pkg/client" ) func TestProvision(t *testing.T) { @@ -49,59 +43,8 @@ func TestProvision(t *testing.T) { } } -func TestApplyKustomizations(t *testing.T) { - ctx := context.Background() - env := Env{} - - // set the kustomizePath to common/base directory - kustomizePath, err := AbsolutePathToBase() - assert.NoError(t, err) - fmt.Println(kustomizePath) - - // create a kind cluster and install fluxcd on it - cluster, k8sClient, err := provisionEnv(ctx) - assert.NoError(t, err) - defer env.Destroy(ctx) - - env.SetK8sClient(k8sClient) - env.SetCluster(cluster) - - // apply common/base kustomizations - err = env.ApplyKustomizations(ctx, kustomizePath, nil) - assert.NoError(t, err) - - // assert that following HelmRepository (as an example) is created - hr := &sourcev1beta2.HelmRepository{ - TypeMeta: metav1.TypeMeta{ - Kind: "source.toolkit.fluxcd.io", - APIVersion: "v1beta2", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "vmware-tanzu.github.io", - Namespace: kommanderFluxNamespace, - }, - } - - client, err := genericCLient.New(env.K8sClient.Config(), genericCLient.Options{Scheme: flux.NewScheme()}) - assert.NoError(t, err) - - // set timeout on the context - ctx, cancel := context.WithTimeout(ctx, 5*time.Minute) - defer cancel() - - // assert that eventually helmRelease object is reconciled - err = wait.PollUntilContextCancel(ctx, pollInterval, true, func(ctx context.Context) (done bool, err error) { - err = client.Get(ctx, genericCLient.ObjectKeyFromObject(hr), hr) - if err != nil { - return false, err - } - for _, cond := range hr.Status.Conditions { - if cond.Status == metav1.ConditionTrue { - return true, nil - } - } - return false, nil - }) +func TestAbsolutePathToBase(t *testing.T) { + s, err := AbsolutePathToBase("../..") assert.NoError(t, err) - assert.NotNil(t, hr) + assert.Contains(t, s, "/kommander-applications/common/base") }