mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
internal/states/statefile: TestReadErrNoState() (#440)
This commit is contained in:
parent
a127607a85
commit
69f3c97db7
34
internal/states/statefile/read_test.go
Normal file
34
internal/states/statefile/read_test.go
Normal file
@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package statefile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadErrNoState_emptyFile(t *testing.T) {
|
||||
emptyFile, err := os.Open("testdata/read/empty")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer emptyFile.Close()
|
||||
|
||||
_, err = Read(emptyFile)
|
||||
if !errors.Is(err, ErrNoState) {
|
||||
t.Fatalf("expected ErrNoState, got %T", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadErrNoState_nilFile(t *testing.T) {
|
||||
nilFile, err := os.Open("")
|
||||
if err == nil {
|
||||
t.Fatal("wrongly succeeded in opening non-existent file")
|
||||
}
|
||||
|
||||
_, err = Read(nilFile)
|
||||
if !errors.Is(err, ErrNoState) {
|
||||
t.Fatalf("expected ErrNoState, got %T", err)
|
||||
}
|
||||
}
|
0
internal/states/statefile/testdata/read/empty
vendored
Normal file
0
internal/states/statefile/testdata/read/empty
vendored
Normal file
Loading…
Reference in New Issue
Block a user