Skip to content
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

Refactor sink test #882

Merged
merged 1 commit into from
Jan 15, 2021
Merged

Conversation

dibyom
Copy link
Member

@dibyom dibyom commented Dec 30, 2020

Changes

There are two commits in this PR. It's pretty big but a lot of it is deleting duplicated code. The largest change is to take the many TestHandle* tests that all had the same setup steps and combine them into a single table driven test with multiple test cases.

There were a lost of TestHandle* tests with the same copy pasta making
it hard to read/modify e.g. they all copied the same code to create
PipelineResource templates, used the same eventBody etc.

  1. combine most TestHandle into a table driven test
  2. use v1beta1 TaskRuns instead of PipelineResources for all tests
  3. add a func for creating test servers with core/webhook interceptors
  4. refactor test.HMACHeader to take in testing.TB
  5. use switch instead of if/else to reduce verbosity in TestHandle_OverrideAuth
  6. use test.RawExtension helper for creating triggertemplates

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

See the contribution guide for more details.

Release Notes

NONE

@tekton-robot tekton-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Dec 30, 2020
@tekton-robot tekton-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 30, 2020
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 90.0% 92.2% 2.2
pkg/sink/sink.go 78.1% 78.5% 0.5
test/controller.go 72.9% 73.1% 0.2
test/resources.go 0.0% 42.9% 42.9
test/signature.go 80.0% 83.3% 3.3

@dibyom dibyom force-pushed the refactor_sink_test branch from 58580a3 to 639ef65 Compare December 30, 2020 23:00
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 90.0% 92.2% 2.2
pkg/sink/sink.go 78.1% 78.5% 0.5
test/controller.go 72.9% 73.1% 0.2
test/resources.go 0.0% 42.9% 42.9
test/signature.go 80.0% 83.3% 3.3

@dibyom dibyom force-pushed the refactor_sink_test branch from 639ef65 to a589532 Compare January 6, 2021 03:09
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 90.0% 92.2% 2.2
pkg/sink/sink.go 78.1% 78.1% 0.1
test/controller.go 72.9% 73.1% 0.2
test/resources.go 0.0% 42.9% 42.9
test/signature.go 80.0% 83.3% 3.3

@dibyom dibyom force-pushed the refactor_sink_test branch from a589532 to bdd91ea Compare January 6, 2021 16:39
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 90.0% 92.1% 2.1
pkg/sink/sink.go 78.1% 78.4% 0.3
test/controller.go 72.9% 73.1% 0.2
test/resources.go 0.0% 42.9% 42.9
test/signature.go 80.0% 83.3% 3.3

@dibyom dibyom force-pushed the refactor_sink_test branch from bdd91ea to 43be775 Compare January 7, 2021 20:28
@dibyom dibyom marked this pull request as ready for review January 7, 2021 20:29
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 7, 2021
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
test/controller.go 72.9% 73.1% 0.2
test/resources.go 0.0% 42.9% 42.9
test/signature.go 80.0% 83.3% 3.3

@dibyom dibyom added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Jan 7, 2021
@bigkevmcd
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 12, 2021
test/resources.go Outdated Show resolved Hide resolved
Copy link
Contributor

@savitaashture savitaashture left a comment

Choose a reason for hiding this comment

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

looks good to me 👍

minor question on attribute position change

@dibyom dibyom force-pushed the refactor_sink_test branch from 43be775 to 3c07486 Compare January 12, 2021 20:32
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jan 12, 2021
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
test/controller.go 72.9% 73.1% 0.2
test/resources.go 0.0% 42.9% 42.9
test/signature.go 80.0% 83.3% 3.3

Copy link
Contributor

@savitaashture savitaashture left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2021
Copy link
Member

@MarcelMue MarcelMue left a comment

Choose a reason for hiding this comment

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

Just some comments as I try to get into the project more.

pkg/sink/sink_test.go Outdated Show resolved Hide resolved
// want is the resulting TaskRun(s) created by the EventListener
want []pipelinev1.TaskRun
}{{
name: "single trigger embedded within EventListener",
Copy link
Member

Choose a reason for hiding this comment

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

Are there any conventions on test case naming? I generally like this style of naming but have noticed that it is inconsistent throughout the triggers project.

Copy link
Member Author

Choose a reason for hiding this comment

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

no hard and fast rule. Ideally the name would be both descriptive and short but if not possible, I prefer a more descriptive but longer name over a shorter one (though you are right we haven't been very consistent about this).

// Check right resources were created.
got := toTaskRun(t, dynamicClient.Actions())
// Sort actions (we do not know what order they executed in)
if diff := cmp.Diff(tc.want, got, cmpopts.SortSlices(func(x, y pipelinev1.TaskRun) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Could this be split into two lines? Otherwise the comment is not really true as we sort and compare in a single line. It would make the code more readable / easier to follow IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

sure!

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the comment -- we don't technically sort the taskRuns ourselves, cmp.Diff has an option to sortSlices, we just pass it a function that it can use to compare the TaskRuns when sorting.

"secretKey": []byte("secret"),
},
}
// Setup for TestHandleEvent_AuthOverride
Copy link
Member

Choose a reason for hiding this comment

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

Why are these declared in the middle of the file as compared to either at the top or in inside the test func?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't put it inside the TestHandleEvent_AuthOverride since these variables are used in the OverrideAuthentication method that we implement for the fakeAuth type below. We could put these at the top of the file too but given that these are only used for the test below, we declare them close to where they are being used.

@dibyom dibyom force-pushed the refactor_sink_test branch from 3c07486 to 9f8452a Compare January 13, 2021 22:14
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2021
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
test/controller.go 72.9% 73.1% 0.2
test/resources.go 0.0% 42.9% 42.9
test/signature.go 80.0% 83.3% 3.3

@MarcelMue
Copy link
Member

/lgtm

@tekton-robot
Copy link

@MarcelMue: changing LGTM is restricted to collaborators

In response to this:

/lgtm

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.

@savitaashture
Copy link
Contributor

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 14, 2021
Copy link
Contributor

@khrm khrm left a comment

Choose a reason for hiding this comment

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

/lgtm

@khrm
Copy link
Contributor

khrm commented Jan 15, 2021

/approve

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: khrm

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

The pull request process is described here

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 15, 2021
@dibyom dibyom force-pushed the refactor_sink_test branch from 9f8452a to ac2543f Compare January 15, 2021 16:39
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jan 15, 2021
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
test/controller.go 72.9% 73.1% 0.2
test/resources.go 0.0% 42.9% 42.9
test/signature.go 80.0% 83.3% 3.3

There were a lost of TestHandle* tests with the same copy pasta making
it hard to read/modify e.g. they all copied the same code to create
PipelineResource templates, used the same eventBody etc.

1. combine most TestHandle into a table driven test
2. use v1beta1 TaskRuns instead of PipelineResources for all tests
3. add a func for creating test servers with core/webhook interceptors
4. refactor test.HMACHeader to take in testing.TB
5. use switch instead of if/else to reduce verbosity in TestHandle_OverrideAuth
6. use test.RawExtension helper for creating triggertemplates

Signed-off-by: Dibyo Mukherjee <[email protected]>
@dibyom dibyom force-pushed the refactor_sink_test branch from ac2543f to 02cfee5 Compare January 15, 2021 18:49
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
test/controller.go 72.9% 73.1% 0.2
test/resources.go 0.0% 42.9% 42.9
test/signature.go 80.0% 83.3% 3.3

@MarcelMue
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 15, 2021
@tekton-robot tekton-robot merged commit ee784d4 into tektoncd:master Jan 15, 2021
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants