-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Module versions #16466
Merged
Merged
Module versions #16466
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
803d18a
add more metadata to the Tree and the storage path
jbardin 8d8f77c
Use the new regsrc and response packages
jbardin 9fdf0e1
failing test for changing intermediate modules
jbardin 750b46f
missing current module source in versionedPathKey
jbardin 439dcac
a series of test commits
jbardin 152918d
remove the registryDetector
jbardin f56633c
Lookup registry module versions during Tree.Load.
jbardin 4ab03bf
ProviderConfig needs an Inherited flag
jbardin 74dec5e
flag off registry ACC test
jbardin e360939
update test for error condition
jbardin e658390
use URLs rather than strings is registry functions
jbardin 32c2efe
add example for the reason behind versionedPathKey
jbardin 68bf48e
fix vet error
jbardin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package module | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/registry/regsrc" | ||
) | ||
|
||
func TestParseRegistrySource(t *testing.T) { | ||
for _, tc := range []struct { | ||
source string | ||
host string | ||
id string | ||
err bool | ||
notRegistry bool | ||
}{ | ||
{ // simple source id | ||
source: "namespace/id/provider", | ||
id: "namespace/id/provider", | ||
}, | ||
{ // source with hostname | ||
source: "registry.com/namespace/id/provider", | ||
host: "registry.com", | ||
id: "namespace/id/provider", | ||
}, | ||
{ // source with hostname and port | ||
source: "registry.com:4443/namespace/id/provider", | ||
host: "registry.com:4443", | ||
id: "namespace/id/provider", | ||
}, | ||
{ // too many parts | ||
source: "registry.com/namespace/id/provider/extra", | ||
notRegistry: true, | ||
}, | ||
{ // local path | ||
source: "./local/file/path", | ||
notRegistry: true, | ||
}, | ||
{ // local path with hostname | ||
source: "./registry.com/namespace/id/provider", | ||
notRegistry: true, | ||
}, | ||
{ // full URL | ||
source: "https://example.com/foo/bar/baz", | ||
notRegistry: true, | ||
}, | ||
{ // punycode host not allowed in source | ||
source: "xn--80akhbyknj4f.com/namespace/id/provider", | ||
err: true, | ||
}, | ||
{ // simple source id with subdir | ||
source: "namespace/id/provider//subdir", | ||
id: "namespace/id/provider", | ||
}, | ||
{ // source with hostname and subdir | ||
source: "registry.com/namespace/id/provider//subdir", | ||
host: "registry.com", | ||
id: "namespace/id/provider", | ||
}, | ||
{ // source with hostname | ||
source: "registry.com/namespace/id/provider", | ||
host: "registry.com", | ||
id: "namespace/id/provider", | ||
}, | ||
{ // we special case github | ||
source: "github.com/namespace/id/provider", | ||
notRegistry: true, | ||
}, | ||
{ // we special case github ssh | ||
source: "git@github.com:namespace/id/provider", | ||
notRegistry: true, | ||
}, | ||
{ // we special case bitbucket | ||
source: "bitbucket.org/namespace/id/provider", | ||
notRegistry: true, | ||
}, | ||
} { | ||
t.Run(tc.source, func(t *testing.T) { | ||
mod, err := regsrc.ParseModuleSource(tc.source) | ||
if tc.notRegistry { | ||
if err != regsrc.ErrInvalidModuleSource { | ||
t.Fatalf("%q should not be a registry source, got err %v", tc.source, err) | ||
} | ||
return | ||
} | ||
|
||
if tc.err { | ||
if err == nil { | ||
t.Fatal("expected error") | ||
} | ||
return | ||
} | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
id := fmt.Sprintf("%s/%s/%s", mod.RawNamespace, mod.RawName, mod.RawProvider) | ||
|
||
if tc.host != "" { | ||
if mod.RawHost.Normalized() != tc.host { | ||
t.Fatalf("expected host %q, got %q", tc.host, mod.RawHost) | ||
} | ||
} | ||
|
||
if tc.id != id { | ||
t.Fatalf("expected id %q, got %q", tc.id, id) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this style return an error? I can't think of what useful behavior this could have if we don't treat it as a registry URL, and so I think probably better to give the user the feedback that this isn't a valid source string. (Notwithstanding the special exceptions for
github.com
/etc handled elsewhere, of course.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, it actually does now, but
notRegistry
is checked first. I'll update the test.