Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudStorageFileSystemProvider::setStorageOptions should warn if the constructor has already been called. #1190

Open
tylercunnion opened this issue Jun 5, 2023 · 0 comments
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.

Comments

@tylercunnion
Copy link

setStorageOptions is meant to facilitate testing by substituting in the StorageOptions of the user's choice (e.g., the in-memory local storage provided in this library). In short, it sets the StorageOptions which will be used when the constructor is called (by the NIO's service locator, on demand when creating a GCS Path object via Path::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 a Path 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:

  1. The setStorageOptions method is called...
  2. ..after the constructor for CloudStorageFileSystemProvider has been called...
  3. ...with a 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.

@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/java-storage-nio API. label Jun 5, 2023
@meredithslota meredithslota added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

2 participants