Add test for nil *os.File in ReadState

This commit is contained in:
James Bardin 2017-02-09 16:06:07 -05:00
parent 0c1b138719
commit 92cea2478d

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -1577,6 +1578,20 @@ func TestReadStateNewVersion(t *testing.T) {
} }
} }
func TestReadStateEmptyOrNilFile(t *testing.T) {
var emptyState bytes.Buffer
_, err := ReadState(&emptyState)
if err != ErrNoState {
t.Fatal("expected ErrNostate, got", err)
}
var nilFile *os.File
_, err = ReadState(nilFile)
if err != ErrNoState {
t.Fatal("expected ErrNostate, got", err)
}
}
func TestReadStateTFVersion(t *testing.T) { func TestReadStateTFVersion(t *testing.T) {
type tfVersion struct { type tfVersion struct {
Version int `json:"version"` Version int `json:"version"`