From f35ebe703201536dc734f338c39916d6838758a4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 3 Oct 2014 13:46:19 -0700 Subject: [PATCH] config/module: walk actually recurses into dirs, don't copy dot-prefix --- config/module/copy_dir.go | 4 ++-- config/module/get_test.go | 19 +++++++++++++++++++ .../test-fixtures/basic-dot/.test/foo.tf | 1 + config/module/test-fixtures/basic-dot/main.tf | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 config/module/test-fixtures/basic-dot/.test/foo.tf create mode 100644 config/module/test-fixtures/basic-dot/main.tf diff --git a/config/module/copy_dir.go b/config/module/copy_dir.go index 981bba1ba..3a5f95e95 100644 --- a/config/module/copy_dir.go +++ b/config/module/copy_dir.go @@ -26,7 +26,7 @@ func copyDir(dst, src string) error { basePath := filepath.Base(path) if strings.HasPrefix(basePath, ".") { // Skip any dot files - return nil + return filepath.SkipDir } dstPath := filepath.Join(dst, basePath) @@ -38,7 +38,7 @@ func copyDir(dst, src string) error { return err } - return copyDir(dstPath, path) + return nil } // If we have a file, copy the contents. diff --git a/config/module/get_test.go b/config/module/get_test.go index 831780214..b403c835c 100644 --- a/config/module/get_test.go +++ b/config/module/get_test.go @@ -60,6 +60,25 @@ func TestGet_fileSubdir(t *testing.T) { } } +func TestGetCopy_dot(t *testing.T) { + dst := tempDir(t) + u := testModule("basic-dot") + + if err := GetCopy(dst, u); err != nil { + t.Fatalf("err: %s", err) + } + + mainPath := filepath.Join(dst, "main.tf") + if _, err := os.Stat(mainPath); err != nil { + t.Fatalf("err: %s", err) + } + + mainPath = filepath.Join(dst, "foo.tf") + if _, err := os.Stat(mainPath); err == nil { + t.Fatal("should not have foo.tf") + } +} + func TestGetCopy_file(t *testing.T) { dst := tempDir(t) u := testModule("basic") diff --git a/config/module/test-fixtures/basic-dot/.test/foo.tf b/config/module/test-fixtures/basic-dot/.test/foo.tf new file mode 100644 index 000000000..76f177f19 --- /dev/null +++ b/config/module/test-fixtures/basic-dot/.test/foo.tf @@ -0,0 +1 @@ +# Hi diff --git a/config/module/test-fixtures/basic-dot/main.tf b/config/module/test-fixtures/basic-dot/main.tf new file mode 100644 index 000000000..383063715 --- /dev/null +++ b/config/module/test-fixtures/basic-dot/main.tf @@ -0,0 +1,5 @@ +# Hello + +module "foo" { + source = "./foo" +}