mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
70 lines
1.3 KiB
Go
70 lines
1.3 KiB
Go
package command
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
"github.com/mitchellh/cli"
|
|
)
|
|
|
|
func TestPush_noRemote(t *testing.T) {
|
|
tmp, cwd := testCwd(t)
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
ui := new(cli.MockUi)
|
|
c := &PushCommand{
|
|
Meta: Meta{
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
Ui: ui,
|
|
},
|
|
}
|
|
|
|
args := []string{}
|
|
if code := c.Run(args); code != 1 {
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
}
|
|
}
|
|
|
|
func TestPush_local(t *testing.T) {
|
|
tmp, cwd := testCwd(t)
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
s := terraform.NewState()
|
|
s.Serial = 5
|
|
conf, srv := testRemoteState(t, s, 200)
|
|
defer srv.Close()
|
|
|
|
s = terraform.NewState()
|
|
s.Serial = 10
|
|
s.Remote = conf
|
|
|
|
// Store the local state
|
|
statePath := filepath.Join(tmp, DefaultDataDir, DefaultStateFilename)
|
|
if err := os.MkdirAll(filepath.Dir(statePath), 0755); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
f, err := os.Create(statePath)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
err = terraform.WriteState(s, f)
|
|
f.Close()
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
ui := new(cli.MockUi)
|
|
c := &PushCommand{
|
|
Meta: Meta{
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
Ui: ui,
|
|
},
|
|
}
|
|
args := []string{}
|
|
if code := c.Run(args); code != 0 {
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
}
|
|
}
|