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 IsValid() in did/web/web.go #399

Merged
merged 4 commits into from
Jun 1, 2023

Conversation

vlad-tim
Copy link
Contributor

@vlad-tim vlad-tim commented May 30, 2023

Description

  • Change return type of IsValid() to error, and rename the function to Validate().
  • Add context.Context as it's first parameter and propagate it to the network call.
  • Add a unit test that calls Validate() function.
  • Update production code and tests code to account for the method signature changes.

Testing

Ran mage cbt without any errors.

References

Related to #395 .

@michaelneale
Copy link
Contributor

nice to see a test case too, cool

Copy link
Contributor

@andresuribe87 andresuribe87 left a comment

Choose a reason for hiding this comment

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

Thanks so much! A couple minor nits

did/web/web.go Outdated
func (d DIDWeb) Validate(ctx context.Context) error {
_, err := d.resolveDocBytes(ctx)
if err != nil {
return errors.Wrap(err, "failed to validate DID")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return errors.Wrap(err, "failed to validate DID")
return errors.Wrap(err, "resolving doc bytes")

t.Run("Unresolvable Path - Validate DID", func(tt *testing.T) {
err := didWebNotADomain.Validate(context.Background())
assert.Error(tt, err)
assert.Contains(tt, err.Error(), "failed to validate")
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer using

Suggested change
assert.Contains(tt, err.Error(), "failed to validate")
assert.ErrorContains(tt, err, "failed to validate")

@codecov-commenter
Copy link

codecov-commenter commented May 30, 2023

Codecov Report

Merging #399 (5d1e2de) into main (7878abd) will increase coverage by 0.04%.
The diff coverage is 68.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #399      +/-   ##
==========================================
+ Coverage   57.22%   57.26%   +0.04%     
==========================================
  Files          68       68              
  Lines        7347     7354       +7     
==========================================
+ Hits         4204     4211       +7     
+ Misses       2400     2399       -1     
- Partials      743      744       +1     
Impacted Files Coverage Δ
did/web/resolver.go 0.00% <0.00%> (ø)
did/web/web.go 70.64% <78.57%> (+2.01%) ⬆️

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

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

very nice. thank you!

@vlad-tim
Copy link
Contributor Author

vlad-tim commented Jun 1, 2023

Looks like this PR now has conflicts with the mainline. I have just made an attempt to resolve them from the Github UI.

@andresuribe87 andresuribe87 merged commit 07707db into TBD54566975:main Jun 1, 2023
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.

5 participants