mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
command: fix panic on show when state file is invalid or unavailable (#31444)
This commit is contained in:
@@ -905,6 +905,34 @@ func TestShow_planWithNonDefaultStateLineage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestShow_corruptStatefile(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
inputDir := "testdata/show-corrupt-statefile"
|
||||
testCopyDir(t, inputDir, td)
|
||||
defer testChdir(t, td)()
|
||||
|
||||
view, done := testView(t)
|
||||
c := &ShowCommand{
|
||||
Meta: Meta{
|
||||
testingOverrides: metaOverridesForProvider(testProvider()),
|
||||
View: view,
|
||||
},
|
||||
}
|
||||
|
||||
code := c.Run([]string{})
|
||||
output := done(t)
|
||||
|
||||
if code != 1 {
|
||||
t.Fatalf("unexpected exit status %d; want 1\ngot: %s", code, output.Stdout())
|
||||
}
|
||||
|
||||
got := output.Stderr()
|
||||
want := `Unsupported state file format`
|
||||
if !strings.Contains(got, want) {
|
||||
t.Errorf("unexpected output\ngot: %s\nwant:\n%s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// showFixtureSchema returns a schema suitable for processing the configuration
|
||||
// in testdata/show. This schema should be assigned to a mock provider
|
||||
// named "test".
|
||||
|
||||
Reference in New Issue
Block a user