Skip to content

Commit

Permalink
Issue #615 - E2E tests - additional repo cleanup for package variants
Browse files Browse the repository at this point in the history
- tests now delete package variants whose upstream is a repo created by the test

nephio-project/nephio#615
  • Loading branch information
JamesMcDermott committed Jan 7, 2025
1 parent 1e5e34c commit ff91f1a
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions test/e2e/suite_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/google/go-cmp/cmp"
porchapi "github.com/nephio-project/porch/api/porch/v1alpha1"
configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1"
variantapi "github.com/nephio-project/porch/controllers/packagevariants/api/v1alpha1"
internalapi "github.com/nephio-project/porch/internal/api/porchinternal/v1alpha1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -218,8 +219,9 @@ func (t *TestSuite) registerGitRepositoryFromConfigF(ctx context.Context, name s

t.Cleanup(func() {
t.DeleteE(ctx, repository)
t.WaitUntilRepositoryDeleted(ctx, name, t.Namespace)
t.WaitUntilAllPackagesDeleted(ctx, name, t.Namespace)
t.DeleteVariantsForRepo(ctx, name)
t.WaitUntilRepositoryDeleted(ctx, name)
t.WaitUntilAllPackagesDeleted(ctx, name)
})

// Make sure the repository is ready before we test to (hopefully)
Expand Down Expand Up @@ -350,8 +352,41 @@ func (t *TestSuite) WaitUntilRepositoryReady(ctx context.Context, name, namespac
}
}

func (t *TestSuite) WaitUntilRepositoryDeleted(ctx context.Context, name, namespace string) {
func (t *TestSuite) DeleteVariantsForRepo(ctx context.Context, repoName string) {
t.Helper()
namespace := t.Namespace
var variantList variantapi.PackageVariantList
if err := t.Client.List(ctx, &variantList, client.InNamespace(namespace)); err != nil {
t.Errorf("error listing package variants: %v", err)
}
for _, variant := range variantList.Items {
if variant.Spec.Upstream.Repo == repoName {
t.DeleteE(ctx, &variant)
}
}

err := wait.PollUntilContextTimeout(ctx, time.Second, 60*time.Second, true, func(ctx context.Context) (done bool, err error) {
t.Helper()
if err := t.Client.List(ctx, &variantList, client.InNamespace(namespace)); err != nil {
t.Logf("error listing packages: %v", err)
return false, nil
}
for _, variant := range variantList.Items {
if variant.Spec.Upstream.Repo == repoName {
t.Logf("Found package variant %s using repo %s as upstream", variant.Name, repoName)
return false, nil
}
}
return true, nil
})
if err != nil {
t.Fatalf("Package variant(s) still remain using repo %s as upstream", repoName)
}
}

func (t *TestSuite) WaitUntilRepositoryDeleted(ctx context.Context, name string) {
t.Helper()
namespace := t.Namespace
err := wait.PollUntilContextTimeout(ctx, time.Second, 20*time.Second, true, func(ctx context.Context) (done bool, err error) {
var repo configapi.Repository
nn := types.NamespacedName{
Expand All @@ -371,8 +406,9 @@ func (t *TestSuite) WaitUntilRepositoryDeleted(ctx context.Context, name, namesp
}
}

func (t *TestSuite) WaitUntilAllPackagesDeleted(ctx context.Context, repoName string, namespace string) {
func (t *TestSuite) WaitUntilAllPackagesDeleted(ctx context.Context, repoName string) {
t.Helper()
namespace := t.Namespace
err := wait.PollUntilContextTimeout(ctx, time.Second, 60*time.Second, true, func(ctx context.Context) (done bool, err error) {
t.Helper()
var pkgRevList porchapi.PackageRevisionList
Expand Down Expand Up @@ -434,7 +470,7 @@ func (t *TestSuite) WaitUntilPackageRevisionFulfillingConditionExists(
var foundPkgRev *porchapi.PackageRevision
err := wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, func(ctx context.Context) (done bool, err error) {
var pkgRevList porchapi.PackageRevisionList
if err := t.Client.List(ctx, &pkgRevList); err != nil {
if err := t.Client.List(ctx, &pkgRevList, client.InNamespace(t.Namespace)); err != nil {
t.Logf("error listing packages: %v", err)
return false, nil
}
Expand Down

0 comments on commit ff91f1a

Please sign in to comment.