Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Manifest Version/Source Validation #1370

Merged
merged 5 commits into from
Dec 3, 2017
Merged

Conversation

JackyChiu
Copy link
Contributor

@JackyChiu JackyChiu commented Nov 12, 2017

What does this do / why do we need it?

Constraints/Overrides configs should have a version rule or source.
Warn when it doesn't.

ex.

# Gopkg.toml
[[constraint]]
  name = "github.com/JackyChiu/super-cool-project

$ dep ensure
dep: WARNING: version rule or source should be provided in "constraint"

What should your reviewer look out for in this PR?

  • Is the warning message clear?

Which issue(s) does this PR fix?

fixes #1336

@carolynvs
Copy link
Collaborator

I left a comment on the original issue but want to make it clear that I think we should hold off on merging this until the importers are updated to match (or we rethink how we want this to work). Otherwise after using dep init people will immediately get warnings which would be super confusing for users. 😀

Copy link
Collaborator

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

Reviewing this now, although we might put this on a little hold.

Looks good 👍
Suggested some improvements.

manifest.go Outdated
@@ -117,6 +121,9 @@ func validateManifest(s string) ([]error, error) {
warns = append(warns, fmt.Errorf("Invalid key %q in %q", key, prop))
}
}
if !ruleProvided && len(props) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's warn for no name attribute in constraint/override too. With that we can be sure, we have at least one attribute and not empty. And this check should be performed before checking for missing rule.

Also, since there won't be any changing part in missing name in constraint/override warning, you can create 2 separate variables for them, similar to the error variables in https://github.com/golang/dep/blob/v0.3.2/manifest.go#L31 . And use the same variables in tests to perform comparison.

manifest.go Outdated
@@ -117,6 +121,9 @@ func validateManifest(s string) ([]error, error) {
warns = append(warns, fmt.Errorf("Invalid key %q in %q", key, prop))
}
}
if !ruleProvided && len(props) > 0 {
warns = append(warns, fmt.Errorf("version rule or source should be provided in %q", prop))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be a dynamic error with name in it. So, maybe something like:

fmt.Errorf("branch, version, revision, or source should be provided for %q %q", prop, props["name"])

Which would look something like:

branch, version, revision, or source should be provided for "constraint" "github.com/foo/bar"

Since this warning would only show up after checking for missing constraint/override, we are sure that props["name"] won't be empty.

Copy link
Collaborator

@darkowlzz darkowlzz Nov 13, 2017

Choose a reason for hiding this comment

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

⚠️ Also, no rule check should only be performed for constraint and not for override because just the name attribute is useful in case of overrides. Not the same case with constraints.

manifest_test.go Outdated
@@ -233,15 +233,20 @@ func TestValidateManifest(t *testing.T) {
[[constraint]]
name = "github.com/foo/bar"
`,
wantWarn: []error{errors.New("metadata should be a TOML table")},
wantWarn: []error{
errors.New("metadata should be a TOML table"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's improve this. This error can be put in a variable and reused, like the variables in https://github.com/golang/dep/blob/v0.3.2/manifest.go#L31.

@JackyChiu
Copy link
Contributor Author

JackyChiu commented Nov 14, 2017

Thanks for the review, I'll ping when I've fixed things up 😄

@sdboyer
Copy link
Member

sdboyer commented Nov 14, 2017

thanks for creating #1373, @carolynvs - i've marked this as blocked by that.

@JackyChiu
Copy link
Contributor Author

@darkowlzz updated!

Copy link
Collaborator

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

As discussed earlier, since this is blocked by another issue, we will merge it after that's cleared.

Thanks!

@darkowlzz
Copy link
Collaborator

However, I'm not sure why it's failing on Windows only 🤔

--- FAIL: TestCaseInsentitiveGOPATH (0.03s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x5a2e8b]

Copy link
Collaborator

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

ah! got it. So TestCaseInsentitiveGOPATH is a windows only test and it creates a file with content "[[constraint]]". And that's invalid with this change.

Let's make that a valid constraint.

Updated tests for manifest warnings for new rule
Dynamic version constraint error message
Only warn for version constraint when it's a constraint field
@carolynvs
Copy link
Collaborator

#1414 was just merged and dep init shouldn't create empty constraints anymore, so this can finally be merged! 🎉

@carolynvs carolynvs merged commit 8f4a82c into golang:master Dec 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn when project constraint is missing in Gopkg.toml
5 participants