-
Notifications
You must be signed in to change notification settings - Fork 562
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
Convert package manifest e2e to ginkgo test #1439
Conversation
@@ -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}) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
test/e2e/packagemanifest_e2e_test.go
Outdated
_, 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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
c344a25
to
3c06da0
Compare
/retest |
test/e2e/util_test.go
Outdated
require.NoError(t, extScheme.AddToScheme(scheme)) | ||
require.NoError(t, k8sscheme.AddToScheme(scheme)) | ||
require.NoError(t, v1beta1.AddToScheme(scheme)) | ||
err := extScheme.AddToScheme(scheme) |
There was a problem hiding this comment.
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())
.
test/e2e/packagemanifest_e2e_test.go
Outdated
relatedImages := pm.Status.Channels[0].CurrentCSVDesc.RelatedImages | ||
Expect(len(relatedImages)).To(Equal(len(expectedRelatedImages))) | ||
|
||
for _, v := range relatedImages { |
There was a problem hiding this comment.
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.
test/e2e/packagemanifest_e2e_test.go
Outdated
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() { |
There was a problem hiding this comment.
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!
test/e2e/packagemanifest_e2e_test.go
Outdated
csvJSON, _ := json.Marshal(csv) | ||
|
||
// Wait for package-server to be ready | ||
err := wait.Poll(pollInterval, 1*time.Minute, func() (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this use Eventually
?
test/e2e/packagemanifest_e2e_test.go
Outdated
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) |
There was a problem hiding this comment.
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.
test/e2e/packagemanifest_e2e_test.go
Outdated
return true, nil | ||
} | ||
return false, nil | ||
Context("Given a ConfigMap containing package manifest, CSV and CRD", func() { |
There was a problem hiding this comment.
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.
test/e2e/packagemanifest_e2e_test.go
Outdated
_, err = fetchCatalogSource(crc, catalogSourceName, testNamespace, catalogSourceRegistryPodSynced) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
By("querying the package manifest using the package name", func() { |
There was a problem hiding this comment.
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.
test/e2e/packagemanifest_e2e_test.go
Outdated
} | ||
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() { |
There was a problem hiding this comment.
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:
- poll until list package manifests returns without error
- require that get catalog source returns without error
- poll until get package manifest returns without error
to:
- 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.
test/e2e/packagemanifest_e2e_test.go
Outdated
_, 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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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}) |
There was a problem hiding this comment.
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.
test/e2e/packagemanifest_e2e_test.go
Outdated
@@ -3,170 +3,196 @@ package e2e | |||
import ( | |||
"context" | |||
"encoding/json" | |||
|
There was a problem hiding this comment.
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
test/e2e/packagemanifest_e2e_test.go
Outdated
}, | ||
} | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" |
There was a problem hiding this comment.
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
3c06da0
to
ce76cf5
Compare
ce76cf5
to
d79d739
Compare
test/e2e/packagemanifest_e2e_test.go
Outdated
"quay.io/coreos/etcd@sha256:49d3d4a81e0d030d3f689e7167f23e120abf955f7d08dbedf3ea246485acee9f": "", | ||
"quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2": "", | ||
} | ||
It("lists the CatalogSource contents using the PackageManifest API", func() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
bddb339
to
f627979
Compare
/lgtm |
/test e2e-aws-olm |
/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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
test/e2e/packagemanifest_e2e_test.go
Outdated
func containsPackageManifest(pmList []packagev1.PackageManifest, pkgName string) bool { | ||
for _, pm := range pmList { | ||
if pm.GetName() == pkgName { | ||
fmt.Printf("$$$ %v\n", pm.GetName()) |
There was a problem hiding this comment.
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?
test/e2e/packagemanifest_e2e_test.go
Outdated
func containsPackageManifest(pmList []packagev1.PackageManifest, pkgName string) bool { | ||
for _, pm := range pmList { | ||
if pm.GetName() == pkgName { | ||
fmt.Printf("$$$ %v\n", pm.GetName()) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
/retest |
/retest Please review the full test history for this PR and help us cut down flakes. |
14 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
Are we going to push this in soon? |
/retest Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
/retest Please review the full test history for this PR and help us cut down flakes. |
/hold |
Signed-off-by: Harish <[email protected]>
/lgtm |
@shawn-hurley, I have rebased this PR and is ready for merge. Could you please take a look? |
/hold cancel |
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 calledMotivation for the change:
Reviewer Checklist
/docs