From b0eae2f002b20f6a406a271c04188ffd84599a29 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Mon, 17 Jul 2017 15:07:22 -0700 Subject: [PATCH] Test AllocDir.Copy --- client/allocdir/alloc_dir_test.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/client/allocdir/alloc_dir_test.go b/client/allocdir/alloc_dir_test.go index 7ed7c13b7..774d84ed3 100644 --- a/client/allocdir/alloc_dir_test.go +++ b/client/allocdir/alloc_dir_test.go @@ -16,6 +16,7 @@ import ( cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/client/testutil" "github.com/hashicorp/nomad/nomad/structs" + "github.com/kr/pretty" ) var ( @@ -50,7 +51,10 @@ var ( ) func testLogger() *log.Logger { - return log.New(os.Stderr, "", log.LstdFlags) + if testing.Verbose() { + return log.New(os.Stderr, "", log.LstdFlags) + } + return log.New(ioutil.Discard, "", log.LstdFlags) } // Test that AllocDir.Build builds just the alloc directory. @@ -409,6 +413,25 @@ func TestAllocDir_CreateDir(t *testing.T) { } } +// TestAllocDir_Copy asserts that AllocDir.Copy does a deep copy of itself and +// all TaskDirs. +func TestAllocDir_Copy(t *testing.T) { + a := NewAllocDir(testLogger(), "foo") + a.NewTaskDir("bar") + a.NewTaskDir("baz") + + b := a.Copy() + if diff := pretty.Diff(a, b); len(diff) > 0 { + t.Errorf("differences between copies: %# v", pretty.Formatter(diff)) + } + + // Make sure TaskDirs map is copied + a.NewTaskDir("new") + if b.TaskDirs["new"] != nil { + t.Errorf("TaskDirs map shared between copied") + } +} + func TestPathFuncs(t *testing.T) { dir, err := ioutil.TempDir("", "nomadtest-pathfuncs") if err != nil {