Add tests for project (re)creation and name case mismatch
Change-Id: I54589caaf117f7e96faf95f3be1f50710aa82e89
This commit is contained in:
@@ -18,14 +18,19 @@ import java.security.AccessController;
|
|||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
|
|
||||||
public final class HostPlatform {
|
public final class HostPlatform {
|
||||||
private static final boolean win32 = computeWin32();
|
private static final boolean win32 = compute("windows");
|
||||||
|
private static final boolean mac = compute("mac");
|
||||||
|
|
||||||
/** @return true if this JVM is running on a Windows platform. */
|
/** @return true if this JVM is running on a Windows platform. */
|
||||||
public static boolean isWin32() {
|
public static boolean isWin32() {
|
||||||
return win32;
|
return win32;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean computeWin32() {
|
public static boolean isMac() {
|
||||||
|
return mac;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean compute(String platform) {
|
||||||
final String osDotName =
|
final String osDotName =
|
||||||
AccessController.doPrivileged(new PrivilegedAction<String>() {
|
AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -34,7 +39,7 @@ public final class HostPlatform {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return osDotName != null
|
return osDotName != null
|
||||||
&& osDotName.toLowerCase().contains("windows");
|
&& osDotName.toLowerCase().contains(platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HostPlatform() {
|
private HostPlatform() {
|
||||||
|
|||||||
@@ -15,9 +15,11 @@
|
|||||||
package com.google.gerrit.server.git;
|
package com.google.gerrit.server.git;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static com.google.common.truth.TruthJUnit.assume;
|
||||||
|
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.config.SitePaths;
|
import com.google.gerrit.server.config.SitePaths;
|
||||||
|
import com.google.gerrit.server.util.HostPlatform;
|
||||||
import com.google.gerrit.testutil.TempFileUtil;
|
import com.google.gerrit.testutil.TempFileUtil;
|
||||||
import com.google.gwtorm.client.KeyUtil;
|
import com.google.gwtorm.client.KeyUtil;
|
||||||
import com.google.gwtorm.server.StandardKeyEncoder;
|
import com.google.gwtorm.server.StandardKeyEncoder;
|
||||||
@@ -34,6 +36,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class LocalDiskRepositoryManagerTest extends EasyMockSupport {
|
public class LocalDiskRepositoryManagerTest extends EasyMockSupport {
|
||||||
@@ -164,6 +167,21 @@ public class LocalDiskRepositoryManagerTest extends EasyMockSupport {
|
|||||||
repoManager.createRepository(new Project.NameKey("project\\rA"));
|
repoManager.createRepository(new Project.NameKey("project\\rA"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalStateException.class)
|
||||||
|
public void testProjectRecreation() throws Exception {
|
||||||
|
repoManager.createRepository(new Project.NameKey("a"));
|
||||||
|
repoManager.createRepository(new Project.NameKey("a"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalStateException.class)
|
||||||
|
public void testProjectRecreationAfterRestart() throws Exception {
|
||||||
|
repoManager.createRepository(new Project.NameKey("a"));
|
||||||
|
LocalDiskRepositoryManager newRepoManager =
|
||||||
|
new LocalDiskRepositoryManager(site, cfg);
|
||||||
|
newRepoManager.start();
|
||||||
|
newRepoManager.createRepository(new Project.NameKey("a"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOpenRepositoryCreatedDirectlyOnDisk() throws Exception {
|
public void testOpenRepositoryCreatedDirectlyOnDisk() throws Exception {
|
||||||
Project.NameKey projectA = new Project.NameKey("projectA");
|
Project.NameKey projectA = new Project.NameKey("projectA");
|
||||||
@@ -174,6 +192,42 @@ public class LocalDiskRepositoryManagerTest extends EasyMockSupport {
|
|||||||
assertThat(repoManager.list()).containsExactly(projectA);
|
assertThat(repoManager.list()).containsExactly(projectA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = RepositoryCaseMismatchException.class)
|
||||||
|
public void testNameCaseMismatch() throws Exception {
|
||||||
|
assume().that(HostPlatform.isWin32() || HostPlatform.isMac()).isTrue();
|
||||||
|
repoManager.createRepository(new Project.NameKey("a"));
|
||||||
|
repoManager.createRepository(new Project.NameKey("A"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = RepositoryCaseMismatchException.class)
|
||||||
|
public void testNameCaseMismatchWithSymlink() throws Exception {
|
||||||
|
assume().that(HostPlatform.isWin32() || HostPlatform.isMac()).isTrue();
|
||||||
|
Project.NameKey name = new Project.NameKey("a");
|
||||||
|
repoManager.createRepository(name);
|
||||||
|
createSymLink(name, "b.git");
|
||||||
|
repoManager.createRepository(new Project.NameKey("B"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = RepositoryCaseMismatchException.class)
|
||||||
|
public void testNameCaseMismatchAfterRestart() throws Exception {
|
||||||
|
assume().that(HostPlatform.isWin32() || HostPlatform.isMac()).isTrue();
|
||||||
|
Project.NameKey name = new Project.NameKey("a");
|
||||||
|
repoManager.createRepository(name);
|
||||||
|
|
||||||
|
LocalDiskRepositoryManager newRepoManager =
|
||||||
|
new LocalDiskRepositoryManager(site, cfg);
|
||||||
|
newRepoManager.start();
|
||||||
|
newRepoManager.createRepository(new Project.NameKey("A"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createSymLink(Project.NameKey project, String link)
|
||||||
|
throws IOException {
|
||||||
|
Path base = repoManager.getBasePath(project);
|
||||||
|
Path projectDir = base.resolve(project.get() + ".git");
|
||||||
|
Path symlink = base.resolve(link);
|
||||||
|
Files.createSymbolicLink(symlink, projectDir);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = RepositoryNotFoundException.class)
|
@Test(expected = RepositoryNotFoundException.class)
|
||||||
public void testOpenRepositoryInvalidName() throws Exception {
|
public void testOpenRepositoryInvalidName() throws Exception {
|
||||||
repoManager.openRepository(new Project.NameKey("project%?|<>A"));
|
repoManager.openRepository(new Project.NameKey("project%?|<>A"));
|
||||||
|
|||||||
Reference in New Issue
Block a user