Merge pull request #19100 from hashicorp/jbardin/command-tests
Backend config and command tests
This commit is contained in:
commit
9c2f3ebe17
|
@ -14,10 +14,16 @@ func (b *Local) CLIInit(opts *backend.CLIOpts) error {
|
|||
b.OpValidation = opts.Validation
|
||||
b.RunningInAutomation = opts.RunningInAutomation
|
||||
|
||||
// Only configure state paths if we didn't do so via the configure func.
|
||||
if b.StatePath == "" {
|
||||
// configure any new cli options
|
||||
if opts.StatePath != "" {
|
||||
b.StatePath = opts.StatePath
|
||||
}
|
||||
|
||||
if opts.StateOutPath != "" {
|
||||
b.StateOutPath = opts.StateOutPath
|
||||
}
|
||||
|
||||
if opts.StateBackupPath != "" {
|
||||
b.StateBackupPath = opts.StateBackupPath
|
||||
}
|
||||
|
||||
|
|
|
@ -585,8 +585,9 @@ func TestApply_plan_backup(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-state-out", statePath,
|
||||
"-state", statePath,
|
||||
"-backup", backupPath,
|
||||
planPath,
|
||||
}
|
||||
|
@ -964,7 +965,7 @@ func TestApply_state(t *testing.T) {
|
|||
Name: "foo",
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
||||
&states.ResourceInstanceObjectSrc{
|
||||
AttrsJSON: []byte(`{"ami":"bar"}`),
|
||||
AttrsJSON: []byte(`{"ami":"foo"}`),
|
||||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.ProviderConfig{Type: "test"}.Absolute(addrs.RootModuleInstance),
|
||||
|
@ -1006,7 +1007,7 @@ func TestApply_state(t *testing.T) {
|
|||
actual := p.PlanResourceChangeRequest.PriorState
|
||||
expected := cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.NullVal(cty.String),
|
||||
"ami": cty.StringVal("bar"),
|
||||
"ami": cty.StringVal("foo"),
|
||||
})
|
||||
if !expected.RawEquals(actual) {
|
||||
t.Fatalf("wrong prior state during plan\ngot: %#v\nwant: %#v", actual, expected)
|
||||
|
@ -1015,9 +1016,9 @@ func TestApply_state(t *testing.T) {
|
|||
actual = p.ApplyResourceChangeRequest.PriorState
|
||||
expected = cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.NullVal(cty.String),
|
||||
"ami": cty.StringVal("bar"),
|
||||
"ami": cty.StringVal("foo"),
|
||||
})
|
||||
if actual != expected {
|
||||
if !expected.RawEquals(actual) {
|
||||
t.Fatalf("wrong prior state during apply\ngot: %#v\nwant: %#v", actual, expected)
|
||||
}
|
||||
|
||||
|
|
|
@ -240,6 +240,12 @@ func (s *Filesystem) RefreshState() error {
|
|||
}
|
||||
|
||||
f, err := statefile.Read(reader)
|
||||
|
||||
// nothing to backup if there's no initial state
|
||||
if f == nil {
|
||||
s.writtenBackup = true
|
||||
}
|
||||
|
||||
// if there's no state we just assign the nil return value
|
||||
if err != nil && err != statefile.ErrNoState {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue