From d37d9ea6ef0ef8ae58ed119558d87d429041fe3f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 6 Mar 2015 00:06:54 -0800 Subject: [PATCH] command/push: send the context variables up --- command/push.go | 23 ++++++++++++++++++----- command/push_test.go | 5 +++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/command/push.go b/command/push.go index 4e39e4ab16..3430a9ab88 100644 --- a/command/push.go +++ b/command/push.go @@ -116,7 +116,11 @@ func (c *PushCommand) Run(args []string) int { } // Upsert! - if err := c.client.Upsert(archiveR, archiveR.Size); err != nil { + opts := &pushUpsertOptions{ + Archive: archiveR, + Variables: ctx.Variables(), + } + if err := c.client.Upsert(opts); err != nil { c.Ui.Error(fmt.Sprintf( "An error occurred while uploading the module:\n\n%s", err)) return 1 @@ -152,27 +156,36 @@ func (c *PushCommand) Synopsis() string { // pushClient is implementd internally to control where pushes go. This is // either to Atlas or a mock for testing. type pushClient interface { - Upsert(io.Reader, int64) error + Upsert(*pushUpsertOptions) error +} + +type pushUpsertOptions struct { + Archive *archive.Archive + Variables map[string]string } type mockPushClient struct { File string - UpsertCalled bool - UpsertError error + UpsertCalled bool + UpsertOptions *pushUpsertOptions + UpsertError error } -func (c *mockPushClient) Upsert(data io.Reader, size int64) error { +func (c *mockPushClient) Upsert(opts *pushUpsertOptions) error { f, err := os.Create(c.File) if err != nil { return err } defer f.Close() + data := opts.Archive + size := opts.Archive.Size if _, err := io.CopyN(f, data, size); err != nil { return err } c.UpsertCalled = true + c.UpsertOptions = opts return c.UpsertError } diff --git a/command/push_test.go b/command/push_test.go index e15402246b..e6ee2dc180 100644 --- a/command/push_test.go +++ b/command/push_test.go @@ -58,6 +58,11 @@ func TestPush_good(t *testing.T) { if !reflect.DeepEqual(actual, expected) { t.Fatalf("bad: %#v", actual) } + + variables := make(map[string]string) + if !reflect.DeepEqual(client.UpsertOptions.Variables, variables) { + t.Fatalf("bad: %#v", client.UpsertOptions) + } } func TestPush_noState(t *testing.T) {