Skip to content

Commit

Permalink
feat: consider working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Azhovan committed Oct 17, 2023
1 parent 8ea16fd commit e7e1bf8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 64 deletions.
8 changes: 4 additions & 4 deletions apptests/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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"))
}
63 changes: 3 additions & 60 deletions apptests/environment/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}

0 comments on commit e7e1bf8

Please sign in to comment.