Fix the `resources` variable not reset after the resource manager is closed (#1105)

* Fix the resource variable not reset after the resource manager is closed

* Format code
master
chenquan 3 years ago committed by GitHub
parent e43357164c
commit d1bfb5ef61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,7 +33,8 @@ func (manager *ResourceManager) Close() error {
be.Add(err)
}
}
// reset resources
manager.resources = make(map[string]io.Closer)
return be.Err()
}

@ -44,3 +44,17 @@ func TestResourceManager_GetResourceError(t *testing.T) {
assert.NotNil(t, err)
}
}
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))
}

Loading…
Cancel
Save