Skip to content

Commit

Permalink
cli: Fix state mv exit code for missing resource (#29839)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrocb committed Feb 14, 2022
1 parent 7a20c07 commit aed7162
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/command/state_mv.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ func (c *StateMvCommand) Run(args []string) int {
msgInvalidSource,
fmt.Sprintf("Cannot move %s: does not match anything in the current state.", sourceAddr),
))
c.showDiagnostics(diags)
return 1
}
for _, rawAddrFrom := range sourceAddrs {
switch addrFrom := rawAddrFrom.(type) {
Expand Down
28 changes: 28 additions & 0 deletions internal/command/state_mv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,34 @@ func TestStateMvHelp(t *testing.T) {
}
}

func TestStateMvInvalidSourceAddress(t *testing.T) {
state := states.BuildState(func(s *states.SyncState) {})
statePath := testStateFile(t, state)

p := testProvider()
ui := new(cli.MockUi)
view, _ := testView(t)
c := &StateMvCommand{
StateMeta{
Meta: Meta{
testingOverrides: metaOverridesForProvider(p),
Ui: ui,
View: view,
},
},
}

args := []string{
"-state", statePath,
"foo.bar1",
"foo.bar2",
}
code := c.Run(args)
if code != 1 {
t.Fatalf("expected error code 1, got:\n%d", code)
}
}

const testStateMvOutputOriginal = `
test_instance.baz:
ID = foo
Expand Down

0 comments on commit aed7162

Please sign in to comment.