Merge branch 'stable-2.12' into stable-2.13
* stable-2.12: Fix broken submit tests Add @Sandboxed annotation for classes and methods Add tests for submit whole topic on multiple projects/branches Update download-commands plugin It seems no longer necessary to run the submit tests sandboxed, so remove that annotation. Change-Id: I442ed6efc045bff51259b8d08915b8a1cc1e2eb0
This commit is contained in:
@@ -29,6 +29,7 @@ import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.primitives.Chars;
|
||||
import com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
@@ -322,7 +323,8 @@ public abstract class AbstractDaemonTest {
|
||||
baseConfig.setString("gerrit", null, "tempSiteDir",
|
||||
tempSiteDir.getRoot().getPath());
|
||||
baseConfig.setInt("receive", null, "changeUpdateThreads", 4);
|
||||
if (classDesc.equals(methodDesc)) {
|
||||
if (classDesc.equals(methodDesc) && !classDesc.sandboxed() &&
|
||||
!methodDesc.sandboxed()) {
|
||||
if (commonServer == null) {
|
||||
commonServer = GerritServer.start(classDesc, baseConfig);
|
||||
}
|
||||
@@ -940,4 +942,13 @@ public abstract class AbstractDaemonTest {
|
||||
(EmailHeader.String)message.headers().get("Reply-To");
|
||||
assertThat(replyTo.getString()).isEqualTo(email);
|
||||
}
|
||||
|
||||
protected TestRepository<?> createProjectWithPush(String name,
|
||||
@Nullable Project.NameKey parent,
|
||||
SubmitType submitType) throws Exception {
|
||||
Project.NameKey project = createProject(name, parent, true, submitType);
|
||||
grant(Permission.PUSH, project, "refs/heads/*");
|
||||
grant(Permission.SUBMIT, project, "refs/for/refs/heads/*");
|
||||
return cloneProject(project);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.eclipse.jgit.lib.RepositoryCache;
|
||||
import org.eclipse.jgit.util.FS;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -61,7 +62,8 @@ public class GerritServer {
|
||||
return new AutoValue_GerritServer_Description(
|
||||
configName,
|
||||
true, // @UseLocalDisk is only valid on methods.
|
||||
!hasNoHttpd(testDesc.getTestClass()),
|
||||
!has(NoHttpd.class, testDesc.getTestClass()),
|
||||
has(Sandboxed.class, testDesc.getTestClass()),
|
||||
null, // @GerritConfig is only valid on methods.
|
||||
null); // @GerritConfigs is only valid on methods.
|
||||
|
||||
@@ -73,14 +75,17 @@ public class GerritServer {
|
||||
configName,
|
||||
testDesc.getAnnotation(UseLocalDisk.class) == null,
|
||||
testDesc.getAnnotation(NoHttpd.class) == null
|
||||
&& !hasNoHttpd(testDesc.getTestClass()),
|
||||
&& !has(NoHttpd.class, testDesc.getTestClass()),
|
||||
testDesc.getAnnotation(Sandboxed.class) != null ||
|
||||
has(Sandboxed.class, testDesc.getTestClass()),
|
||||
testDesc.getAnnotation(GerritConfig.class),
|
||||
testDesc.getAnnotation(GerritConfigs.class));
|
||||
}
|
||||
|
||||
private static boolean hasNoHttpd(Class<?> clazz) {
|
||||
private static boolean has(
|
||||
Class<? extends Annotation> annotation, Class<?> clazz) {
|
||||
for (; clazz != null; clazz = clazz.getSuperclass()) {
|
||||
if (clazz.getAnnotation(NoHttpd.class) != null) {
|
||||
if (clazz.getAnnotation(annotation) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -90,6 +95,7 @@ public class GerritServer {
|
||||
@Nullable abstract String configName();
|
||||
abstract boolean memory();
|
||||
abstract boolean httpd();
|
||||
abstract boolean sandboxed();
|
||||
@Nullable abstract GerritConfig config();
|
||||
@Nullable abstract GerritConfigs configs();
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2016 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({TYPE, METHOD})
|
||||
@Retention(RUNTIME)
|
||||
public @interface Sandboxed {
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2016 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
@Sandboxed
|
||||
public class SandboxTest extends AbstractDaemonTest {
|
||||
@After
|
||||
public void addUser() throws Exception {
|
||||
gApi.accounts().create("sandboxuser");
|
||||
}
|
||||
|
||||
private void testUserNotPresent() throws Exception {
|
||||
assertThat(gApi.accounts().query("sandboxuser").get()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserNotPresent1() throws Exception {
|
||||
testUserNotPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserNotPresent2() throws Exception {
|
||||
testUserNotPresent();
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.SubscribeSection;
|
||||
import com.google.gerrit.extensions.client.SubmitType;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
@@ -74,14 +73,6 @@ public abstract class AbstractSubmoduleSubscription extends AbstractDaemonTest {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
protected TestRepository<?> createProjectWithPush(String name,
|
||||
@Nullable Project.NameKey parent, SubmitType submitType) throws Exception {
|
||||
Project.NameKey project = createProject(name, parent, submitType);
|
||||
grant(Permission.PUSH, project, "refs/heads/*");
|
||||
grant(Permission.SUBMIT, project, "refs/for/refs/heads/*");
|
||||
return cloneProject(project);
|
||||
}
|
||||
|
||||
protected TestRepository<?> createProjectWithPush(String name,
|
||||
@Nullable Project.NameKey parent) throws Exception {
|
||||
return createProjectWithPush(name, parent, getSubmitType());
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.acceptance.TestProjectInput;
|
||||
import com.google.gerrit.extensions.api.changes.SubmitInput;
|
||||
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||
import com.google.gerrit.extensions.client.ChangeStatus;
|
||||
import com.google.gerrit.extensions.client.InheritableBoolean;
|
||||
@@ -116,6 +117,86 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
assertThat(getRemoteHead().getId()).isEqualTo(change.getCommit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void submitWholeTopicMultipleProjects() throws Exception {
|
||||
assume().that(isSubmitWholeTopicEnabled()).isTrue();
|
||||
String topic = "test-topic";
|
||||
|
||||
// Create test projects
|
||||
TestRepository<?> repoA = createProjectWithPush(
|
||||
"project-a", null, getSubmitType());
|
||||
TestRepository<?> repoB = createProjectWithPush(
|
||||
"project-b", null, getSubmitType());
|
||||
|
||||
// Create changes on project-a
|
||||
PushOneCommit.Result change1 =
|
||||
createChange(repoA, "master", "Change 1", "a.txt", "content", topic);
|
||||
PushOneCommit.Result change2 =
|
||||
createChange(repoA, "master", "Change 2", "b.txt", "content", topic);
|
||||
|
||||
// Create changes on project-b
|
||||
PushOneCommit.Result change3 =
|
||||
createChange(repoB, "master", "Change 3", "a.txt", "content", topic);
|
||||
PushOneCommit.Result change4 =
|
||||
createChange(repoB, "master", "Change 4", "b.txt", "content", topic);
|
||||
|
||||
approve(change1.getChangeId());
|
||||
approve(change2.getChangeId());
|
||||
approve(change3.getChangeId());
|
||||
approve(change4.getChangeId());
|
||||
submit(change4.getChangeId());
|
||||
|
||||
String expectedTopic = name(topic);
|
||||
change1.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||
change2.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||
change3.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||
change4.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void submitWholeTopicMultipleBranchesOnSameProject() throws Exception {
|
||||
assume().that(isSubmitWholeTopicEnabled()).isTrue();
|
||||
String topic = "test-topic";
|
||||
|
||||
// Create test project
|
||||
String projectName = "project-a";
|
||||
TestRepository<?> repoA = createProjectWithPush(
|
||||
projectName, null, getSubmitType());
|
||||
|
||||
RevCommit initialHead =
|
||||
getRemoteHead(new Project.NameKey(name(projectName)), "master");
|
||||
|
||||
// Create the dev branch on the test project
|
||||
BranchInput in = new BranchInput();
|
||||
in.revision = initialHead.name();
|
||||
gApi.projects().name(name(projectName)).branch("dev").create(in);
|
||||
|
||||
// Create changes on master
|
||||
PushOneCommit.Result change1 =
|
||||
createChange(repoA, "master", "Change 1", "a.txt", "content", topic);
|
||||
PushOneCommit.Result change2 =
|
||||
createChange(repoA, "master", "Change 2", "b.txt", "content", topic);
|
||||
|
||||
// Create changes on dev
|
||||
repoA.reset(initialHead);
|
||||
PushOneCommit.Result change3 =
|
||||
createChange(repoA, "dev", "Change 3", "a.txt", "content", topic);
|
||||
PushOneCommit.Result change4 =
|
||||
createChange(repoA, "dev", "Change 4", "b.txt", "content", topic);
|
||||
|
||||
approve(change1.getChangeId());
|
||||
approve(change2.getChangeId());
|
||||
approve(change3.getChangeId());
|
||||
approve(change4.getChangeId());
|
||||
submit(change4.getChangeId());
|
||||
|
||||
String expectedTopic = name(topic);
|
||||
change1.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||
change2.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||
change3.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||
change4.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void submitWholeTopic() throws Exception {
|
||||
assume().that(isSubmitWholeTopicEnabled()).isTrue();
|
||||
@@ -134,6 +215,7 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
change1.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||
change2.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||
change3.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||
|
||||
// Check for the exact change to have the correct submitter.
|
||||
assertSubmitter(change3);
|
||||
// Also check submitters for changes submitted via the topic relationship.
|
||||
|
||||
Reference in New Issue
Block a user