Merge "Test tracing git push for a project via config"
diff --git a/javatests/com/google/gerrit/acceptance/rest/TraceIT.java b/javatests/com/google/gerrit/acceptance/rest/TraceIT.java
index 568b2da..c675634 100644
--- a/javatests/com/google/gerrit/acceptance/rest/TraceIT.java
+++ b/javatests/com/google/gerrit/acceptance/rest/TraceIT.java
@@ -38,6 +38,7 @@
import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.acceptance.config.GerritConfig;
+import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.SubmitRecord;
@@ -68,6 +69,7 @@
import java.util.Optional;
import java.util.Set;
import org.apache.http.message.BasicHeader;
+import org.eclipse.jgit.junit.TestRepository;
import org.junit.Rule;
import org.junit.Test;
@@ -91,6 +93,7 @@
@Inject private ExtensionRegistry extensionRegistry;
@Inject private WorkQueue workQueue;
+ @Inject private ProjectOperations projectOperations;
@Test
public void restCallWithoutTrace() throws Exception {
@@ -594,6 +597,40 @@
}
@Test
+ @GerritConfig(name = "tracing.issue123.requestType", value = "GIT_RECEIVE")
+ @GerritConfig(name = "tracing.issue123.projectPattern", value = "traced-project")
+ public void traceGitReceiveForProject() throws Exception {
+ Project.NameKey tracedProject = projectOperations.newProject().name("traced-project").create();
+ TestRepository<?> tracedRepo = cloneProject(tracedProject);
+
+ TraceValidatingCommitValidationListener commitValidationListener =
+ new TraceValidatingCommitValidationListener();
+ try (Registration registration =
+ extensionRegistry.newRegistration().add(commitValidationListener)) {
+ PushOneCommit push = pushFactory.create(admin.newIdent(), tracedRepo);
+ PushOneCommit.Result r = push.to("refs/for/master");
+ r.assertOkStatus();
+ assertThat(commitValidationListener.traceId).isEqualTo("issue123");
+ assertThat(commitValidationListener.isLoggingForced).isTrue();
+ assertThat(commitValidationListener.tags.get("project")).containsExactly(tracedProject.get());
+ }
+
+ // other project is not traced
+ commitValidationListener = new TraceValidatingCommitValidationListener();
+ try (Registration registration =
+ extensionRegistry.newRegistration().add(commitValidationListener)) {
+ PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
+ PushOneCommit.Result r = push.to("refs/for/master");
+ r.assertOkStatus();
+ assertThat(commitValidationListener.traceId).isNull();
+ assertThat(commitValidationListener.isLoggingForced).isFalse();
+
+ // The logging tag with the project name is also set if tracing is off.
+ assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get());
+ }
+ }
+
+ @Test
@GerritConfig(name = "tracing.issue123.requestType", value = "FOO")
public void traceProjectInvalidRequestType() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =