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:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user