Skip to content

Commit

Permalink
test(packagemanifest): add fetch function for packagemanifests
Browse files Browse the repository at this point in the history
  • Loading branch information
njhale committed Sep 10, 2018
1 parent 16d2467 commit 7f25bfa
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions test/e2e/packagemanifest_e2e_test.go
Original file line number Diff line number Diff line change
@@ -7,12 +7,41 @@ import (
"github.com/stretchr/testify/require"
extv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
pmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/packagemanifest/v1alpha1"
pmversioned "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client/clientset/versioned"
)

type packageManifestCheckFunc func(*pmv1alpha1.PackageManifest) bool

func packageManifestHasStatus(pm *pmv1alpha1.PackageManifest) bool {
// as long as it has a package name we consider the status non-empty
if pm == nil || pm.Status.PackageName == "" {
return false
}

return true
}

func fetchPackageManifest(t *testing.T, pmc pmversioned.Interface, namespace, name string, check packageManifestCheckFunc) (*pmv1alpha1.PackageManifest, error) {
var fetched *pmv1alpha1.PackageManifest
var err error

err = wait.Poll(pollInterval, pollDuration, func() (bool, error) {
t.Logf("Polling...")
fetched, err = pmc.Packagemanifest().PackageManifests(namespace).Get(name, metav1.GetOptions{})
if err != nil {
return true, err
}
return check(fetched), nil
})

return fetched, err
}

func TestPackageManifestLoading(t *testing.T) {
// create a simple catalogsource
packageName := genName("nginx")
@@ -52,13 +81,12 @@ func TestPackageManifestLoading(t *testing.T) {
DefaultChannelName: stableChannel,
}

// TODO: Ensure catalog source is tracked by package server before checking
// get PackageManifest
pmc := newPMClient(t)
pm, err := pmc.Packagemanifest().PackageManifests(testNamespace).Get(packageName, metav1.GetOptions{})
pm, err := fetchPackageManifest(t, pmc, testNamespace, packageName, packageManifestHasStatus)

// check parsed PackageManifest
// check against expected
require.NoError(t, err, "error getting package manifest")
t.Logf("packagemanifest: %v", pm)
require.NotNil(t, pm)
require.Equal(t, packageName, pm.GetName())
require.Equal(t, expectedStatus, pm.Status)

0 comments on commit 7f25bfa

Please sign in to comment.