mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
command/push: send the context variables up
This commit is contained in:
parent
a1b424d53f
commit
d37d9ea6ef
@ -116,7 +116,11 @@ func (c *PushCommand) Run(args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Upsert!
|
// 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(
|
c.Ui.Error(fmt.Sprintf(
|
||||||
"An error occurred while uploading the module:\n\n%s", err))
|
"An error occurred while uploading the module:\n\n%s", err))
|
||||||
return 1
|
return 1
|
||||||
@ -152,27 +156,36 @@ func (c *PushCommand) Synopsis() string {
|
|||||||
// pushClient is implementd internally to control where pushes go. This is
|
// pushClient is implementd internally to control where pushes go. This is
|
||||||
// either to Atlas or a mock for testing.
|
// either to Atlas or a mock for testing.
|
||||||
type pushClient interface {
|
type pushClient interface {
|
||||||
Upsert(io.Reader, int64) error
|
Upsert(*pushUpsertOptions) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type pushUpsertOptions struct {
|
||||||
|
Archive *archive.Archive
|
||||||
|
Variables map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockPushClient struct {
|
type mockPushClient struct {
|
||||||
File string
|
File string
|
||||||
|
|
||||||
UpsertCalled bool
|
UpsertCalled bool
|
||||||
|
UpsertOptions *pushUpsertOptions
|
||||||
UpsertError error
|
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)
|
f, err := os.Create(c.File)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
|
data := opts.Archive
|
||||||
|
size := opts.Archive.Size
|
||||||
if _, err := io.CopyN(f, data, size); err != nil {
|
if _, err := io.CopyN(f, data, size); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.UpsertCalled = true
|
c.UpsertCalled = true
|
||||||
|
c.UpsertOptions = opts
|
||||||
return c.UpsertError
|
return c.UpsertError
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,11 @@ func TestPush_good(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
t.Fatalf("bad: %#v", actual)
|
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) {
|
func TestPush_noState(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user