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