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

Initial receipt type #512

Merged
merged 6 commits into from
Feb 27, 2020

Conversation

chriskim06
Copy link
Member

This refactors the receipts to use a new Receipt type. The tests for it are pretty much identical to the old ones but using the new type. Once the status object gets added to receipts the tests will need to be updated.

I decided to not do type Receipt Plugin, only because I figured this would be changed very soon and would save a bit of work down the line. If you'd like me to change it and start out without the embedded type just let me know.

Related issues: #483, #507

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 25, 2020
Comment on lines 30 to 35
func (r *Receipt) WithName(s string) *Receipt { r.v.ObjectMeta.Name = s; return r }
func (r *Receipt) WithShortDescription(v string) *Receipt { r.v.Spec.ShortDescription = v; return r }
func (r *Receipt) WithTypeMeta(v metav1.TypeMeta) *Receipt { r.v.TypeMeta = v; return r }
func (r *Receipt) WithPlatforms(v ...index.Platform) *Receipt { r.v.Spec.Platforms = v; return r }
func (r *Receipt) WithVersion(v string) *Receipt { r.v.Spec.Version = v; return r }
func (r *Receipt) V() index.Receipt { return r.v }
Copy link
Member

Choose a reason for hiding this comment

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

let's not copy it like this.

Something that is much smaller like the following would be enough:

NewReceipt().WithPlugin(p).WithStatus()

Copy link
Member Author

Choose a reason for hiding this comment

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

I could just remove instead, since I only added this for the validation test that I was unsure of. What do you think about just removing this for now? It will probably come up later but its not needed once I remove the validation stuff.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I don't see enough reasons for this to exist yet.

@codecov-io
Copy link

codecov-io commented Feb 25, 2020

Codecov Report

Merging #512 into master will decrease coverage by 0.27%.
The diff coverage is 64%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #512      +/-   ##
==========================================
- Coverage   59.12%   58.85%   -0.28%     
==========================================
  Files          23       23              
  Lines        1003     1011       +8     
==========================================
+ Hits          593      595       +2     
- Misses        350      358       +8     
+ Partials       60       58       -2
Impacted Files Coverage Δ
internal/installation/receipt/receipt.go 75% <100%> (ø) ⬆️
internal/index/indexscanner/scanner.go 66.1% <60.86%> (-6.45%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f1339f...29c6f53. Read the comment docs.

pkg/index/types.go Show resolved Hide resolved
internal/index/indexscanner/scanner_test.go Outdated Show resolved Hide resolved
internal/index/indexscanner/scanner_test.go Outdated Show resolved Hide resolved
internal/index/indexscanner/scanner_test.go Outdated Show resolved Hide resolved
internal/index/indexscanner/scanner_test.go Outdated Show resolved Hide resolved
@corneliusweig
Copy link
Contributor

Interesting. Travis builds seem to be broken right now. I guess we either need to disable travis or this test for now :)

@ahmetb
Copy link
Member

ahmetb commented Feb 25, 2020

@corneliusweig do you mind Making the error more Verbose in Test_fetchLatestTag_GitHubAPI? I suspect it’s hitting API rate limits of travis servers.

internal/index/indexscanner/scanner_test.go Outdated Show resolved Hide resolved
if got.Name != "foo" && got.Kind != "Plugin" {
t.Errorf("ReadReceiptFromFile() has not parsed the metainformations %v", got)
return
if cmp.Diff(got.Plugin, receipt) != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

cmp.Diff already formats the differences in an easy to read way. You should do

if diff := cmp.Diff(got.Plugin, receipt); diff != "" {
   t.Errorf("Parsed receipt has unexpected content: %s", diff)
}

internal/index/indexscanner/scanner.go Outdated Show resolved Hide resolved
internal/index/indexscanner/scanner.go Outdated Show resolved Hide resolved
internal/index/indexscanner/scanner.go Outdated Show resolved Hide resolved
internal/index/indexscanner/scanner.go Show resolved Hide resolved
internal/index/indexscanner/scanner.go Show resolved Hide resolved
@@ -90,6 +93,56 @@ func TestReadPluginFile(t *testing.T) {
}
}

func TestReadReceiptFile(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not particularly happy with the test below, as it exercises only a few things. For example, it doesn't check whether the status fields are parsed correctly.

We just need 1 test case that makes sure the fields are parsed decently. and the json:"foo,omitempty" field-tags are accurate.

So I suggest we do this:

  1. Add a few receipt test files in testdata/receipts/foo.yaml

  2. Parse the receipt file from disk.

  3. Build as NewReceipt().WithXxx(...)....V() and use cmp.Diff to do equality check.

@corneliusweig wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, so far Receipt does not have any extra fields beside the ones from Plugin. So we are cutting corners by parsing a plugin yaml as a receipt. I think that's ok for now, but we need to ensure that we extend this test as suggested by Ahmet.

And I'm in for the receipt builder pattern. The sooner we have it, the better.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah in the next PR, we should add the status field and start working with it to develop tests like this (where we can roundtrip the type i.e. write/parse a YAML file).

Copy link
Member Author

Choose a reason for hiding this comment

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

So is this ok as is for now while status doesn't exist?

Copy link
Member

Choose a reason for hiding this comment

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

yeah not so useful but helps us pass the tests.
feel free to remove it altogether or add TODO that captures comment above, but this should be the next PR anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I'll just remove it from this PR and add the tests in the next one when they can be more meaningful with the new status field.

@ahmetb
Copy link
Member

ahmetb commented Feb 27, 2020

We can go ahead with this if you merge the small outstanding style comments.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 27, 2020
@corneliusweig
Copy link
Contributor

/lgtm
/approve
Thanks, @chriskim06, for bearing with us. It always takes some time to get used to the coding style of a new project. But we're getting there! And having two reviewers is also challenging :)

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 27, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chriskim06, corneliusweig

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 27, 2020
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 27, 2020
@corneliusweig
Copy link
Contributor

/lgtm
🎊

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 27, 2020
@k8s-ci-robot k8s-ci-robot merged commit 7b0041a into kubernetes-sigs:master Feb 27, 2020
@chriskim06 chriskim06 mentioned this pull request Feb 29, 2020
@chriskim06 chriskim06 deleted the initial-receipt-type branch June 11, 2020 15:05
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. area/multi-index cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants