1
0
mirror of https://github.com/google/nomulus synced 2025-12-23 06:15:42 +00:00

Create Users when setting up OT&E and Production registrars (#2488)

This commit is contained in:
Lai Jiang
2024-07-03 14:31:07 -04:00
committed by GitHub
parent 54c5a9450d
commit d86c002132
24 changed files with 705 additions and 312 deletions

View File

@@ -14,6 +14,8 @@
package google.registry.util;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.base.Ascii;
/** Registry environments. */
@@ -59,6 +61,20 @@ public enum RegistryEnvironment {
private static final boolean ON_JETTY =
Boolean.parseBoolean(System.getProperty(JETTY_PROPERTY, "false"));
/**
* A thread local boolean that can be set in tests to indicate some code is running in a local
* test server.
*
* <p>Certain API calls (like calls to Cloud Tasks) are hard to stub when they run in the test
* server because the test server does not allow arbitrary injection of dependencies. Instead,
* code running in the server can check this value and decide whether to skip these API calls.
*
* <p>The value is set to false by default and can only be set to true in unit test environment.
* It is set to {@code true} in {@code start()} and {@code false} in {@code stop()} in {@code
* TestServer}.
*/
private static final ThreadLocal<Boolean> IN_TEST_SERVER = ThreadLocal.withInitial(() -> false);
/** Sets this enum as the name of the registry environment. */
public RegistryEnvironment setup() {
return setup(SystemPropertySetter.PRODUCTION_IMPL);
@@ -81,4 +97,13 @@ public enum RegistryEnvironment {
public static boolean isOnJetty() {
return ON_JETTY;
}
public static void setIsInTestDriver(boolean value) {
checkState(RegistryEnvironment.get() == RegistryEnvironment.UNITTEST);
IN_TEST_SERVER.set(value);
}
public static boolean isInTestServer() {
return IN_TEST_SERVER.get();
}
}