|
|
|
@ -47,14 +47,28 @@ func TestResourceManager_GetResourceError(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestResourceManager_Close(t *testing.T) {
|
|
|
|
|
manager := NewResourceManager()
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
|
_, err := manager.GetResource("key", func() (io.Closer, error) {
|
|
|
|
|
return nil, errors.New("fail")
|
|
|
|
|
})
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
}
|
|
|
|
|
err := manager.Close()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, len(manager.resources))
|
|
|
|
|
|
|
|
|
|
if assert.NoError(t, manager.Close()) {
|
|
|
|
|
assert.Equal(t, 0, len(manager.resources))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestResourceManager_UseAfterClose(t *testing.T) {
|
|
|
|
|
manager := NewResourceManager()
|
|
|
|
|
_, err := manager.GetResource("key", func() (io.Closer, error) {
|
|
|
|
|
return nil, errors.New("fail")
|
|
|
|
|
})
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
if assert.NoError(t, manager.Close()) {
|
|
|
|
|
_, err = manager.GetResource("key", func() (io.Closer, error) {
|
|
|
|
|
return nil, errors.New("fail")
|
|
|
|
|
})
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|