File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,6 +44,12 @@ func (s *LocalState) PersistState() error {
4444func (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 ()
Original file line number Diff line number Diff 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+
1728func TestLocalState_impl (t * testing.T ) {
1829 var _ StateReader = new (LocalState )
1930 var _ StateWriter = new (LocalState )
You can’t perform that action at this time.
0 commit comments