Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/controller/bucket_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import (
const EnvGcpStorageHost = "STORAGE_EMULATOR_HOST"

func TestBucketReconciler_deleteBeforeFinalizer(t *testing.T) {
testStorage := newTestStorageForTest(t)

g := NewWithT(t)

namespaceName := "bucket-" + randStringRunes(5)
Expand Down Expand Up @@ -196,6 +198,8 @@ func TestBucketReconciler_Reconcile(t *testing.T) {
}

func TestBucketReconciler_reconcileStorage(t *testing.T) {
testStorage := newTestStorageForTest(t)

tests := []struct {
name string
beforeFunc func(obj *sourcev1.Bucket, storage *storage.Storage) error
Expand Down Expand Up @@ -433,6 +437,8 @@ func TestBucketReconciler_reconcileStorage(t *testing.T) {
}

func TestBucketReconciler_reconcileSource_generic(t *testing.T) {
testStorage := newTestStorageForTest(t)

tests := []struct {
name string
bucketName string
Expand Down Expand Up @@ -1002,6 +1008,8 @@ const gcsExternalAccountConfig = `{
}`

func TestBucketReconciler_reconcileSource_gcs(t *testing.T) {
testStorage := newTestStorageForTest(t)

tests := []struct {
name string
bucketName string
Expand Down Expand Up @@ -1512,6 +1520,8 @@ func TestBucketReconciler_reconcileSource_gcs(t *testing.T) {
}

func TestBucketReconciler_reconcileArtifact(t *testing.T) {
testStorage := newTestStorageForTest(t)

tests := []struct {
name string
beforeFunc func(t *WithT, obj *sourcev1.Bucket, index *index.Digester, dir string)
Expand Down
16 changes: 16 additions & 0 deletions internal/controller/gitrepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ KXi2P5xm89dQni0kTeAAY=
)

func TestGitRepositoryReconciler_deleteBeforeFinalizer(t *testing.T) {
testStorage := newTestStorageForTest(t)

g := NewWithT(t)

namespaceName := "gitrepo-" + randStringRunes(5)
Expand Down Expand Up @@ -318,6 +320,8 @@ func TestGitRepositoryReconciler_Reconcile(t *testing.T) {
}

func TestGitRepositoryReconciler_reconcileSource_emptyRepository(t *testing.T) {
testStorage := newTestStorageForTest(t)

g := NewWithT(t)

server, err := gittestserver.NewTempGitServer()
Expand Down Expand Up @@ -370,6 +374,8 @@ func TestGitRepositoryReconciler_reconcileSource_emptyRepository(t *testing.T) {
}

func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
testStorage := newTestStorageForTest(t)

type options struct {
username string
password string
Expand Down Expand Up @@ -1115,6 +1121,8 @@ func TestGitRepositoryReconciler_getAuthOpts_provider(t *testing.T) {
}

func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T) {
testStorage := newTestStorageForTest(t)

g := NewWithT(t)

branches := []string{"staging"}
Expand Down Expand Up @@ -1365,6 +1373,8 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
}

func TestGitRepositoryReconciler_reconcileArtifact(t *testing.T) {
testStorage := newTestStorageForTest(t)

tests := []struct {
name string
dir string
Expand Down Expand Up @@ -1730,6 +1740,8 @@ func TestGitRepositoryReconciler_reconcileInclude(t *testing.T) {
}

func TestGitRepositoryReconciler_reconcileStorage(t *testing.T) {
testStorage := newTestStorageForTest(t)

tests := []struct {
name string
beforeFunc func(obj *sourcev1.GitRepository, storage *storage.Storage) error
Expand Down Expand Up @@ -1968,6 +1980,8 @@ func TestGitRepositoryReconciler_reconcileStorage(t *testing.T) {
}

func TestGitRepositoryReconciler_reconcileDelete(t *testing.T) {
testStorage := newTestStorageForTest(t)

g := NewWithT(t)

r := &GitRepositoryReconciler{
Expand Down Expand Up @@ -2797,6 +2811,8 @@ func TestGitRepositoryReconciler_verifySignature(t *testing.T) {
}

func TestGitRepositoryReconciler_ConditionsUpdate(t *testing.T) {
testStorage := newTestStorageForTest(t)

g := NewWithT(t)

server, err := gittestserver.NewTempGitServer()
Expand Down
52 changes: 34 additions & 18 deletions internal/controller/helmchart_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ import (
)

func TestHelmChartReconciler_deleteBeforeFinalizer(t *testing.T) {
testStorage := newTestStorageForTest(t)

g := NewWithT(t)

namespaceName := "helmchart-" + randStringRunes(5)
Expand Down Expand Up @@ -333,6 +335,8 @@ func TestHelmChartReconciler_Reconcile(t *testing.T) {
}

func TestHelmChartReconciler_reconcileStorage(t *testing.T) {
testStorage := newTestStorageForTest(t)

tests := []struct {
name string
beforeFunc func(obj *sourcev1.HelmChart, storage *storage.Storage) error
Expand Down Expand Up @@ -875,7 +879,7 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
beforeFunc func(obj *sourcev1.HelmChart, repository *sourcev1.HelmRepository)
want sreconcile.Result
wantErr error
assertFunc func(g *WithT, obj *sourcev1.HelmChart, build chart.Build)
assertFunc func(g *WithT, obj *sourcev1.HelmChart, build chart.Build, testStorage *storage.Storage)
cleanFunc func(g *WithT, build *chart.Build)
}{
{
Expand All @@ -884,7 +888,7 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
obj.Spec.Chart = "helmchart"
},
want: sreconcile.ResultSuccess,
assertFunc: func(g *WithT, _ *sourcev1.HelmChart, build chart.Build) {
assertFunc: func(g *WithT, _ *sourcev1.HelmChart, build chart.Build, _ *storage.Storage) {
g.Expect(build.Name).To(Equal(chartName))
g.Expect(build.Version).To(Equal(higherChartVersion))
g.Expect(build.Path).ToNot(BeEmpty())
Expand Down Expand Up @@ -915,7 +919,7 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
repository.Spec.SecretRef = &meta.LocalObjectReference{Name: "auth"}
},
want: sreconcile.ResultSuccess,
assertFunc: func(g *WithT, _ *sourcev1.HelmChart, build chart.Build) {
assertFunc: func(g *WithT, _ *sourcev1.HelmChart, build chart.Build, _ *storage.Storage) {
g.Expect(build.Name).To(Equal(chartName))
g.Expect(build.Version).To(Equal(chartVersion))
g.Expect(build.Path).ToNot(BeEmpty())
Expand All @@ -933,10 +937,10 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
obj.Status.Artifact = &meta.Artifact{Path: chartName + "-" + chartVersion + ".tgz"}
},
want: sreconcile.ResultSuccess,
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build) {
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build, testStorage *storage.Storage) {
g.Expect(build.Name).To(Equal(chartName))
g.Expect(build.Version).To(Equal(chartVersion))
g.Expect(build.Path).To(Equal(filepath.Join(serverFactory.Root(), obj.Status.Artifact.Path)))
g.Expect(build.Path).To(Equal(testStorage.LocalPath(*obj.Status.Artifact)))
g.Expect(build.Path).To(BeARegularFile())
},
},
Expand All @@ -949,10 +953,10 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
obj.Status.ObservedValuesFiles = []string{"values.yaml", "override.yaml"}
},
want: sreconcile.ResultSuccess,
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build) {
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build, testStorage *storage.Storage) {
g.Expect(build.Name).To(Equal(chartName))
g.Expect(build.Version).To(Equal(chartVersion))
g.Expect(build.Path).To(Equal(filepath.Join(serverFactory.Root(), obj.Status.Artifact.Path)))
g.Expect(build.Path).To(Equal(testStorage.LocalPath(*obj.Status.Artifact)))
g.Expect(build.Path).To(BeARegularFile())
g.Expect(build.ValuesFiles).To(Equal([]string{"values.yaml", "override.yaml"}))
},
Expand All @@ -965,7 +969,7 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
obj.Spec.ValuesFiles = []string{"values.yaml", "override.yaml"}
},
want: sreconcile.ResultSuccess,
assertFunc: func(g *WithT, _ *sourcev1.HelmChart, build chart.Build) {
assertFunc: func(g *WithT, _ *sourcev1.HelmChart, build chart.Build, _ *storage.Storage) {
g.Expect(build.Name).To(Equal(chartName))
g.Expect(build.Version).To(Equal(higherChartVersion + "+3"))
g.Expect(build.Path).ToNot(BeEmpty())
Expand Down Expand Up @@ -993,7 +997,7 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
obj.Spec.IgnoreMissingValuesFiles = true
},
want: sreconcile.ResultSuccess,
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build) {
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build, _ *storage.Storage) {
g.Expect(build.Name).To(Equal(chartName))
g.Expect(build.Version).To(Equal(chartVersion + "+0"))
g.Expect(build.ValuesFiles).To(BeEmpty())
Expand All @@ -1011,7 +1015,7 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
obj.Spec.IgnoreMissingValuesFiles = true
},
want: sreconcile.ResultSuccess,
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build) {
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build, _ *storage.Storage) {
g.Expect(build.Name).To(Equal(chartName))
g.Expect(build.Version).To(Equal(chartVersion + "+0"))
g.Expect(build.ValuesFiles).To(Equal([]string{"values.yaml", "override.yaml"}))
Expand All @@ -1031,10 +1035,10 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
obj.Status.Artifact = &meta.Artifact{Path: chartName + "-" + chartVersion + ".tgz"}
},
want: sreconcile.ResultSuccess,
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build) {
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build, testStorage *storage.Storage) {
g.Expect(build.Name).To(Equal(chartName))
g.Expect(build.Version).To(Equal(chartVersion))
g.Expect(build.Path).ToNot(Equal(filepath.Join(serverFactory.Root(), obj.Status.Artifact.Path)))
g.Expect(build.Path).ToNot(Equal(testStorage.LocalPath(*obj.Status.Artifact)))
g.Expect(build.Path).To(BeARegularFile())
},
cleanFunc: func(g *WithT, build *chart.Build) {
Expand All @@ -1050,7 +1054,7 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
},
want: sreconcile.ResultEmpty,
wantErr: &serror.Generic{Err: errors.New("failed to get authentication secret '/invalid': secrets \"invalid\" not found")},
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build) {
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build, _ *storage.Storage) {
g.Expect(build.Complete()).To(BeFalse())

g.Expect(obj.Status.Conditions).To(conditions.MatchConditions([]metav1.Condition{
Expand All @@ -1065,7 +1069,7 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
},
want: sreconcile.ResultEmpty,
wantErr: &serror.Stalling{Err: errors.New("scheme \"file\" not supported")},
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build) {
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build, _ *storage.Storage) {
g.Expect(build.Complete()).To(BeFalse())

g.Expect(obj.Status.Conditions).To(conditions.MatchConditions([]metav1.Condition{
Expand All @@ -1080,7 +1084,7 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
},
want: sreconcile.ResultEmpty,
wantErr: &serror.Stalling{Err: errors.New("missing protocol scheme")},
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build) {
assertFunc: func(g *WithT, obj *sourcev1.HelmChart, build chart.Build, _ *storage.Storage) {
g.Expect(build.Complete()).To(BeFalse())

g.Expect(obj.Status.Conditions).To(conditions.MatchConditions([]metav1.Condition{
Expand Down Expand Up @@ -1126,8 +1130,7 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
clientBuilder.WithObjects(tt.secret.DeepCopy())
}

testStorage, err := newTestStorage(server)
g.Expect(err).ToNot(HaveOccurred())
testStorage := newTestStorageForTest(t)

r := &HelmChartReconciler{
Client: clientBuilder.Build(),
Expand Down Expand Up @@ -1162,6 +1165,11 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
if tt.beforeFunc != nil {
tt.beforeFunc(obj, repository)
}
if obj.Status.Artifact != nil {
artifact, err := os.ReadFile(filepath.Join(serverFactory.Root(), obj.Status.Artifact.Path))
g.Expect(err).NotTo(HaveOccurred())
g.Expect(os.WriteFile(testStorage.LocalPath(*obj.Status.Artifact), artifact, 0o600)).To(Succeed())
}

var b chart.Build
if tt.cleanFunc != nil {
Expand All @@ -1177,7 +1185,7 @@ func TestHelmChartReconciler_buildFromHelmRepository(t *testing.T) {
g.Expect(got).To(Equal(tt.want))

if tt.assertFunc != nil {
tt.assertFunc(g, obj, b)
tt.assertFunc(g, obj, b, testStorage)
}
})
}
Expand Down Expand Up @@ -1668,6 +1676,8 @@ func TestHelmChartReconciler_buildFromTarballArtifact(t *testing.T) {
}

func TestHelmChartReconciler_reconcileArtifact(t *testing.T) {
testStorage := newTestStorageForTest(t)

tests := []struct {
name string
build *chart.Build
Expand Down Expand Up @@ -2025,6 +2035,8 @@ func TestHelmChartReconciler_getSource(t *testing.T) {
}

func TestHelmChartReconciler_reconcileDelete(t *testing.T) {
testStorage := newTestStorageForTest(t)

g := NewWithT(t)

r := &HelmChartReconciler{
Expand Down Expand Up @@ -2768,6 +2780,8 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_authStrategy(t *testing.T) {
}

func TestHelmChartRepository_reconcileSource_verifyOCISourceSignature_keyless(t *testing.T) {
testStorage := newTestStorageForTest(t)

tests := []struct {
name string
version string
Expand Down Expand Up @@ -2944,6 +2958,8 @@ func TestHelmChartRepository_reconcileSource_verifyOCISourceSignature_keyless(t
}

func TestHelmChartReconciler_reconcileSourceFromOCI_verifySignatureNotation(t *testing.T) {
testStorage := newTestStorageForTest(t)

g := NewWithT(t)

tmpDir := t.TempDir()
Expand Down
8 changes: 8 additions & 0 deletions internal/controller/helmrepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ import (
)

func TestHelmRepositoryReconciler_deleteBeforeFinalizer(t *testing.T) {
testStorage := newTestStorageForTest(t)

g := NewWithT(t)

namespaceName := "helmrepo-" + randStringRunes(5)
Expand Down Expand Up @@ -171,6 +173,8 @@ func TestHelmRepositoryReconciler_Reconcile(t *testing.T) {
}

func TestHelmRepositoryReconciler_reconcileStorage(t *testing.T) {
testStorage := newTestStorageForTest(t)

tests := []struct {
name string
beforeFunc func(obj *sourcev1.HelmRepository, storage *storage.Storage) error
Expand Down Expand Up @@ -405,6 +409,8 @@ func TestHelmRepositoryReconciler_reconcileStorage(t *testing.T) {
}

func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
testStorage := newTestStorageForTest(t)

type options struct {
username string
password string
Expand Down Expand Up @@ -1073,6 +1079,8 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
}

func TestHelmRepositoryReconciler_reconcileArtifact(t *testing.T) {
testStorage := newTestStorageForTest(t)

tests := []struct {
name string
cache *cache.Cache
Expand Down
Loading