Commit d73cbd37 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/vmware/common: make the dir private for LocalOutputDir

parent 50f8b2c1
...@@ -8,11 +8,11 @@ import ( ...@@ -8,11 +8,11 @@ import (
// LocalOutputDir is an OutputDir implementation where the directory // LocalOutputDir is an OutputDir implementation where the directory
// is on the local machine. // is on the local machine.
type LocalOutputDir struct { type LocalOutputDir struct {
Dir string dir string
} }
func (d *LocalOutputDir) DirExists() (bool, error) { func (d *LocalOutputDir) DirExists() (bool, error) {
_, err := os.Stat(d.Dir) _, err := os.Stat(d.dir)
return err == nil, nil return err == nil, nil
} }
...@@ -29,11 +29,11 @@ func (d *LocalOutputDir) ListFiles() ([]string, error) { ...@@ -29,11 +29,11 @@ func (d *LocalOutputDir) ListFiles() ([]string, error) {
return nil return nil
} }
return files, filepath.Walk(d.Dir, visit) return files, filepath.Walk(d.dir, visit)
} }
func (d *LocalOutputDir) MkdirAll() error { func (d *LocalOutputDir) MkdirAll() error {
return os.MkdirAll(d.Dir, 0755) return os.MkdirAll(d.dir, 0755)
} }
func (d *LocalOutputDir) Remove(path string) error { func (d *LocalOutputDir) Remove(path string) error {
...@@ -41,13 +41,13 @@ func (d *LocalOutputDir) Remove(path string) error { ...@@ -41,13 +41,13 @@ func (d *LocalOutputDir) Remove(path string) error {
} }
func (d *LocalOutputDir) RemoveAll() error { func (d *LocalOutputDir) RemoveAll() error {
return os.RemoveAll(d.Dir) return os.RemoveAll(d.dir)
} }
func (d *LocalOutputDir) SetOutputDir(path string) { func (d *LocalOutputDir) SetOutputDir(path string) {
d.Dir = path d.dir = path
} }
func (d *LocalOutputDir) String() string { func (d *LocalOutputDir) String() string {
return d.Dir return d.dir
} }
...@@ -13,7 +13,10 @@ func testOutputDir(t *testing.T) *LocalOutputDir { ...@@ -13,7 +13,10 @@ func testOutputDir(t *testing.T) *LocalOutputDir {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
os.RemoveAll(td) os.RemoveAll(td)
return &LocalOutputDir{Dir: td}
result := new(LocalOutputDir)
result.SetOutputDir(td)
return result
} }
func TestStepOutputDir_impl(t *testing.T) { func TestStepOutputDir_impl(t *testing.T) {
...@@ -34,13 +37,13 @@ func TestStepOutputDir(t *testing.T) { ...@@ -34,13 +37,13 @@ func TestStepOutputDir(t *testing.T) {
if _, ok := state.GetOk("error"); ok { if _, ok := state.GetOk("error"); ok {
t.Fatal("should NOT have error") t.Fatal("should NOT have error")
} }
if _, err := os.Stat(dir.Dir); err != nil { if _, err := os.Stat(dir.dir); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
// Test the cleanup // Test the cleanup
step.Cleanup(state) step.Cleanup(state)
if _, err := os.Stat(dir.Dir); err != nil { if _, err := os.Stat(dir.dir); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
} }
...@@ -53,7 +56,7 @@ func TestStepOutputDir_existsNoForce(t *testing.T) { ...@@ -53,7 +56,7 @@ func TestStepOutputDir_existsNoForce(t *testing.T) {
state.Put("dir", dir) state.Put("dir", dir)
// Make sure the dir exists // Make sure the dir exists
if err := os.MkdirAll(dir.Dir, 0755); err != nil { if err := os.MkdirAll(dir.dir, 0755); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
...@@ -67,7 +70,7 @@ func TestStepOutputDir_existsNoForce(t *testing.T) { ...@@ -67,7 +70,7 @@ func TestStepOutputDir_existsNoForce(t *testing.T) {
// Test the cleanup // Test the cleanup
step.Cleanup(state) step.Cleanup(state)
if _, err := os.Stat(dir.Dir); err != nil { if _, err := os.Stat(dir.dir); err != nil {
t.Fatal("should not delete dir") t.Fatal("should not delete dir")
} }
} }
...@@ -81,7 +84,7 @@ func TestStepOutputDir_existsForce(t *testing.T) { ...@@ -81,7 +84,7 @@ func TestStepOutputDir_existsForce(t *testing.T) {
state.Put("dir", dir) state.Put("dir", dir)
// Make sure the dir exists // Make sure the dir exists
if err := os.MkdirAll(dir.Dir, 0755); err != nil { if err := os.MkdirAll(dir.dir, 0755); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
...@@ -92,7 +95,7 @@ func TestStepOutputDir_existsForce(t *testing.T) { ...@@ -92,7 +95,7 @@ func TestStepOutputDir_existsForce(t *testing.T) {
if _, ok := state.GetOk("error"); ok { if _, ok := state.GetOk("error"); ok {
t.Fatal("should NOT have error") t.Fatal("should NOT have error")
} }
if _, err := os.Stat(dir.Dir); err != nil { if _, err := os.Stat(dir.dir); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
} }
...@@ -111,14 +114,14 @@ func TestStepOutputDir_cancel(t *testing.T) { ...@@ -111,14 +114,14 @@ func TestStepOutputDir_cancel(t *testing.T) {
if _, ok := state.GetOk("error"); ok { if _, ok := state.GetOk("error"); ok {
t.Fatal("should NOT have error") t.Fatal("should NOT have error")
} }
if _, err := os.Stat(dir.Dir); err != nil { if _, err := os.Stat(dir.dir); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
// Test cancel/halt // Test cancel/halt
state.Put(multistep.StateCancelled, true) state.Put(multistep.StateCancelled, true)
step.Cleanup(state) step.Cleanup(state)
if _, err := os.Stat(dir.Dir); err == nil { if _, err := os.Stat(dir.dir); err == nil {
t.Fatal("directory should not exist") t.Fatal("directory should not exist")
} }
} }
...@@ -137,14 +140,14 @@ func TestStepOutputDir_halt(t *testing.T) { ...@@ -137,14 +140,14 @@ func TestStepOutputDir_halt(t *testing.T) {
if _, ok := state.GetOk("error"); ok { if _, ok := state.GetOk("error"); ok {
t.Fatal("should NOT have error") t.Fatal("should NOT have error")
} }
if _, err := os.Stat(dir.Dir); err != nil { if _, err := os.Stat(dir.dir); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
// Test cancel/halt // Test cancel/halt
state.Put(multistep.StateHalted, true) state.Put(multistep.StateHalted, true)
step.Cleanup(state) step.Cleanup(state)
if _, err := os.Stat(dir.Dir); err == nil { if _, err := os.Stat(dir.dir); err == nil {
t.Fatal("directory should not exist") t.Fatal("directory should not exist")
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment