Add nil/null support to the cryptString struct#10
Add nil/null support to the cryptString struct#10sowmiyamuthuraman wants to merge 2 commits intoblaskovicz:masterfrom
Conversation
Pull Request Test Coverage Report for Build 38
💛 - Coveralls |
cryptkeeper.go
Outdated
| ) | ||
|
|
||
| /* NullString is an alias for sql.NullInt64 data type */ | ||
| type NullString sql.NullString |
cryptkeeper.go
Outdated
| driver.Valuer | ||
|
|
||
| String string | ||
| String NullString |
There was a problem hiding this comment.
it may be worth embedding the NullString struct rather than making a .String since that will cut out some code noise (ie .String.String, .String.Valid, etc)
cryptkeeper.go
Outdated
| func (cs *CryptString) UnmarshalJSON(b []byte) error { | ||
| var target string | ||
| if err := json.Unmarshal(b, &target); err != nil { | ||
| cs.String = NullString{Valid: false} |
5803d31 to
62ee9d1
Compare
cryptkeeper_test.go
Outdated
| t.Run("Value", func(t *testing.T) { | ||
| var cs CryptString | ||
| cs.String = "hello world!" | ||
| cs.NullString = sql.NullString{"hello world!", true} |
There was a problem hiding this comment.
now that you've embedded the struct, is it possible to do the following:
| cs.NullString = sql.NullString{"hello world!", true} | |
| cs.String = "hello world!" | |
| cs.Valid = true |
62ee9d1 to
00d90a1
Compare
| if err != nil { | ||
| t.Fatalf("SetCryptKey should be valid, got: '%s'", err) | ||
| } | ||
| cs := CryptString{String: "another secret text"} |
There was a problem hiding this comment.
this can stay what it was with, Valid: true, similar to how you made the change in the previous code.
00d90a1 to
4353c2f
Compare
|
Is it possible to add some test cases for this (specifically for Valid, and also for the null cases) and also add it to CryptBytes as well (since you already added it to CryptString)? Thank you for your help. |
|
@blaskovicz for CryptBytes, as there is no structs like sql.NullString for bytes is it fine to introduce the Valid field in the CryptBytes struct. |
Fixes #4