Skip to content

Convert package manifest e2e to ginkgo test #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

harishsurf
Copy link
Contributor

@harishsurf harishsurf commented Apr 13, 2020

Description of the change:
This change converts packagemanifest_e2e_test.go to leverage ginkgo's BDD approach.
The change also involves adding GinkgoRecover wherever go routines are called

Motivation for the change:

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /docs
  • Commit messages sensible and descriptive

@@ -242,10 +242,10 @@ var _ = Describe("Catalog", func() {
}

// Create the initial catalogsource
createInternalCatalogSource(GinkgoT(), c, crc, mainCatalogName, testNamespace, mainManifests, nil, []v1alpha1.ClusterServiceVersion{mainCSV})
createInternalCatalogSource(c, crc, mainCatalogName, testNamespace, mainManifests, nil, []v1alpha1.ClusterServiceVersion{mainCSV})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method uses deprecated internal catalog source type. I was thinking of rewriting this method to use configMap catalog source type as a separate PR. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is a great idea.

_, ok := expectedRelatedImages[v]
require.True(GinkgoT(), ok, "Expect this image %s to exist in the related images list\n", v)
}
Context("Given an operator-registry image", func() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a 100% sure, if the Context wording is accurate. I felt a second look at it would be good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until we update this test to build its own registry image during the test run, it makes more sense to me to merge the
"CatalogSource created..." context into this and leave the image reference string as an implementation detail.

@harishsurf harishsurf force-pushed the pkg-msft-e2e branch 2 times, most recently from c344a25 to 3c06da0 Compare April 21, 2020 16:26
@harishsurf
Copy link
Contributor Author

/retest

require.NoError(t, extScheme.AddToScheme(scheme))
require.NoError(t, k8sscheme.AddToScheme(scheme))
require.NoError(t, v1beta1.AddToScheme(scheme))
err := extScheme.AddToScheme(scheme)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A slightly more gomega-forward way of writing this might be Expect(extScheme.AddToScheme(scheme)).To(Succeed()).

https://godoc.org/github.com/onsi/gomega#Succeed

relatedImages := pm.Status.Channels[0].CurrentCSVDesc.RelatedImages
Expect(len(relatedImages)).To(Equal(len(expectedRelatedImages)))

for _, v := range relatedImages {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be:

Expect(relatedImages).To(ConsistOf([]string{
  "quay.io/coreos/etcd@sha256:3816b6daf9b66d6ced6f0f966314e2d4f894982c6b1493061502f8c2bf86ac84",
  "quay.io/coreos/etcd@sha256:49d3d4a81e0d030d3f689e7167f23e120abf955f7d08dbedf3ea246485acee9f",
  "quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2"
}))

which would cover this for loop as well as the length assertion on L187.

return false, nil
Context("Given a ConfigMap containing package manifest, CSV and CRD", func() {
When("A CatalogSource is created using the ConfigMap as catalog source type", func() {
It("Package manifest loading can be verified", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec descriptions need to state the behavior that is being verified!

csvJSON, _ := json.Marshal(csv)

// Wait for package-server to be ready
err := wait.Poll(pollInterval, 1*time.Minute, func() (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this use Eventually?

csv := newCSV(packageStable, testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{crd}, nil, namedStrategy)
csv.SetLabels(map[string]string{"projected": "label"})
csv.Spec.NativeAPIs = []metav1.GroupVersionKind{{Group: "kubenative.io", Version: "v1", Kind: "Native"}}
csvJSON, _ := json.Marshal(csv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure this isn't new, but the test shouldn't be ignoring the error value returned from Marshal. A nice thing to add (in a separate PR) would be automation for running static analysis tools like errcheck on every change.

return true, nil
}
return false, nil
Context("Given a ConfigMap containing package manifest, CSV and CRD", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ConfigMap mentioned in the container description should be created as part of this container (in a BeforeEach).

Edit: I have the same comment with a few other container nodes, please take a look at those.

_, err = fetchCatalogSource(crc, catalogSourceName, testNamespace, catalogSourceRegistryPodSynced)
Expect(err).ToNot(HaveOccurred())

By("querying the package manifest using the package name", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's clearer not to pass the option function to By, to reduce nesting and avoid giving the impression of a new container node. The only use case I can imagine for the optional function argument would be calling a named function that was used in multiple specs.

}
Context("Given an operator-registry image", func() {
Context("When a CatalogSource is created using gRPC catalog source type", func() {
When("Package manifest is available", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be clearer to change the test from:

  1. poll until list package manifests returns without error
  2. require that get catalog source returns without error
  3. poll until get package manifest returns without error

to:

  1. poll until get package manifest returns without error

It seems to me that we're checking for multiple related conditions, when a failure in any one of them would imply a failure of the primary test condition.

_, ok := expectedRelatedImages[v]
require.True(GinkgoT(), ok, "Expect this image %s to exist in the related images list\n", v)
}
Context("Given an operator-registry image", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until we update this test to build its own registry image during the test run, it makes more sense to me to merge the
"CatalogSource created..." context into this and leave the image reference string as an implementation detail.

Copy link
Member

@Bowenislandsong Bowenislandsong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIce work! Just added some nits.

@@ -242,10 +242,10 @@ var _ = Describe("Catalog", func() {
}

// Create the initial catalogsource
createInternalCatalogSource(GinkgoT(), c, crc, mainCatalogName, testNamespace, mainManifests, nil, []v1alpha1.ClusterServiceVersion{mainCSV})
createInternalCatalogSource(c, crc, mainCatalogName, testNamespace, mainManifests, nil, []v1alpha1.ClusterServiceVersion{mainCSV})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is a great idea.

@@ -3,170 +3,196 @@ package e2e
import (
"context"
"encoding/json"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: dont need new line

},
}
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: these need to be in the second group of imports

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 24, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 28, 2020
"quay.io/coreos/etcd@sha256:49d3d4a81e0d030d3f689e7167f23e120abf955f7d08dbedf3ea246485acee9f": "",
"quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": "",
}
It("lists the CatalogSource contents using the PackageManifest API", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this two specs in one ("packagemanifest can be retrieved by name" and "packagemanifest appears in list")? If yes, I think the second one is underspecified -- it would pass if Items is an empty slice or if it contained a packagemanifest other than the expected one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split them into two It specs

require.NoError(GinkgoT(), err, "error getting package manifest")
require.NotNil(GinkgoT(), pm)
require.Equal(GinkgoT(), packageName, pm.GetName())
It("lists the CatalogSource contents using the PackageManifest API", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this precisely stating the behavior the test is intended to verify? It looks like a relatedImages test.

@harishsurf harishsurf force-pushed the pkg-msft-e2e branch 3 times, most recently from bddb339 to f627979 Compare May 5, 2020 16:51
@exdx
Copy link
Member

exdx commented May 6, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 6, 2020
@exdx
Copy link
Member

exdx commented May 6, 2020

/test e2e-aws-olm

@Bowenislandsong
Copy link
Member

/lgtm

fetched, err = pmc.OperatorsV1().PackageManifests(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil && !errors.IsNotFound(err) {
return true, err
}
return check(fetched), nil
})
}).Should(BeTrue())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an opportunity here to define custom matchers, which would make the output of test failures more useful. I don't think it needs to block this PR, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I'll look into this and follow it up with another PR

func containsPackageManifest(pmList []packagev1.PackageManifest, pkgName string) bool {
for _, pm := range pmList {
if pm.GetName() == pkgName {
fmt.Printf("$$$ %v\n", pm.GetName())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this left in by mistake?

func containsPackageManifest(pmList []packagev1.PackageManifest, pkgName string) bool {
for _, pm := range pmList {
if pm.GetName() == pkgName {
fmt.Printf("$$$ %v\n", pm.GetName())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this left in by mistake?


return fetched, err
}

func containsPackageManifest(pmList []packagev1.PackageManifest, pkgName string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be expressed by composing the ContainsElement and WithTransform matchers. I suspect this is a common pattern in the tests, so maybe that's something to come back to in the future when considering reusable matchers/fixtures.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label May 7, 2020
@harishsurf
Copy link
Contributor Author

/retest

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

14 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@Bowenislandsong
Copy link
Member

Are we going to push this in soon?

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@shawn-hurley
Copy link
Member

/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 18, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label May 18, 2020
@awgreene
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 18, 2020
@harishsurf
Copy link
Contributor Author

@shawn-hurley, I have rebased this PR and is ready for merge. Could you please take a look?

@shawn-hurley
Copy link
Member

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 19, 2020
@openshift-merge-robot openshift-merge-robot merged commit bc89b65 into operator-framework:master May 19, 2020
@harishsurf harishsurf deleted the pkg-msft-e2e branch May 19, 2020 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants