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

refactor crypto keys test #158

Merged
merged 4 commits into from
Jul 29, 2022
Merged

refactor crypto keys test #158

merged 4 commits into from
Jul 29, 2022

Conversation

nitro-neal
Copy link
Contributor

Removing duplicate code and dynamically running all supported key types

@codecov-commenter
Copy link

codecov-commenter commented Jul 28, 2022

Codecov Report

Merging #158 (dc79b90) into main (fd21ecc) will increase coverage by 0.05%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main     #158      +/-   ##
==========================================
+ Coverage   53.27%   53.32%   +0.05%     
==========================================
  Files          32       32              
  Lines        3773     3773              
==========================================
+ Hits         2010     2012       +2     
+ Misses       1391     1389       -2     
  Partials      372      372              
Impacted Files Coverage Δ
crypto/models.go 11.11% <0.00%> (+11.11%) ⬆️

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 fd21ecc...dc79b90. Read the comment docs.

assert.NoError(tt, err)
assert.NotEmpty(tt, pub)
assert.NotEmpty(tt, priv)
func validateKeyGeneration(tt *testing.T, pub crypto.PublicKey, priv crypto.PrivateKey, keyType KeyType, err error) {
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 sure I see the benefit in having this as a separate function.

Perhaps just embedding it in the above is sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup embedding is a good call

assert.EqualValues(tt, priv, reconstructedPriv)
})
for _, keyType := range GetSupportedKeyTypes() {
t.Run(string(keyType), func(tt *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.

Table driven tests are a go convention.

What do you think about adjusting this from a loop to a table test format?

https://github.com/golang/go/wiki/TableDrivenTests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like for a table driven test it has known input and output. With this unit test it doesn't really have a known output, so the table would only have on dimension an input.

I could explicitly create an array in the test to match this basically or we can keep using GetSupportedKeyTypes

https://github.com/TBD54566975/ssi-sdk/blob/main/crypto/models.go#L45

@decentralgabe decentralgabe merged commit 1ad45a9 into main Jul 29, 2022
@decentralgabe decentralgabe deleted the refactor-unit-test branch July 29, 2022 16:58
@decentralgabe decentralgabe added this to the Milestone 2 milestone Jul 29, 2022
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.

None yet

3 participants