Merge pull request #19100 from hashicorp/jbardin/command-tests

Backend config and command tests
This commit is contained in:
James Bardin 2018-10-17 13:10:21 -04:00 committed by GitHub
commit 9c2f3ebe17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 7 deletions

View File

@ -14,10 +14,16 @@ func (b *Local) CLIInit(opts *backend.CLIOpts) error {
b.OpValidation = opts.Validation b.OpValidation = opts.Validation
b.RunningInAutomation = opts.RunningInAutomation b.RunningInAutomation = opts.RunningInAutomation
// Only configure state paths if we didn't do so via the configure func. // configure any new cli options
if b.StatePath == "" { if opts.StatePath != "" {
b.StatePath = opts.StatePath b.StatePath = opts.StatePath
}
if opts.StateOutPath != "" {
b.StateOutPath = opts.StateOutPath b.StateOutPath = opts.StateOutPath
}
if opts.StateBackupPath != "" {
b.StateBackupPath = opts.StateBackupPath b.StateBackupPath = opts.StateBackupPath
} }

View File

@ -585,8 +585,9 @@ func TestApply_plan_backup(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
args := []string{ args := []string{
"-state-out", statePath, "-state", statePath,
"-backup", backupPath, "-backup", backupPath,
planPath, planPath,
} }
@ -964,7 +965,7 @@ func TestApply_state(t *testing.T) {
Name: "foo", Name: "foo",
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
&states.ResourceInstanceObjectSrc{ &states.ResourceInstanceObjectSrc{
AttrsJSON: []byte(`{"ami":"bar"}`), AttrsJSON: []byte(`{"ami":"foo"}`),
Status: states.ObjectReady, Status: states.ObjectReady,
}, },
addrs.ProviderConfig{Type: "test"}.Absolute(addrs.RootModuleInstance), addrs.ProviderConfig{Type: "test"}.Absolute(addrs.RootModuleInstance),
@ -1006,7 +1007,7 @@ func TestApply_state(t *testing.T) {
actual := p.PlanResourceChangeRequest.PriorState actual := p.PlanResourceChangeRequest.PriorState
expected := cty.ObjectVal(map[string]cty.Value{ expected := cty.ObjectVal(map[string]cty.Value{
"id": cty.NullVal(cty.String), "id": cty.NullVal(cty.String),
"ami": cty.StringVal("bar"), "ami": cty.StringVal("foo"),
}) })
if !expected.RawEquals(actual) { if !expected.RawEquals(actual) {
t.Fatalf("wrong prior state during plan\ngot: %#v\nwant: %#v", actual, expected) 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 actual = p.ApplyResourceChangeRequest.PriorState
expected = cty.ObjectVal(map[string]cty.Value{ expected = cty.ObjectVal(map[string]cty.Value{
"id": cty.NullVal(cty.String), "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) t.Fatalf("wrong prior state during apply\ngot: %#v\nwant: %#v", actual, expected)
} }

View File

@ -240,6 +240,12 @@ func (s *Filesystem) RefreshState() error {
} }
f, err := statefile.Read(reader) 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 there's no state we just assign the nil return value
if err != nil && err != statefile.ErrNoState { if err != nil && err != statefile.ErrNoState {
return err return err