-
Notifications
You must be signed in to change notification settings - Fork 196
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
Improve the external API of the PropertyBag #1669
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1669 +/- ##
==========================================
+ Coverage 68.30% 68.39% +0.08%
==========================================
Files 217 220 +3
Lines 15438 15581 +143
==========================================
+ Hits 10545 10656 +111
- Misses 4131 4155 +24
- Partials 762 770 +8
Continue to review full report at Codecov.
|
// Add is used to add a value into the bag; exact formatting depends on the type. | ||
// Any existing value will be overwritten. | ||
// property is the name of the item to put into the bag | ||
// value is the instance to be stashed away for later | ||
func (bag PropertyBag) Add(property string, value interface{}) error { | ||
switch v := value.(type) { | ||
case string: |
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.
minor: This isn't in the code you actually changed, but I'm curious why string
is called out here but not other primitive types?
Feels like you could probably get away without any special casing and just always use json.Marshal
? I am assuming that json.Marshal(str)
just returns str
but I don't know for sure.
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 don't recall - might have been to avoid the overhead of calling json.Marshal
when not required, or it may have been to handle round trip formatting issues. I do remember it was deliberate 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.
Might be worth leaving a comment there as to the reason? Especially if there was some problem if it wasn't handled specially?
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 have a laundry list of minor code-gardening things to do post codegen-alpha-0
, I'll add this to that.
g.Expect(original.Add("Christmas", "25DEC")).To(Succeed()) | ||
|
||
bag := NewPropertyBag(original) | ||
g.Expect(bag).To(HaveKey("Answer")) |
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 aren't asserting that the actual content is correct here, just that it has the key?
Shouldn't you also check to make sure that the key maps to the correct value?
Same comment applies below in a couple other tests, but won't repeat.
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.
Hmm I see in the other tests (that you already had) that you may have those cases covered already.
Maybe this just becomes minor: rather than ReturnsBagWithExpectedContent
use ReturnsBagWithExpectedKeys
to make it clear you only care about asserting on keys here?
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.
Other tests check that the values stored can be recalled cleanly, so I'm only worried in this test whether the expected keys are put into the bag. I'll rename the tests as you suggest.
6ec9760
to
cd54a3a
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.
Approved as the active comments I have are pretty minor, and/or are on sections of the code that actually weren't changed as part of the PR.
Feel free to merge once you've taken a look at them.
What this PR does / why we need it:
The original API of the property bag was going to be troublesome to generate code to consume, partly because of the way it combined checking for existence with deserialization. I've split those functions out into separate methods, which will allow code generation to avoid name collisions by using a nested scope:
Special notes for your reviewer:
Split out as a separate PR to help keep the main PropertyBag usage PR smaller.
How does this PR make you feel:
If applicable: