CloudStorageFileSystemProvider::setStorageOptions should warn if the constructor has already been called. #1190
Labels
api: storage
Issues related to the googleapis/java-storage-nio API.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
setStorageOptions
is meant to facilitate testing by substituting in theStorageOptions
of the user's choice (e.g., the in-memory local storage provided in this library). In short, it sets theStorageOptions
which will be used when the constructor is called (by the NIO's service locator, on demand when creating a GCSPath
object viaPath::of
).However, if the constructor has already been called (i.e., a GCS
Path
has already been created), this method will have no effect. This can create a problem within the test suite if aPath
object is created before one is expected (a test runs in a different order for example). The problem will present to the user when their test code tries to make a request to the real GCS API when it appears it should be calling the fake storage.There's not much way around this given the Singleton nature of the FileSystemProvider, the only remedy I would hope for is a warning under the following conditions:
setStorageOptions
method is called...CloudStorageFileSystemProvider
has been called...StorageOptions
argument that is not equal to the options the provider was constructed with (it's fine if we attempt to set the options to the value they already are, in fact if you have multiple test classes that need LocalStorage it's very likely to happen).This could alert the user that the test they are trying to run is not using the fake storage like they expect (though this will likely be obvious by the test failure) but more importantly why and what they can do to fix it.
The text was updated successfully, but these errors were encountered: