Acceptance tests: Always check error after SshSession.exec()

The GitUtil.createProject() method in particular was failing silently
in a surprising number of cases. Fix all of these, and add the error
message to the AssertionError in cases where it was checked.

Change-Id: Ibca7881edfe8be583a19cc08f2b942bf4a9bbfc3
This commit is contained in:
Dave Borowitz 2014-08-06 09:46:49 -07:00
parent cf31c84e8a
commit 2148bf294d
7 changed files with 12 additions and 69 deletions

View File

@ -100,6 +100,10 @@ public class GitUtil {
b.append("\"");
}
s.exec(b.toString());
if (s.hasError()) {
throw new IllegalStateException(
"gerrit create-project returned error: " + s.getError());
}
}
public static Git cloneProject(String url) throws GitAPIException, IOException {

View File

@ -14,8 +14,6 @@
package com.google.gerrit.acceptance.git;
import static com.google.gerrit.acceptance.GitUtil.cloneProject;
import static com.google.gerrit.acceptance.GitUtil.createProject;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@ -24,7 +22,6 @@ import com.google.common.collect.Iterables;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.NoHttpd;
import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.acceptance.SshSession;
import com.google.gerrit.common.data.AccessSection;
import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRule;
@ -33,7 +30,6 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.account.GroupCache;
@ -44,10 +40,8 @@ import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
@ -57,18 +51,12 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.RefSpec;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
@NoHttpd
public class SubmitOnPushIT extends AbstractDaemonTest {
@Inject
private SchemaFactory<ReviewDb> reviewDbProvider;
@Inject
private GitRepositoryManager repoManager;
@ -93,26 +81,6 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
@Inject
private PushOneCommit.Factory pushFactory;
private Project.NameKey project;
private Git git;
private ReviewDb db;
@Before
public void setUp() throws Exception {
project = new Project.NameKey("p");
SshSession sshSession = new SshSession(server, admin);
createProject(sshSession, project.get());
git = cloneProject(sshSession.getUrl() + "/" + project.get());
sshSession.close();
db = reviewDbProvider.open();
}
@After
public void cleanup() {
db.close();
}
@Test
public void submitOnPush() throws GitAPIException, OrmException,
IOException, ConfigInvalidException {

View File

@ -14,7 +14,6 @@
package com.google.gerrit.acceptance.git;
import static com.google.gerrit.acceptance.GitUtil.createProject;
import static com.google.gerrit.server.group.SystemGroupBackend.PROJECT_OWNERS;
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
import static org.junit.Assert.assertEquals;
@ -27,7 +26,6 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.common.data.AccessSection;
import com.google.gerrit.common.data.Permission;
import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.project.Util;
@ -44,8 +42,6 @@ public class VisibleRefFilterIT extends AbstractDaemonTest {
@Before
public void setUp() throws Exception {
project = new Project.NameKey("p");
createProject(sshSession, project.get());
setUpChanges();
setUpPermissions();
}

View File

@ -14,6 +14,7 @@
package com.google.gerrit.acceptance.rest.group;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.google.common.collect.Sets;
@ -47,6 +48,7 @@ public class DefaultGroupsIT extends AbstractDaemonTest {
public void defaultGroupsCreated_ssh() throws JSchException, IOException {
SshSession session = new SshSession(server, admin);
String result = session.exec("gerrit ls-groups");
assertFalse(session.getError(), session.hasError());
assertTrue(result.contains("Administrators"));
assertTrue(result.contains("Non-Interactive Users"));
session.close();

View File

@ -16,36 +16,26 @@ package com.google.gerrit.acceptance.rest.project;
import static com.google.gerrit.acceptance.GitUtil.checkout;
import static com.google.gerrit.acceptance.GitUtil.cloneProject;
import static com.google.gerrit.acceptance.GitUtil.createProject;
import static com.google.gerrit.acceptance.GitUtil.fetch;
import static org.junit.Assert.assertEquals;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.acceptance.SshSession;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.config.AllProjectsNameProvider;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Config;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
public class ProjectLevelConfigIT extends AbstractDaemonTest {
@Inject
private SchemaFactory<ReviewDb> reviewDbProvider;
@Inject
private ProjectCache projectCache;
@ -55,27 +45,10 @@ public class ProjectLevelConfigIT extends AbstractDaemonTest {
@Inject
private PushOneCommit.Factory pushFactory;
private ReviewDb db;
private SshSession sshSession;
private String project;
private Git git;
@Before
public void setUp() throws Exception {
sshSession = new SshSession(server, admin);
project = "p";
createProject(sshSession, project, null, true);
git = cloneProject(sshSession.getUrl() + "/" + project);
fetch(git, RefNames.REFS_CONFIG + ":refs/heads/config");
checkout(git, "refs/heads/config");
db = reviewDbProvider.open();
}
@After
public void cleanup() {
db.close();
}
@Test
@ -89,13 +62,13 @@ public class ProjectLevelConfigIT extends AbstractDaemonTest {
configName, cfg.toText());
push.to(git, RefNames.REFS_CONFIG);
ProjectState state = projectCache.get(new Project.NameKey(project));
ProjectState state = projectCache.get(project);
assertEquals(cfg.toText(), state.getConfig(configName).get().toText());
}
@Test
public void nonExistingConfig() {
ProjectState state = projectCache.get(new Project.NameKey(project));
ProjectState state = projectCache.get(project);
assertEquals("", state.getConfig("test.config").get().toText());
}
@ -125,7 +98,7 @@ public class ProjectLevelConfigIT extends AbstractDaemonTest {
configName, cfg.toText());
push.to(git, RefNames.REFS_CONFIG);
ProjectState state = projectCache.get(new Project.NameKey(project));
ProjectState state = projectCache.get(project);
Config expectedCfg = new Config();
expectedCfg.setString("s1", null, "k1", "childValue1");

View File

@ -42,7 +42,7 @@ public class BanCommitIT extends AbstractDaemonTest {
String response =
sshSession.exec("gerrit ban-commit " + project.get() + " "
+ c.getCommit().getName());
assertFalse(sshSession.hasError());
assertFalse(sshSession.getError(), sshSession.hasError());
assertFalse(response, response.toLowerCase(Locale.US).contains("error"));
PushResult pushResult = pushHead(git, "refs/heads/master", false);

View File

@ -76,7 +76,7 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
String response =
sshSession.exec("gerrit gc \"" + project1.get() + "\" \""
+ project2.get() + "\"");
assertFalse(sshSession.hasError());
assertFalse(sshSession.getError(), sshSession.hasError());
assertNoError(response);
gcAssert.assertHasPackFile(project1, project2);
gcAssert.assertHasNoPackFile(allProjects, project3);
@ -86,7 +86,7 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
@UseLocalDisk
public void testGcAll() throws JSchException, IOException {
String response = sshSession.exec("gerrit gc --all");
assertFalse(sshSession.hasError());
assertFalse(sshSession.getError(), sshSession.hasError());
assertNoError(response);
gcAssert.assertHasPackFile(allProjects, project1, project2, project3);
}