command/push: send the context variables up

This commit is contained in:
Mitchell Hashimoto 2015-03-06 00:06:54 -08:00
parent a1b424d53f
commit d37d9ea6ef
2 changed files with 23 additions and 5 deletions

View File

@ -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
}

View File

@ -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) {