Create/Set Label REST endpoints: Check for conflicting label names

ProjectConfig#loadLabelSections(Config) reports labels with names that
only differ by case as validation error, hence we should not allow to
create such labels, or update the label name so that it conflicts.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I8d55a7c7773c50a3be88007bc40d80ab24b786b7
This commit is contained in:
Edwin Kempin
2019-10-28 09:59:22 +01:00
parent af3e24d6bc
commit 725343b5de
4 changed files with 49 additions and 2 deletions

View File

@@ -100,6 +100,21 @@ public class CreateLabelIT extends AbstractDaemonTest {
assertThat(thrown).hasMessageThat().contains("label Code-Review already exists");
}
@Test
public void cannotCreateLabelWithNameThatConflicts() throws Exception {
ResourceConflictException thrown =
assertThrows(
ResourceConflictException.class,
() ->
gApi.projects()
.name(allProjects.get())
.label("code-review")
.create(new LabelDefinitionInput()));
assertThat(thrown)
.hasMessageThat()
.contains("label code-review conflicts with existing label Code-Review");
}
@Test
public void cannotCreateLabelWithInvalidName() throws Exception {
LabelDefinitionInput input = new LabelDefinitionInput();

View File

@@ -147,6 +147,23 @@ public class SetLabelIT extends AbstractDaemonTest {
assertThat(thrown).hasMessageThat().contains("name " + input.name + " already in use");
}
@Test
public void cannotSetNameIfNameConflicts() throws Exception {
configLabel("Foo-Review", LabelFunction.NO_OP);
configLabel("Bar-Review", LabelFunction.NO_OP);
LabelDefinitionInput input = new LabelDefinitionInput();
input.name = "bar-review";
ResourceConflictException thrown =
assertThrows(
ResourceConflictException.class,
() -> gApi.projects().name(project.get()).label("Foo-Review").update(input));
assertThat(thrown)
.hasMessageThat()
.contains("name bar-review conflicts with existing label Bar-Review");
}
@Test
public void updateFunction() throws Exception {
LabelDefinitionInput input = new LabelDefinitionInput();