internal/states/statefile: TestReadErrNoState() (#440)

This commit is contained in:
Lars Lehtonen 2023-09-26 11:45:17 -07:00 committed by GitHub
parent a127607a85
commit 69f3c97db7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View 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)
}
}

View File