-
Notifications
You must be signed in to change notification settings - Fork 369
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
Add receipt status #526
Add receipt status #526
Conversation
Codecov Report
@@ Coverage Diff @@
## master #526 +/- ##
==========================================
+ Coverage 58.73% 59.49% +0.75%
==========================================
Files 23 23
Lines 1013 1022 +9
==========================================
+ Hits 595 608 +13
+ Misses 359 355 -4
Partials 59 59
Continue to review full report at Codecov.
|
uri: http://example.com/ | ||
shortDescription: in-memory test plugin object | ||
version: v1.0.0-test.1 | ||
Status: |
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 shouldnt be parsing correctly, right?
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 didn't actually notice that I capitalized those. Let me look into it.
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 thought the json struct tags would affect how it was parsed but it doesn't seem to be that way. When the receipt is written it uses lower case letters for those keys. Am I missing something?
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 just shouldn’t be parsing accurately.
We currently ignore unknown fields intentionally.
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 a little confused I think. What do you mean by unknown fields in this case? If you're referring specifically to the test receipt that has a custom index set in its status, I mainly added that even though only default can be set in a receipt because receipt.Load
doesn't validate the index that is parsed. Let me know if I misunderstood.
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.
All our fields are case-sensitive.
So as you can imagine, there can't be a field capitalized like Status
.
So typing Status
here should be the same as Asadklfjdksfj
(which would be ignored).
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 tried changing version
to Version
in my receipts in my normal krew installation and was still able to parse receipts in kubectl krew list
(where it loads the receipts and gets .Spec.Version
from them). Maybe I'm doing something wrong. I also thought they were case sensitive and made a mistake by accidentally making those capitalized in the test file, but didn't notice it since the tests were passing and they were still parsing correctly.
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.
That's very odd. Let's continue assuming they're case-sensitive.
We can investigate later why.
internal/index/indexscanner/testdata/testindex/receipts/default-explicit.yaml
Outdated
Show resolved
Hide resolved
internal/index/indexscanner/testdata/testindex/receipts/default-explicit.yaml
Outdated
Show resolved
Hide resolved
pkg/index/types.go
Outdated
@@ -62,4 +62,17 @@ type FileOperation struct { | |||
// Receipt describes a plugin receipt file. | |||
type Receipt struct { | |||
Plugin `json:",inline" yaml:",inline"` | |||
|
|||
Status ReceiptStatus `json:"status,omitempty"` |
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.
why ,omitempty
? we want receipts to always have status
(except today's receipts, which currently don't have, but once they are updated, they should).
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 was just me misremembering what we talked about before, I wrote up the receipt issue before you and I cleared that up and I copied over the struct definitions I wrote there and forgot to remove this. I'll get rid of it 👍
/lgtm |
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 already looks quite good. However, I'd like to reduce the number of extra test files. Ideally, you don't even need to add extra yaml files at all (see below).
But if you have a good reason to add these, please remove one of them because it does not add anything.
} | ||
tests := []struct { | ||
name string | ||
args args |
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 haven't read the previous review comments, but is there a reason why receiptFilePath
is wrapped in this args struct? There could as well just be a single receiptFilePath
field.
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.
Its left over from a previous version. I had some other things there before that I moved out, I'll make the change.
wantStatus: index.ReceiptStatus{}, | ||
}, | ||
{ | ||
name: "read receipt of plugin from default index with status", |
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.
name: "read receipt of plugin from default index with status", | |
name: "read receipt with explicit source index", |
dest := tmpDir.Path("some-plugin.yaml") | ||
|
||
if err := Store(testPlugin, dest); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
actual, err := indexscanner.LoadPluginByName(tmpDir.Root(), "some-plugin") | ||
actual, err := indexscanner.ReadReceiptFromFile(tmpDir.Path("some-plugin.yaml")) |
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.
actual, err := indexscanner.ReadReceiptFromFile(tmpDir.Path("some-plugin.yaml")) | |
actual, err := indexscanner.ReadReceiptFromFile(dest) |
args: args{ | ||
receiptFilePath: filepath.Join(testdataPath(t), "testindex", "receipts", "foo.yaml"), | ||
}, |
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.
You could also use your testdata builder NewReceipt().WithXX().V()
and store that in a temporary directory with tmpDir.WriteYAML(...)
.
Why did you opt for test fixtures instead?
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.
Ya I can change it to this. I think I did it this way because this is how it was outlined in the previous receipts PR and I just had that on my mind while I was working on this initially.
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.
Yeah, we talked about both options. Back then we didn't have the receipt builder, so the static file was easier. But now, I think the dynamic approach is far better.
It's also currently unclear to me where we should be doing the "defaulting" of the missing WDYT @corneliusweig? |
Doing the defaulting while reading leads to the least duplication, so let's do it that way. Good idea! |
Add tests to scanner_test.go to verify reading receipt files
c1f485e
to
22764a6
Compare
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 last two little nits, then it's ready to merge from my side.
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahmetb, chriskim06 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 |
wantStatus := &index.ReceiptStatus{ | ||
Source: index.SourceIndex{ | ||
Name: name, | ||
type args struct { |
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.
for this time it's ok but in the future I recommend avoiding single-field type args
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.
Crap sorry about that, you mentioned that before. I'll remember next time and change this in a follow up PR most likely.
/lgtm |
🎊 One more step! So nice to see this going forward! |
This adds the status object to the receipt type that was added earlier. The changes are pretty small, most of the additions are from tests implemented in the way outlined here.
Fixes #507
Related issue: #483