Skip to content

Add nil/null support to the cryptString struct#10

Open
sowmiyamuthuraman wants to merge 2 commits intoblaskovicz:masterfrom
sowmiyamuthuraman:Fix/#4
Open

Add nil/null support to the cryptString struct#10
sowmiyamuthuraman wants to merge 2 commits intoblaskovicz:masterfrom
sowmiyamuthuraman:Fix/#4

Conversation

@sowmiyamuthuraman
Copy link

Fixes #4

@coveralls
Copy link

coveralls commented Oct 13, 2019

Pull Request Test Coverage Report for Build 38

  • 8 of 12 (66.67%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-2.03%) to 88.811%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cryptkeeper.go 8 12 66.67%
Totals Coverage Status
Change from base Build 28: -2.03%
Covered Lines: 127
Relevant Lines: 143

💛 - Coveralls

cryptkeeper.go Outdated
)

/* NullString is an alias for sql.NullInt64 data type */
type NullString sql.NullString
Copy link
Owner

Choose a reason for hiding this comment

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

Why did you need to do this?

cryptkeeper.go Outdated
driver.Valuer

String string
String NullString
Copy link
Owner

Choose a reason for hiding this comment

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

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}
Copy link
Owner

Choose a reason for hiding this comment

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

Valid is false by default

@sowmiyamuthuraman sowmiyamuthuraman force-pushed the Fix/#4 branch 4 times, most recently from 5803d31 to 62ee9d1 Compare October 22, 2019 18:42
t.Run("Value", func(t *testing.T) {
var cs CryptString
cs.String = "hello world!"
cs.NullString = sql.NullString{"hello world!", true}
Copy link
Owner

Choose a reason for hiding this comment

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

now that you've embedded the struct, is it possible to do the following:

Suggested change
cs.NullString = sql.NullString{"hello world!", true}
cs.String = "hello world!"
cs.Valid = true

if err != nil {
t.Fatalf("SetCryptKey should be valid, got: '%s'", err)
}
cs := CryptString{String: "another secret text"}
Copy link
Owner

Choose a reason for hiding this comment

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

this can stay what it was with, Valid: true, similar to how you made the change in the previous code.

@blaskovicz
Copy link
Owner

blaskovicz commented Oct 24, 2019

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.

@sowmiyamuthuraman
Copy link
Author

@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.

@blaskovicz
Copy link
Owner

@sowmiyamuthuraman yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add nil/null support similar to sql.NullBool

3 participants