From 583cc350a9ebffecdd4c33ebec61f06c48298d02 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 6 Jul 2017 13:49:26 -0400 Subject: [PATCH 1/2] fix minor races in workspace tests The improved err scanner loop in meta causes these to race. There's no need to write back to the same commands struct, so just use a new instance in each iteration. --- command/workspace_command_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/command/workspace_command_test.go b/command/workspace_command_test.go index 778dbd01a9..cfa261b485 100644 --- a/command/workspace_command_test.go +++ b/command/workspace_command_test.go @@ -74,14 +74,14 @@ func TestWorkspace_createAndList(t *testing.T) { t.Fatal(err) } - newCmd := &WorkspaceNewCommand{} - envs := []string{"test_a", "test_b", "test_c"} // create multiple workspaces for _, env := range envs { ui := new(cli.MockUi) - newCmd.Meta = Meta{Ui: ui} + newCmd := &WorkspaceNewCommand{ + Meta: Meta{Ui: ui}, + } if code := newCmd.Run([]string{env}); code != 0 { t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter) } @@ -179,14 +179,14 @@ func TestWorkspace_createInvalid(t *testing.T) { defer os.RemoveAll(td) defer testChdir(t, td)() - newCmd := &WorkspaceNewCommand{} - envs := []string{"test_a*", "test_b/foo", "../../../test_c", "好_d"} // create multiple workspaces for _, env := range envs { ui := new(cli.MockUi) - newCmd.Meta = Meta{Ui: ui} + newCmd := &WorkspaceNewCommand{ + Meta: Meta{Ui: ui}, + } if code := newCmd.Run([]string{env}); code == 0 { t.Fatalf("expected failure: \n%s", ui.OutputWriter) } From c66dd48b6e1e0350119810f80d46845806156cec Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 6 Jul 2017 16:25:47 -0400 Subject: [PATCH 2/2] make shadow.Value a Locker This way it's correctly handled by CopyStructure --- helper/shadow/value.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/helper/shadow/value.go b/helper/shadow/value.go index 2413335b80..178b7e78ad 100644 --- a/helper/shadow/value.go +++ b/helper/shadow/value.go @@ -26,6 +26,14 @@ type Value struct { valueSet bool } +func (v *Value) Lock() { + v.lock.Lock() +} + +func (v *Value) Unlock() { + v.lock.Unlock() +} + // Close closes the value. This can never fail. For a definition of // "close" see the struct docs. func (w *Value) Close() error {