use of com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_partiallyOverriddenSRIsIgnored.
@Test
public void submitRequirement_partiallyOverriddenSRIsIgnored() throws Exception {
// Create build-cop-override label
LabelDefinitionInput input = new LabelDefinitionInput();
input.function = "NoOp";
input.values = ImmutableMap.of("+1", "Override", " 0", "No Override");
gApi.projects().name(project.get()).label("build-cop-override").create(input).get();
// Allow to vote on the build-cop-override label.
projectOperations.project(project).forUpdate().add(TestProjectUpdate.allowLabel("build-cop-override").range(0, 1).ref("refs/*").group(REGISTERED_USERS).build()).update();
// Define submit requirement in root project.
configSubmitRequirement(allProjects, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.create("label:Code-Review=+1")).setOverrideExpression(SubmitRequirementExpression.of("label:build-cop-override=+1")).setAllowOverrideInChildProjects(true).build());
// Create Code-Review-Override label
gApi.projects().name(project.get()).label("Code-Review-Override").create(input).get();
// Allow to vote on the Code-Review-Override label.
projectOperations.project(project).forUpdate().add(TestProjectUpdate.allowLabel("Code-Review-Override").range(0, 1).ref("refs/*").group(REGISTERED_USERS).build()).update();
// Override submit requirement in project (requires Code-Review-Override+1 as override instead
// of build-cop-override+1), but do not set all required properties (submittability expression
// is missing). We update the project.config file directly in the remote repository, since
// trying to push such a submit requirement would be rejected by the commit validation.
projectOperations.project(project).forInvalidation().addProjectConfigUpdater(config -> config.setString(ProjectConfig.SUBMIT_REQUIREMENT, "Code-Review", ProjectConfig.KEY_SR_OVERRIDE_EXPRESSION, "label:Code-Review-Override=+1")).invalidate();
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
voteLabel(changeId, "Code-Review-Override", 1);
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
// The override expression in the project is satisfied, but it's ignored since the SR is
// incomplete.
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
voteLabel(changeId, "build-cop-override", 1);
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(2);
// The submit requirement is overridden now (the override expression in the child project is
// ignored)
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.OVERRIDDEN, /* isLegacy= */
false);
// Legacy requirement is coming from the label MaxWithBlock function. Still unsatisfied.
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
true);
}
Aggregations