Support acceptance tests running with different configs

Store a library of configs to be used as the base gerrit.config during
tests. Specify at a per-acceptance_tests-rule level which of these
configs to generate rules for, passing in the config file via a system
property in a new rule named based on the config file name.

Include two additional labels for each test, "acceptance_config" and
"config_<name>", for including and excluding specific configs or all
non-default configs.

This preserves the behavior of running a single test class per VM, at
the cost of making it harder to run tests with nonstandard configs
from Eclipse. For that, developers can create custom run
configurations with different VM args passing the appropriate -D.

Change-Id: If29bcba26ac271479a63da836008b0f6608a1b6c
This commit is contained in:
Dave Borowitz
2014-01-15 14:24:33 -08:00
parent da93b83721
commit 88da34f7fc
6 changed files with 83 additions and 31 deletions

View File

@@ -14,36 +14,59 @@
package com.google.gerrit.acceptance;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Charsets;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
class ConfigAnnotationParser {
private static final String CONFIG_PKG =
"com.google.gerrit.acceptance.config.";
private static final String CONFIG_DIR = "/" + CONFIG_PKG.replace('.', '/');
private static Splitter splitter = Splitter.on(".").trimResults();
static Config parse(GerritConfigs annotation) {
static Config parseFromSystemProperty()
throws ConfigInvalidException, IOException {
Config cfg = new Config();
String name = System.getProperty(CONFIG_PKG + "BaseConfig");
if (!Strings.isNullOrEmpty(name)) {
String resource = CONFIG_DIR + name + ".config";
URL url = checkNotNull(ConfigAnnotationParser.class.getResource(resource),
"test config resource not found: %s", resource);
cfg.fromText(Resources.toString(url, Charsets.UTF_8));
}
return cfg;
}
static Config parse(Config base, GerritConfigs annotation) {
if (annotation == null) {
return null;
}
Config cfg = new Config();
Config cfg = new Config(base);
for (GerritConfig c : annotation.value()) {
parse(cfg, c);
parseAnnotation(cfg, c);
}
return cfg;
}
static Config parse(GerritConfig annotation) {
Config cfg = new Config();
parse(cfg, annotation);
static Config parse(Config base, GerritConfig annotation) {
Config cfg = new Config(base);
parseAnnotation(cfg, annotation);
return cfg;
}
static private void parse(Config cfg, GerritConfig c) {
static private void parseAnnotation(Config cfg, GerritConfig c) {
ArrayList<String> l = Lists.newArrayList(splitter.split(c.name()));
if (l.size() == 2) {
cfg.setString(l.get(0), null, l.get(1), c.value());