Skip to content
This repository was archived by the owner on Jun 24, 2020. It is now read-only.

Feature: reuse e2e tests on productized code#237

Closed
cardil wants to merge 4 commits intoknative:masterfrom
cardil:feature/reuse-tests-on-productized
Closed

Feature: reuse e2e tests on productized code#237
cardil wants to merge 4 commits intoknative:masterfrom
cardil:feature/reuse-tests-on-productized

Conversation

@cardil
Copy link
Contributor

@cardil cardil commented Nov 29, 2019

Proposed Changes

Proposed changes details

Expose e2e test as a compliance suite (dbfbf2c)

As a knative vendor we would like to execute tests from upstream knative in out productized code's test plans.

To do that, I propose this minor change that would result in type safe way of reusing upstream test code, by vendoring it in our code. It involves moving e2e test to regular .go file, instead of _test.go file. In that way we can call that code from our test suite.

Add a test context to fine tune compliance suite testing (5d95dd6)

Sometimes upstream tests could not pass yet. That's natural as vendors will always be behind upstream code. In that case we need a mechanism that will let us skip parts of the tests.

That was implemented in test.Context object.

Example usage

There is already created a PR openshift-knative/serverless-operator#32 that uses this concept. Below I highlighted a key test file from that PR (note that we are using 0.9 version of this change):

package e2e

import (
	"testing"

	"github.com/openshift-knative/serverless-operator/test"
	upstreame2e "knative.dev/serving-operator/test/e2e"
	upstreamtest "knative.dev/serving-operator/test"
)

func TestUpstreamKnativeServingOperator(t *testing.T) {
	upstreamtest.ServingOperatorNamespace = "knative-serving"
	suite := upstreame2e.ComplianceSuite()
	ctx := test.SetupClusterAdmin(t)

	defer test.CleanupAll(ctx)
	test.CleanupOnInterrupt(t, func() { test.CleanupAll(ctx) })

	createSubscriptionAndWaitForCSVtoSucceed(t, ctx) // <1>

	skipConfigureSubTest := upstreamtest.Skip(
		"TestKnativeServingDeployment/configure",
		"Skip due to SRVKS-241") // <2>

	upstreamtest.
		NewContext(t).
		WithOverride(skipConfigureSubTest).
		RunSuite(suite) // <3>

	undeployServerlessOperatorAndCheckDependentOperatorsRemoved(t, ctx) // <4>
}
  • <1> setup of our Serverless operator
  • <2> registering a skip for TestKnativeServingDeployment/configure that we are not supporting at this point
  • <3> actual compliance suite execution
  • <4> teardown of our Serverless operator

Release Note

NONE

Also adding some extra OWNER files and test-infra/devstats from
vendor directory that shouldn't be commited
This commit let change test flags from outside. It can be done either by:

 * declaring environmental variables: `TEST_NAMESPACE`, and `TEST_RESOURCE`,
 * using `-ldflags "-X knative.dev/serving-operator/test.ServingOperatorNamespace=knative-serving"`

Changing those flags is needed to perform tests on RH operators.
@googlebot googlebot added the cla: yes Author(s) signed a CLA. label Nov 29, 2019
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@cardil: 8 warnings.

Details

In response to this:

Proposed Changes

  • Rely on PR #223
  • Expose e2e test as a compliance suite (3f6aac3)
  • Add a test context to fine tune compliance suite testing (72c0d7f)

Proposed changes details

Expose e2e test as a compliance suite (3f6aac3)

As a knative vendor we would like to execute tests from upstream knative in out productized code's test plans.

To do that, I propose this minor change that would result in type safe way of reusing upstream test code, by vendoring it in our code. It involves moving e2e test to regular .go file, instead of _test.go file. In that way we can call that code from our test suite.

Add a test context to fine tune compliance suite testing (72c0d7f)

Sometimes upstream tests could not pass yet. That's natural as vendors will always be behind upstream code. In that case we need a mechanism that will let us skip parts of the tests.

That was implemented in test.Context object.

Example usage

There is already created a PR openshift-knative/serverless-operator#32 that uses this concept. Below I highlighted a key test file from that PR (note that we are using 0.9 version of this change):

package e2e

import (
  "testing"

  "github.com/openshift-knative/serverless-operator/test"
  upstreame2e "knative.dev/serving-operator/test/e2e"
  upstreamtest "knative.dev/serving-operator/test"
)

func TestUpstreamKnativeServingOperator(t *testing.T) {
  upstreamtest.ServingOperatorNamespace = "knative-serving"
  suite := upstreame2e.ComplianceSuite()
  ctx := test.SetupClusterAdmin(t)

  defer test.CleanupAll(ctx)
  test.CleanupOnInterrupt(t, func() { test.CleanupAll(ctx) })

  createSubscriptionAndWaitForCSVtoSucceed(t, ctx) // <1>

  skipConfigureSubTest := upstreamtest.Skip(
  	"TestKnativeServingDeployment/configure",
  	"Skip due to SRVKS-241") // <2>

  upstreamtest.
  	NewContext(t).
  	WithOverride(skipConfigureSubTest).
  	RunSuite(suite) // <3>

  undeployServerlessOperatorAndCheckDependentOperatorsRemoved(t, ctx) // <4>
}
  • <1> setup of our Serverless operator
  • <2> registering a skip for TestKnativeServingDeployment/configure that we are not supporting at this point
  • <3> actual compliance suite execution
  • <4> teardown of our Serverless operator

Release Note

NONE

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

*/

// This is a dummy buildable source file to satisfy `dep`
package knative_serving
Copy link
Contributor

Choose a reason for hiding this comment

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

Golint naming: don't use an underscore in package name. More info.

@knative-prow-robot
Copy link
Contributor

Hi @cardil. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cardil
To complete the pull request process, please assign trshafer
You can assign the PR to them by writing /assign @trshafer in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

As a knative vendor we would like to execute tests from upstream knative
in out productized code's test plans.

To do that, I popose this minor change that would result in type safe way
of reusing upstream test code, by vendoring it in out code.
Sometimes upstream tests could not pass yet. In that case we need a
mechanism that will let us skip parts of the tests.

That was implemented in test.Context object
@cardil cardil force-pushed the feature/reuse-tests-on-productized branch from 72c0d7f to 5d95dd6 Compare November 29, 2019 16:49
@markusthoemmes
Copy link
Contributor

I do think this concept spans wide enough to be proposed and discussed in the productivity WG. It only really makes sense if something like this is adopted or at least acknowledged across the entirety of Knative.

@markusthoemmes
Copy link
Contributor

What's also not entirely clear to me yet: Why is this better than just using go test?

@markusthoemmes
Copy link
Contributor

To further clarify (based on a Slack discussion), referencing the bullets in your example.

  1. This is in the setup scripts of this repository. I think if we want to adopt this, this repository should also deploy the operator in the same vain rather than using scripts. Since we want to deploy our own operator as a vendor, that should then be just a modification of the same steps. I don't know if I agree on having that be part of the tests themselves though.
  2. Is arguably nice to have but should imo be made part of go test.
  3. Is just go test currently.
  4. Same as in 1., this is currently part of the scripts.

@cardil
Copy link
Contributor Author

cardil commented Dec 2, 2019

@markusthoemmes proposing another way of reusing tests. That's to create a bash script that create test context and execute tests.

My approach is different. Writing everything as a Go test will be better of ways:

  • It will be easier to understand and write properly as bash isn't well understood and written well
  • test reports will be the same as in other tests
  • It will be easier to reuse in different tests
  • It's easier to select what tests should be run, with build tags
  • In future we might rewrite cluster setup to GO. Then, we will be able to run and DEBUG single test directly from IDE

The last point is biggest for me. That's what I would like to see. To be able to run everything just from IDE. Just as you run Spring Test or Arquillian!

If you think of e2e testing, that might be written in every language that you want. Any! That's that it simulates user operations on live system.

But, writing those in the same language as production code and unit tests code is beneficial. You can use fewer languages to do the job. You are more proficient with language that you're writing the production code in and can use the same tools to do linting, static analysis.

@cardil
Copy link
Contributor Author

cardil commented Dec 2, 2019

2. Is arguably nice to have but should imo be made part of `go test`.

You can't exclude tests with go test. It's only additive.

@k4leung4
Copy link
Contributor

k4leung4 commented Dec 4, 2019

/cc @chaodaiG

@adrcunha
Copy link
Contributor

Related: knative/serving#4263

@chaodaiG
Copy link
Contributor

Is this still being worked on?

@coryrc
Copy link

coryrc commented Jan 30, 2020

Possibly related: knative/serving#4263

@knative-prow-robot
Copy link
Contributor

@cardil: PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@cardil
Copy link
Contributor Author

cardil commented Feb 26, 2020

This is PoC of solution to be discussed.

@aliok
Copy link
Member

aliok commented Mar 2, 2020

@cardil how should we proceed with this one? anything I can do to help?

@cardil
Copy link
Contributor Author

cardil commented Mar 3, 2020

It should be discussed on TOC meeting. It was already pitched there.

@houshengbo
Copy link

Close this PR, because this repo is deprecated.

@houshengbo houshengbo closed this Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.