Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 34864a6

Browse files
committed
state: LocalState allows file to not exist
1 parent 579f102 commit 34864a6

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

state/local.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ func (s *LocalState) PersistState() error {
4444
func (s *LocalState) RefreshState() error {
4545
f, err := os.Open(s.Path)
4646
if err != nil {
47+
// It is okay if the file doesn't exist, we treat that as a nil state
48+
if os.IsNotExist(err) {
49+
s.state = nil
50+
return nil
51+
}
52+
4753
return err
4854
}
4955
defer f.Close()

state/local_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ func TestLocalState(t *testing.T) {
1414
TestState(t, ls)
1515
}
1616

17+
func TestLocalState_nonExist(t *testing.T) {
18+
ls := &LocalState{Path: "ishouldntexist"}
19+
if err := ls.RefreshState(); err != nil {
20+
t.Fatalf("err: %s", err)
21+
}
22+
23+
if state := ls.State(); state != nil {
24+
t.Fatalf("bad: %#v", state)
25+
}
26+
}
27+
1728
func TestLocalState_impl(t *testing.T) {
1829
var _ StateReader = new(LocalState)
1930
var _ StateWriter = new(LocalState)

0 commit comments

Comments
 (0)