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

Fix issue 518 #547

Merged
merged 3 commits into from
Nov 20, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions command/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,45 @@ func TestInit_noArgs(t *testing.T) {
t.Fatalf("bad: \n%s", ui.OutputWriter.String())
}
}

// https://github.com/hashicorp/terraform/issues/518
func TestIssue518(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's name this something more semantic like "TestInit_dstInSrc". We can still link to the issue, but it's useful to have semantic names for these types of things (imagine if GitHub is down for example)

dir := tempDir(t)
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatalf("err: %s", err)
}

// Change to the temporary directory
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("err: %s", err)
}
if err := os.Chdir(dir); err != nil {
t.Fatalf("err: %s", err)
}
defer os.Chdir(cwd)

if _, err := os.Create("issue518.tf"); err != nil {
t.Fatalf("err: %s", err)
}

ui := new(cli.MockUi)
c := &InitCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
},
}

args := []string{
".",
"foo",
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}

if _, err := os.Stat(filepath.Join(dir, "foo", "issue518.tf")); err != nil {
t.Fatalf("err: %s", err)
}
}
5 changes: 5 additions & 0 deletions config/module/copy_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func copyDir(dst, src string) error {
// If we have a directory, make that subdirectory, then continue
// the walk.
if info.IsDir() {
if path == filepath.Join(src, dst) {
// dst is in src; don't walk it.
return nil
}

if err := os.MkdirAll(dstPath, 0755); err != nil {
return err
}
Expand Down