Merge "Add support for custom Guice modules in tests"
This commit is contained in:
@@ -129,6 +129,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provider;
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -394,13 +395,14 @@ public abstract class AbstractDaemonTest {
|
||||
}
|
||||
|
||||
baseConfig.setInt("receive", null, "changeUpdateThreads", 4);
|
||||
Module module = createModule();
|
||||
if (classDesc.equals(methodDesc) && !classDesc.sandboxed() && !methodDesc.sandboxed()) {
|
||||
if (commonServer == null) {
|
||||
commonServer = GerritServer.initAndStart(classDesc, baseConfig);
|
||||
commonServer = GerritServer.initAndStart(classDesc, baseConfig, module);
|
||||
}
|
||||
server = commonServer;
|
||||
} else {
|
||||
server = GerritServer.initAndStart(methodDesc, baseConfig);
|
||||
server = GerritServer.initAndStart(methodDesc, baseConfig, module);
|
||||
}
|
||||
|
||||
server.getTestInjector().injectMembers(this);
|
||||
@@ -443,6 +445,11 @@ public abstract class AbstractDaemonTest {
|
||||
testRepo = cloneProject(project, getCloneAsAccount(description));
|
||||
}
|
||||
|
||||
/** Override to bind an additional Guice module */
|
||||
public Module createModule() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void initSsh() throws JSchException {
|
||||
if (testRequiresSsh
|
||||
&& SshMode.useSsh()
|
||||
|
@@ -252,10 +252,12 @@ public class GerritServer implements AutoCloseable {
|
||||
*
|
||||
* @param desc server description.
|
||||
* @param baseConfig default config values; merged with config from {@code desc}.
|
||||
* @param testSysModule additional Guice module to use.
|
||||
* @return started server.
|
||||
* @throws Exception
|
||||
*/
|
||||
public static GerritServer initAndStart(Description desc, Config baseConfig) throws Exception {
|
||||
public static GerritServer initAndStart(
|
||||
Description desc, Config baseConfig, @Nullable Module testSysModule) throws Exception {
|
||||
Path site = TempFileUtil.createTempDirectory().toPath();
|
||||
baseConfig = new Config(baseConfig);
|
||||
baseConfig.setString("gerrit", null, "basePath", site.resolve("git").toString());
|
||||
@@ -264,7 +266,7 @@ public class GerritServer implements AutoCloseable {
|
||||
if (!desc.memory()) {
|
||||
init(desc, baseConfig, site);
|
||||
}
|
||||
return start(desc, baseConfig, site, null, null, null);
|
||||
return start(desc, baseConfig, site, testSysModule, null, null);
|
||||
} catch (Exception e) {
|
||||
TempFileUtil.recursivelyDelete(site.toFile());
|
||||
throw e;
|
||||
|
Reference in New Issue
Block a user