make //subdir notation work with registry modules
Append the original source subdir to the discovered subdir when locating the files in the module tree.
This commit is contained in:
parent
a359c4ee2f
commit
8933ef8f70
|
@ -101,6 +101,26 @@ func mockRegistry() *httptest.Server {
|
||||||
return server
|
return server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setResetRegDetector(server *httptest.Server) func() {
|
||||||
|
regDetector := ®istryDetector{
|
||||||
|
api: server.URL + "/v1/modules",
|
||||||
|
client: server.Client(),
|
||||||
|
}
|
||||||
|
|
||||||
|
origDetectors := detectors
|
||||||
|
detectors = []getter.Detector{
|
||||||
|
new(getter.GitHubDetector),
|
||||||
|
new(getter.BitBucketDetector),
|
||||||
|
new(getter.S3Detector),
|
||||||
|
regDetector,
|
||||||
|
new(localDetector),
|
||||||
|
}
|
||||||
|
|
||||||
|
return func() {
|
||||||
|
detectors = origDetectors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDetectRegistry(t *testing.T) {
|
func TestDetectRegistry(t *testing.T) {
|
||||||
server := mockRegistry()
|
server := mockRegistry()
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
@ -178,25 +198,13 @@ func TestDetectRegistry(t *testing.T) {
|
||||||
func TestDetectors(t *testing.T) {
|
func TestDetectors(t *testing.T) {
|
||||||
server := mockRegistry()
|
server := mockRegistry()
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
defer setResetRegDetector(server)()
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
regDetector := ®istryDetector{
|
|
||||||
api: server.URL + "/v1/modules",
|
|
||||||
client: server.Client(),
|
|
||||||
}
|
|
||||||
|
|
||||||
detectors := []getter.Detector{
|
|
||||||
new(getter.GitHubDetector),
|
|
||||||
new(getter.BitBucketDetector),
|
|
||||||
new(getter.S3Detector),
|
|
||||||
regDetector,
|
|
||||||
new(localDetector),
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
source string
|
source string
|
||||||
location string
|
location string
|
||||||
|
@ -291,24 +299,7 @@ func TestDetectors(t *testing.T) {
|
||||||
func TestRegistryGitHubArchive(t *testing.T) {
|
func TestRegistryGitHubArchive(t *testing.T) {
|
||||||
server := mockRegistry()
|
server := mockRegistry()
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
defer setResetRegDetector(server)()
|
||||||
regDetector := ®istryDetector{
|
|
||||||
api: server.URL + "/v1/modules",
|
|
||||||
client: server.Client(),
|
|
||||||
}
|
|
||||||
|
|
||||||
origDetectors := detectors
|
|
||||||
defer func() {
|
|
||||||
detectors = origDetectors
|
|
||||||
}()
|
|
||||||
|
|
||||||
detectors = []getter.Detector{
|
|
||||||
new(getter.GitHubDetector),
|
|
||||||
new(getter.BitBucketDetector),
|
|
||||||
new(getter.S3Detector),
|
|
||||||
new(localDetector),
|
|
||||||
regDetector,
|
|
||||||
}
|
|
||||||
|
|
||||||
storage := testStorage(t)
|
storage := testStorage(t)
|
||||||
tree := NewTree("", testConfig(t, "registry-tar-subdir"))
|
tree := NewTree("", testConfig(t, "registry-tar-subdir"))
|
||||||
|
@ -344,6 +335,34 @@ func TestRegistryGitHubArchive(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that the //subdir notation can be used with registry modules
|
||||||
|
func TestRegisryModuleSubdir(t *testing.T) {
|
||||||
|
server := mockRegistry()
|
||||||
|
defer server.Close()
|
||||||
|
defer setResetRegDetector(server)()
|
||||||
|
|
||||||
|
storage := testStorage(t)
|
||||||
|
tree := NewTree("", testConfig(t, "registry-subdir"))
|
||||||
|
|
||||||
|
if err := tree.Load(storage, GetModeGet); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !tree.Loaded() {
|
||||||
|
t.Fatal("should be loaded")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := tree.Load(storage, GetModeNone); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := strings.TrimSpace(tree.String())
|
||||||
|
expected := strings.TrimSpace(treeLoadRegistrySubdirStr)
|
||||||
|
if actual != expected {
|
||||||
|
t.Fatalf("got: \n\n%s\nexpected: \n\n%s", actual, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccRegistryDiscover(t *testing.T) {
|
func TestAccRegistryDiscover(t *testing.T) {
|
||||||
if os.Getenv("TF_ACC") == "" {
|
if os.Getenv("TF_ACC") == "" {
|
||||||
t.Skip("skipping ACC test")
|
t.Skip("skipping ACC test")
|
||||||
|
|
|
@ -241,14 +241,9 @@ func (t *Tree) Load(s getter.Storage, mode GetMode) error {
|
||||||
// For example, the registry always adds a subdir of `//*`,
|
// For example, the registry always adds a subdir of `//*`,
|
||||||
// indicating that we need to strip off the first component from the
|
// indicating that we need to strip off the first component from the
|
||||||
// tar archive, though we may not yet know what it is called.
|
// tar archive, though we may not yet know what it is called.
|
||||||
//
|
source, detectedSubDir := getter.SourceDirSubdir(source)
|
||||||
// TODO: This can cause us to lose the previously detected subdir. It
|
if detectedSubDir != "" {
|
||||||
// was never an issue before, since none of the supported detectors
|
subDir = filepath.Join(detectedSubDir, subDir)
|
||||||
// previously had this behavior, but we may want to add this ability to
|
|
||||||
// registry modules.
|
|
||||||
source, subDir2 := getter.SourceDirSubdir(source)
|
|
||||||
if subDir2 != "" {
|
|
||||||
subDir = subDir2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[TRACE] getting module source %q", source)
|
log.Printf("[TRACE] getting module source %q", source)
|
||||||
|
|
|
@ -705,3 +705,8 @@ root
|
||||||
foo (path: foo)
|
foo (path: foo)
|
||||||
bar (path: foo, bar)
|
bar (path: foo, bar)
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const treeLoadRegistrySubdirStr = `
|
||||||
|
root
|
||||||
|
foo (path: foo)
|
||||||
|
`
|
||||||
|
|
Loading…
Reference in New Issue