Skip to content

Commit

Permalink
add a new test case for the IsLoaded method
Browse files Browse the repository at this point in the history
  • Loading branch information
asmsh committed Sep 8, 2024
1 parent 23c2952 commit 7af0403
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lazy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ func TestNew(t *testing.T) {
}
})

t.Run("not loaded then loaded", func(t *testing.T) {
value := lazy.NewValue(func() (int, error) {
return 123, errors.New("error")
})

gotBefore := value.IsLoaded()
if gotBefore != false {
t.Errorf("got %t, want %t", gotBefore, false)
}

value.Val() // or value.Err()

gotAfter := value.IsLoaded()
if gotAfter != true {
t.Errorf("got %t, want %t", gotAfter, true)
}
})

t.Run("concurrent reading", func(t *testing.T) {
value := lazy.NewValue(func() (int, error) {
return 123, errors.New("error")
Expand Down

0 comments on commit 7af0403

Please sign in to comment.