Adapt tests to compact JSON Since change I2f1cb91e9 Gerrit now always returns compact JSON. Adapt the test to this. Instead of doing string assertions on the JSON the find-owners tests should rather parse the JSON with GSON and then do assertions on the parsed objects so that the tests would not be affected by such a change. However since the find-owners plugin is deprecated (soon to be replace by the code-owners plugin) we don't want to invest time in rewriting these tests. ApiIT.getOwnersTest was already failing before, as the owner_revision field was not set in the expected response. While we are here, fix this too. Signed-off-by: Edwin Kempin <ekempin@google.com> Change-Id: I616b3fe74ac99fafdd986442751eb74c69c0ac5c (cherry picked from commit fabbbf05f30fb1bfd5c43f6065db5c6b6ffe7b31)
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/ApiIT.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/ApiIT.java index 078ac94..c5396af 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/findowners/ApiIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/ApiIT.java
@@ -46,10 +46,12 @@ ChangeInfo info2 = newChangeInfo("test2 GetOwners"); assertThat(info2._number).isEqualTo(info1._number + 1); String expected = - ")]}' { addDebugMsg:false, maxCacheAge:0, maxCacheSize:1000," - + " minOwnerVoteLevel:1, ownersFileName:OWNERS, rejectErrorInOwners:false," - + (" change:" + info1._number) - + ", patchset:1, file2owners:{}, reviewers:[], owners:[], files:[] }"; + ")]}' {addDebugMsg:false,maxCacheAge:0,maxCacheSize:1000," + + "minOwnerVoteLevel:1,ownersFileName:OWNERS,rejectErrorInOwners:false," + + ("change:" + info1._number) + + ",patchset:1," + + ("owner_revision:" + projectOperations.project(project).getHead(info1.branch).name()) + + ",file2owners:{},reviewers:[],owners:[],files:[]}"; Cache cache = getCache().init(0, 10); // reset, no Cache assertThat(cache.size()).isEqualTo(0L); // GetOwners GET API @@ -67,11 +69,11 @@ @Test public void requestErrorTest() throws Exception { PushOneCommit.Result c1 = createChange("1", "t.c", "##"); - assertThat(getOwnersResponse(c1)).contains("owners:[], files:[ t.c ]"); + assertThat(getOwnersResponse(c1)).contains("owners:[],files:[t.c]"); int id = c1.getChange().getId().get(); // Correct change id. String result = userRestSession.get("/changes/" + id + "/owners").getEntityContent(); - assertThat(filteredJson(result)).contains("owners:[], files:[ t.c ]"); + assertThat(filteredJson(result)).contains("owners:[],files:[t.c]"); // Wrong change number, 404 not found. RestResponse response = userRestSession.get("/changes/" + (id + 1) + "/owners"); assertThat(response.getStatusCode()).isEqualTo(404);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/ConfigIT.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/ConfigIT.java index 425fc9a..643d50b 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/findowners/ConfigIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/ConfigIT.java
@@ -88,20 +88,20 @@ String cXResponse = getOwnersDebugResponse(cX); String cBResponse = getOwnersDebugResponse(cB); String cYResponse = getOwnersDebugResponse(cY); - assertThat(cAResponse).contains(ownerX + ", files:[ tA.c ]"); - assertThat(cBResponse).contains(ownerY + ", files:[ tB.c ]"); - assertThat(cXResponse).contains(", files:[ tX.c ]"); - assertThat(cYResponse).contains(", files:[ tY.c ]"); + assertThat(cAResponse).contains(ownerX + ",files:[tA.c]"); + assertThat(cBResponse).contains(ownerY + ",files:[tB.c]"); + assertThat(cXResponse).contains(",files:[tX.c]"); + assertThat(cYResponse).contains(",files:[tY.c]"); assertThat(cXResponse).doesNotContain(ownerX); assertThat(cYResponse).doesNotContain(ownerY); assertThat(cAResponse).contains("branch:refs/heads/master"); assertThat(cBResponse).contains("branch:refs/heads/master"); assertThat(cXResponse).contains("branch:refs/heads/BranchX"); assertThat(cYResponse).contains("branch:refs/heads/BranchY"); - assertThat(cAResponse).contains("ownersFileName:OWNERS, "); - assertThat(cBResponse).contains("ownersFileName:OWNERS, "); - assertThat(cXResponse).contains("ownersFileName:OWNERS, "); - assertThat(cYResponse).contains("ownersFileName:OWNERS, "); + assertThat(cAResponse).contains("ownersFileName:OWNERS,"); + assertThat(cBResponse).contains("ownersFileName:OWNERS,"); + assertThat(cXResponse).contains("ownersFileName:OWNERS,"); + assertThat(cYResponse).contains("ownersFileName:OWNERS,"); // pA and pB use default OWNERS file name. // cA and cB logs should not contain anything about Missing/Found root. @@ -126,12 +126,12 @@ cBResponse = getOwnersDebugResponse(cB); cXResponse = getOwnersDebugResponse(cX); cYResponse = getOwnersDebugResponse(cY); - assertThat(cAResponse).contains("ownersFileName:OWNERS.alpha, "); - assertThat(cBResponse).contains("ownersFileName:OWNERS.beta, "); - assertThat(cXResponse).contains("ownersFileName:OWNERS.alpha, "); - assertThat(cYResponse).contains("ownersFileName:OWNERS.beta, "); - assertThat(cAResponse).contains(ownerA + ", files:[ tA.c ]"); - assertThat(cBResponse).contains(ownerB + ", files:[ tB.c ]"); + assertThat(cAResponse).contains("ownersFileName:OWNERS.alpha,"); + assertThat(cBResponse).contains("ownersFileName:OWNERS.beta,"); + assertThat(cXResponse).contains("ownersFileName:OWNERS.alpha,"); + assertThat(cYResponse).contains("ownersFileName:OWNERS.beta,"); + assertThat(cAResponse).contains(ownerA + ",files:[tA.c]"); + assertThat(cBResponse).contains(ownerB + ",files:[tB.c]"); // pA and pB now use non-default OWNERS file name. // cA and cB logs should contain "Found root ..." assertThat(cAResponse).contains("FoundrootOWNERS.alpha"); @@ -145,10 +145,10 @@ setProjectConfig("ownersFileName", "MAINTAINERS"); cAResponse = getOwnersDebugResponse(cA); cXResponse = getOwnersDebugResponse(cX); - assertThat(cAResponse).contains("ownersFileName:MAINTAINERS, "); - assertThat(cXResponse).contains("ownersFileName:MAINTAINERS, "); - assertThat(cAResponse).contains("owners:[], "); - assertThat(cXResponse).contains("owners:[], "); + assertThat(cAResponse).contains("ownersFileName:MAINTAINERS,"); + assertThat(cXResponse).contains("ownersFileName:MAINTAINERS,"); + assertThat(cAResponse).contains("owners:[],"); + assertThat(cXResponse).contains("owners:[],"); assertThat(cAResponse).contains("MissingrootMAINTAINERS"); // Gerrit server log file should contain: "Missing root MAINTAINERS for change " // cX is not on the master branch, so we do not check for the root owners file. @@ -160,8 +160,8 @@ assertThat(projectOwnersFileName(pA)).isEqualTo("OWNERS"); cAResponse = getOwnersDebugResponse(cA); cBResponse = getOwnersDebugResponse(cB); - assertThat(cAResponse).contains(ownerX + ", files:[ tA.c ]"); - assertThat(cBResponse).contains(ownerB + ", files:[ tB.c ]"); + assertThat(cAResponse).contains(ownerX + ",files:[tA.c]"); + assertThat(cBResponse).contains(ownerB + ",files:[tB.c]"); // Change back to OWNERS.alpha in Project_B, but there is no OWNERS.alpha switchProject(pB); @@ -170,10 +170,10 @@ cAResponse = getOwnersDebugResponse(cA); cBResponse = getOwnersDebugResponse(cB); cYResponse = getOwnersDebugResponse(cY); - assertThat(cAResponse).contains("ownersFileName:OWNERS, "); - assertThat(cBResponse).contains("ownersFileName:OWNERS.alpha, "); - assertThat(cAResponse).contains(ownerX + ", files:[ tA.c ]"); - assertThat(cBResponse).contains("owners:[], files:[ tB.c ]"); + assertThat(cAResponse).contains("ownersFileName:OWNERS,"); + assertThat(cBResponse).contains("ownersFileName:OWNERS.alpha,"); + assertThat(cAResponse).contains(ownerX + ",files:[tA.c]"); + assertThat(cBResponse).contains("owners:[],files:[tB.c]"); assertThat(cBResponse).contains("MissingrootOWNERS.alpha"); // Gerrit server log file should contain: "Missing root OWNERS.alpha for change " assertThat(cYResponse).doesNotContain("root"); @@ -192,8 +192,8 @@ RestResponse response = adminRestSession.get("/projects/?d"); String content = response.getEntityContent(); // Predefined projects: "All-Projects", "All-Users", project - assertThat(content).contains("\"id\": \"All-Projects\","); - assertThat(content).contains("\"id\": \"All-Users\","); + assertThat(content).contains("\"id\":\"All-Projects\","); + assertThat(content).contains("\"id\":\"All-Users\","); assertThat(content).contains(idProject("projectTest", "project")); assertThat(content).doesNotContain(idProject("projectTest", "ProjectA")); assertThat(content).doesNotContain(idProject("ProjectA"));
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwners.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwners.java index 47620fe..cab6f70 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwners.java +++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwners.java
@@ -63,15 +63,15 @@ } protected String oneOwnerList(String email) { - return "owners:[ " + ownerJson(email) + " ]"; + return "owners:[" + ownerJson(email) + "]"; } protected String ownerJson(String email) { - return "{ email:" + email + ", weights:[ 1, 0, 0 ] }"; + return "{email:" + email + ",weights:[1,0,0]}"; } protected String ownerJson(String email, int w1, int w2, int w3) { - return "{ email:" + email + ", weights:[ " + w1 + ", " + w2 + ", " + w3 + " ] }"; + return "{email:" + email + ",weights:[" + w1 + "," + w2 + "," + w3 + "]}"; } protected ChangeInfo newChangeInfo(String subject) throws Exception { @@ -225,7 +225,7 @@ protected String idProject(String name) { // Expected string of "id": "name",, - return "\"id\": \"" + name + "\","; + return "\"id\":\"" + name + "\","; } protected static void verifyRestResult(
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java index 9401fb2..53bc4f3 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java
@@ -30,7 +30,7 @@ @Rule public Watcher watcher = new Watcher(logger); private static String getRepoFileLog(String msg1, String msg2) { - return "getRepoFile:" + msg1 + ", getFile:" + msg2 + ", "; + return "getRepoFile:" + msg1 + ",getFile:" + msg2 + ","; } private static String concat(String s1, String s2) { @@ -46,45 +46,45 @@ // c2 and c1 are both submitted before existence of OWNERS. PushOneCommit.Result c2 = addFile("1", "t.c", "##"); // Submitted c2 still finds no owners before c1 is submitted. - assertThat(getOwnersResponse(c2)).contains("owners:[], files:[ t.c ]"); + assertThat(getOwnersResponse(c2)).contains("owners:[],files:[t.c]"); PushOneCommit.Result c1 = addFile("2", "OWNERS", "x@x\na@a\ninclude P1/P2 : f1\ninclude ./d1/d2/../../f2\n"); // Now c2 should find owners, but include directives find no repository or file. - String ownersAX = "owners:[ " + ownerJson("a@a") + ", " + ownerJson("x@x") + " ]"; - String path2owners = "path2owners:{ ./:[ a@a, x@x ] }"; - String owner2paths = "owner2paths:{ a@a:[ ./ ], x@x:[ ./ ] }"; + String ownersAX = "owners:[" + ownerJson("a@a") + "," + ownerJson("x@x") + "]"; + String path2owners = "path2owners:{./:[a@a,x@x]}"; + String owner2paths = "owner2paths:{a@a:[./],x@x:[./]}"; String projectName = project.get(); String expectedInLog = - concat("project:", projectName, ", ") - + "ownersFileName:OWNERS, " - + "getBranchId:refs/heads/master(FOUND), " - + "findOwnersFileFor:./t.c, " - + "findOwnersFileIn:., " + concat("project:", projectName, ",") + + "ownersFileName:OWNERS," + + "getBranchId:refs/heads/master(FOUND)," + + "findOwnersFileFor:./t.c," + + "findOwnersFileIn:.," + getRepoFileLog(projectName + ":refs/heads/master:./OWNERS", "OWNERS:(...)") - + "parseLine:include:P1/P2:f1, " - + "getRepoFile:P1/P2:refs/heads/master:f1, " - + "hasReadAccessException:project'P1/P2'isunavailable, " // cannot read - + "parseLine:include:(), " // missing file is treated as empty - + concat("parseLine:include:", projectName, ":./d1/d2/../../f2, ") + + "parseLine:include:P1/P2:f1," + + "getRepoFile:P1/P2:refs/heads/master:f1," + + "hasReadAccessException:project'P1/P2'isunavailable," // cannot read + + "parseLine:include:()," // missing file is treated as empty + + concat("parseLine:include:", projectName, ":./d1/d2/../../f2,") + getRepoFileLog(projectName + ":refs/heads/master:f2", "f2(NOTFOUND)") - + "parseLine:include:(), " // missing file is treated as empty - + "countNumOwners, " - + "findOwners, " - + "checkFile:./t.c, " - + "checkDir:., " - + "addOwnerWeightsIn:./ " - + "] "; + + "parseLine:include:()," // missing file is treated as empty + + "countNumOwners," + + "findOwners," + + "checkFile:./t.c," + + "checkDir:.," + + "addOwnerWeightsIn:./" + + "]"; String c2Response = getOwnersDebugResponse(c2); assertThat(c2Response).contains(path2owners); assertThat(c2Response).contains(owner2paths); - assertThat(c2Response).contains("file2owners:{ ./t.c:[ a@a, x@x ] }"); + assertThat(c2Response).contains("file2owners:{./t.c:[a@a,x@x]}"); assertThat(c2Response).contains(ownersAX); assertThat(c2Response).contains(expectedInLog); // A submitted change gets owners info from current repository. String c1Response = getOwnersDebugResponse(c1); assertThat(c1Response).contains(path2owners); assertThat(c1Response).contains(owner2paths); - assertThat(c1Response).contains("file2owners:{ ./OWNERS:[ a@a, x@x ] }"); + assertThat(c1Response).contains("file2owners:{./OWNERS:[a@a,x@x]}"); assertThat(c1Response).contains(ownersAX); } @@ -100,41 +100,40 @@ String ownerX = ownerJson("x@x"); String ownerG1 = ownerJson("g1@g"); String ownerG2 = ownerJson("g2@g"); - String ownersAG1G2X = - "owners:[ " + ownerA + ", " + ownerG1 + ", " + ownerG2 + ", " + ownerX + " ]"; - String path2owners = "path2owners:{ ./:[ a@a, g1@g, g2@g, x@x ] }"; - String owner2paths = "owner2paths:{ a@a:[ ./ ], g1@g:[ ./ ], g2@g:[ ./ ], x@x:[ ./ ] }"; + String ownersAG1G2X = "owners:[" + ownerA + "," + ownerG1 + "," + ownerG2 + "," + ownerX + "]"; + String path2owners = "path2owners:{./:[a@a,g1@g,g2@g,x@x]}"; + String owner2paths = "owner2paths:{a@a:[./],g1@g:[./],g2@g:[./],x@x:[./]}"; String projectName = project.get(); String expectedInLog = - concat("project:", projectName, ", ") - + "ownersFileName:OWNERS, " - + "getBranchId:refs/heads/master(FOUND), " - + "findOwnersFileFor:./t.c, " - + "findOwnersFileIn:., " + concat("project:", projectName, ",") + + "ownersFileName:OWNERS," + + "getBranchId:refs/heads/master(FOUND)," + + "findOwnersFileFor:./t.c," + + "findOwnersFileIn:.," + getRepoFileLog(projectName + ":refs/heads/master:./OWNERS", "OWNERS:(...)") - + "parseLine:include:P1/P2:f1, " - + "getRepoFile:P1/P2:refs/heads/master:f1, " - + "hasReadAccessException:project'P1/P2'isunavailable, " - + "parseLine:include:(), " // P1/P2 is still not found - + concat("parseLine:include:", projectName, ":./d1/d2/../../f2, ") + + "parseLine:include:P1/P2:f1," + + "getRepoFile:P1/P2:refs/heads/master:f1," + + "hasReadAccessException:project'P1/P2'isunavailable," + + "parseLine:include:()," // P1/P2 is still not found + + concat("parseLine:include:", projectName, ":./d1/d2/../../f2,") + getRepoFileLog(projectName + ":refs/heads/master:f2", "f2:(...)") - + "countNumOwners, " - + "findOwners, " - + "checkFile:./t.c, " - + "checkDir:., " - + "addOwnerWeightsIn:./ " - + "] "; + + "countNumOwners," + + "findOwners," + + "checkFile:./t.c," + + "checkDir:.," + + "addOwnerWeightsIn:./" + + "]"; String c2Response = getOwnersDebugResponse(c2); assertThat(c2Response).contains(path2owners); assertThat(c2Response).contains(owner2paths); - assertThat(c2Response).contains("file2owners:{ ./t.c:[ a@a, g1@g, g2@g, x@x ] }"); + assertThat(c2Response).contains("file2owners:{./t.c:[a@a,g1@g,g2@g,x@x]}"); assertThat(c2Response).contains(ownersAG1G2X); assertThat(c2Response).contains(expectedInLog); // A submitted change gets owners info from current repository. String c1Response = getOwnersDebugResponse(c1); assertThat(c1Response).contains(path2owners); assertThat(c1Response).contains(owner2paths); - assertThat(c1Response).contains("file2owners:{ ./OWNERS:[ a@a, g1@g, g2@g, x@x ] }"); + assertThat(c1Response).contains("file2owners:{./OWNERS:[a@a,g1@g,g2@g,x@x]}"); assertThat(c1Response).contains(ownersAG1G2X); } @@ -159,11 +158,11 @@ String ownerX = ownerJson("x@g", 0, 1, 0); assertThat(getOwnersResponse(c1)) .contains( - "owners:[ " - + concat(ownerD2, ", ") - + concat(ownerF2, ", ") - + concat(ownerD3, ", ") - + concat(ownerX, " ], files:[ d3/t.c ]")); + "owners:[" + + concat(ownerD2, ",") + + concat(ownerF2, ",") + + concat(ownerD3, ",") + + concat(ownerX, "],files:[d3/t.c]")); } @Test @@ -193,15 +192,14 @@ PushOneCommit.Result c22 = createChange("c22", "d3/d2/d2/t.c", "test"); // file and file - String owners11 = "file2owners:{ ./d3/d1/d1/t.c:" + "[ d1d1@g, d1d1d1@g, d3@g, d3d1d1@g ] }"; + String owners11 = "file2owners:{./d3/d1/d1/t.c:" + "[d1d1@g,d1d1d1@g,d3@g,d3d1d1@g]}"; // file and include - String owners12 = "file2owners:{ ./d3/d1/d2/t.c:" + "[ d1d2@g, d1d2d1@g, d3@g, d3d1d2@g ] }"; + String owners12 = "file2owners:{./d3/d1/d2/t.c:" + "[d1d2@g,d1d2d1@g,d3@g,d3d1d2@g]}"; // include and file - String owners21 = - "file2owners:{ ./d3/d2/d1/t.c:" + "[ d2d1@g, d2d1d1@g, d2d1p@g, d3@g, d3d2d1@g ] }"; + String owners21 = "file2owners:{./d3/d2/d1/t.c:" + "[d2d1@g,d2d1d1@g,d2d1p@g,d3@g,d3d2d1@g]}"; // include and include String owners22 = - "file2owners:{ ./d3/d2/d2/t.c:" + "[ d2d2@g, d2d2d1@g, d2d2d1p@g, d2d2p@g, d3d2d2@g ] }"; + "file2owners:{./d3/d2/d2/t.c:" + "[d2d2@g,d2d2d1@g,d2d2d1p@g,d2d2p@g,d3d2d2@g]}"; assertThat(getOwnersDebugResponse(c11)).contains(owners11); assertThat(getOwnersDebugResponse(c12)).contains(owners12); @@ -218,8 +216,8 @@ PushOneCommit.Result c1 = createChange("c1", "d2/d1/t.c", "test"); PushOneCommit.Result c2 = createChange("c2", "d2/d2/t.c", "test"); String projectName = project.get(); - String log1 = "parseLine:useSaved:file:" + projectName + "://d1/OWNERS, "; - String log2 = "parseLine:useSaved:include:" + projectName + ":/d1/OWNERS, "; + String log1 = "parseLine:useSaved:file:" + projectName + "://d1/OWNERS,"; + String log2 = "parseLine:useSaved:include:" + projectName + ":/d1/OWNERS,"; String response1 = getOwnersDebugResponse(c1); String response2 = getOwnersDebugResponse(c2); assertThat(response1).contains(log1); @@ -241,30 +239,29 @@ String response = getOwnersDebugResponse(c); String projectName = project.get(); String expectedInLog = - concat("project:", projectName, ", ") - + "ownersFileName:OWNERS, " - + "getBranchId:refs/heads/master(FOUND), " - + "findOwnersFileFor:./t.c, " - + "findOwnersFileIn:., " + concat("project:", projectName, ",") + + "ownersFileName:OWNERS," + + "getBranchId:refs/heads/master(FOUND)," + + "findOwnersFileFor:./t.c," + + "findOwnersFileIn:.," + getRepoFileLog(projectName + ":refs/heads/master:./OWNERS", "OWNERS:(...)") - + concat("parseLine:include:", projectName, ":./d1/../f1, ") + + concat("parseLine:include:", projectName, ":./d1/../f1,") + getRepoFileLog(projectName + ":refs/heads/master:f1", "f1:(...)") - + concat("parseLine:include:", projectName, ":./f2, ") + + concat("parseLine:include:", projectName, ":./f2,") + getRepoFileLog(projectName + ":refs/heads/master:f2", "f2:(...)") - + concat("parseLine:include:", projectName, ":d1/../f3, ") + + concat("parseLine:include:", projectName, ":d1/../f3,") + getRepoFileLog(projectName + ":refs/heads/master:f3", "f3:(...)") - + concat("parseLine:include:", projectName, ":/f4, ") + + concat("parseLine:include:", projectName, ":/f4,") + getRepoFileLog(projectName + ":refs/heads/master:f4", "f4:(...)") - + concat("parseLine:errorRecursion:include:", projectName, ":d2/../f2, ") - + "countNumOwners, " - + "findOwners, " - + "checkFile:./t.c, " - + "checkDir:., " - + "addOwnerWeightsIn:./ " - + "] "; - assertThat(response).contains("path2owners:{ ./:[ f1@g, f2@g, f3@g, f4@g, x@g ] }"); - assertThat(response) - .contains("owner2paths:{ f1@g:[ ./ ], f2@g:[ ./ ], f3@g:[ ./ ], f4@g:[ ./ ], x@g:[ ./ ] }"); + + concat("parseLine:errorRecursion:include:", projectName, ":d2/../f2,") + + "countNumOwners," + + "findOwners," + + "checkFile:./t.c," + + "checkDir:.," + + "addOwnerWeightsIn:./" + + "]"; + assertThat(response).contains("path2owners:{./:[f1@g,f2@g,f3@g,f4@g,x@g]}"); + assertThat(response).contains("owner2paths:{f1@g:[./],f2@g:[./],f3@g:[./],f4@g:[./],x@g:[./]}"); assertThat(response).contains(expectedInLog); } @@ -286,46 +283,46 @@ "f6@g\ninclude /d0/f0\ninclude ../d1/d2/f1\n" + "include ../d2/f2\ninclude /d2/d3/f3\ninclude /d2/../d4/d5/f5\ninclude /d4/f4\n"); String result = getOwnersDebugResponse(c); - assertThat(result).contains("{ ./d6/OWNERS:[ f0@g, f1@g, f2@g, f3@g, f4@g, f5@g, f6@g ] }"); + assertThat(result).contains("{./d6/OWNERS:[f0@g,f1@g,f2@g,f3@g,f4@g,f5@g,f6@g]}"); String projectName = project.get(); String skipLog = "parseLine:useSaved:include:" + projectName + ":"; for (String path : new String[] {"../../d0/f0", "../d0/f0", "../d2/f2", "/d2/f2", "/d4/f4"}) { assertThat(result).contains(skipLog + path); } String expectedInLog = - concat("project:", projectName, ", ") - + "ownersFileName:OWNERS, " - + "getBranchId:refs/heads/master(FOUND), " - + "findOwnersFileFor:./d6/OWNERS, " - + "findOwnersFileIn:./d6, " + concat("project:", projectName, ",") + + "ownersFileName:OWNERS," + + "getBranchId:refs/heads/master(FOUND)," + + "findOwnersFileFor:./d6/OWNERS," + + "findOwnersFileIn:./d6," + getRepoFileLog(projectName + ":refs/heads/master:./d6/OWNERS", "d6/OWNERS:(...)") - + concat("parseLine:include:", projectName, ":/d0/f0, ") + + concat("parseLine:include:", projectName, ":/d0/f0,") + getRepoFileLog(projectName + ":refs/heads/master:d0/f0", "d0/f0:(...)") - + concat("parseLine:include:", projectName, ":../d1/d2/f1, ") + + concat("parseLine:include:", projectName, ":../d1/d2/f1,") + getRepoFileLog(projectName + ":refs/heads/master:d1/d2/f1", "d1/d2/f1:(...)") - + concat("parseLine:useSaved:include:", projectName, ":../../d0/f0, ") - + concat("parseLine:include:", projectName, ":../d2/f2, ") + + concat("parseLine:useSaved:include:", projectName, ":../../d0/f0,") + + concat("parseLine:include:", projectName, ":../d2/f2,") + getRepoFileLog(projectName + ":refs/heads/master:d2/f2", "d2/f2:(...)") - + concat("parseLine:useSaved:include:", projectName, ":../d0/f0, ") - + concat("parseLine:include:", projectName, ":/d2/d3/f3, ") + + concat("parseLine:useSaved:include:", projectName, ":../d0/f0,") + + concat("parseLine:include:", projectName, ":/d2/d3/f3,") + getRepoFileLog(projectName + ":refs/heads/master:d2/d3/f3", "d2/d3/f3:(...)") - + concat("parseLine:useSaved:include:", projectName, ":/d0/f0, ") - + concat("parseLine:include:", projectName, ":/d2/../d4/d5/f5, ") + + concat("parseLine:useSaved:include:", projectName, ":/d0/f0,") + + concat("parseLine:include:", projectName, ":/d2/../d4/d5/f5,") + getRepoFileLog(projectName + ":refs/heads/master:d4/d5/f5", "d4/d5/f5:(...)") - + concat("parseLine:useSaved:include:", projectName, ":/d2/f2, ") - + concat("parseLine:include:", projectName, ":../f4, ") + + concat("parseLine:useSaved:include:", projectName, ":/d2/f2,") + + concat("parseLine:include:", projectName, ":../f4,") + getRepoFileLog(projectName + ":refs/heads/master:d4/f4", "d4/f4:(...)") - + concat("parseLine:useSaved:include:", projectName, ":../d2/f2, ") - + concat("parseLine:useSaved:include:", projectName, ":/d4/f4, ") - + "findOwnersFileIn:., " + + concat("parseLine:useSaved:include:", projectName, ":../d2/f2,") + + concat("parseLine:useSaved:include:", projectName, ":/d4/f4,") + + "findOwnersFileIn:.," + getRepoFileLog(projectName + ":refs/heads/master:./OWNERS", "OWNERS(NOTFOUND)") - + "countNumOwners, " - + "findOwners, " - + "checkFile:./d6/OWNERS, " - + "checkDir:./d6, " - + "checkDir:., " - + "addOwnerWeightsIn:./d6/ " - + "] "; + + "countNumOwners," + + "findOwners," + + "checkFile:./d6/OWNERS," + + "checkDir:./d6," + + "checkDir:.," + + "addOwnerWeightsIn:./d6/" + + "]"; assertThat(result).contains(expectedInLog); } @@ -351,14 +348,14 @@ // included: pA:d2/OWNERS, pA:d2/../f1, pA:d1/f1, pB:d2/f2, pB:d2/../f1, pB:./d1/f1 // inherited: pA:OWNERS String owners = - "owners:[ " - + concat(ownerJson("pAd1f1@g"), ", ") - + concat(ownerJson("pAd2@g"), ", ") - + concat(ownerJson("pAf1@g"), ", ") - + concat(ownerJson("pBd1f1@g"), ", ") - + concat(ownerJson("pBd2f2@g"), ", ") - + concat(ownerJson("pBf1@g"), ", ") - + concat(ownerJson("pA@g", 0, 1, 0), " ]"); + "owners:[" + + concat(ownerJson("pAd1f1@g"), ",") + + concat(ownerJson("pAd2@g"), ",") + + concat(ownerJson("pAf1@g"), ",") + + concat(ownerJson("pBd1f1@g"), ",") + + concat(ownerJson("pBd2f2@g"), ",") + + concat(ownerJson("pBf1@g"), ",") + + concat(ownerJson("pA@g", 0, 1, 0), "]"); assertThat(getOwnersResponse(c1)).contains(owners); } @@ -386,11 +383,11 @@ // inherited: pA:OWNERS // pB's OWNERS files are not readable String owners = - "owners:[ " - + concat(ownerJson("pAd1f1@g"), ", ") - + concat(ownerJson("pAd2@g"), ", ") - + concat(ownerJson("pAf1@g"), ", ") - + concat(ownerJson("pA@g", 0, 1, 0), " ]"); + "owners:[" + + concat(ownerJson("pAd1f1@g"), ",") + + concat(ownerJson("pAd2@g"), ",") + + concat(ownerJson("pAf1@g"), ",") + + concat(ownerJson("pA@g", 0, 1, 0), "]"); // The "owners:[...]" substring contains only owners from pA. assertThat(getOwnersResponse(c1)).contains(owners); }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/InheritanceIT.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/InheritanceIT.java index 9adb4f9..ab87398 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/findowners/InheritanceIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/InheritanceIT.java
@@ -42,10 +42,10 @@ addFile("4", "d2/OWNERS", "d2@g\nper-file OWNERS=d2o@g\nper-file *S=set noparent \n"); // Files that match per-file globs with set noparent do not inherit global default owners. // But include directive can include more per-file owners as in c3. - assertThat(getOwnersResponse(c1)).contains("{ ./d1/d1/OWNERS:[ d1d1o@g ] }"); - assertThat(getOwnersResponse(c2)).contains("{ ./d1/OWNERS:[ d1o@g ] }"); - assertThat(getOwnersResponse(c3)).contains("{ ./d2/d1/OWNERS:[ d1d1o@g, d2d1o@g ] }"); - assertThat(getOwnersResponse(c4)).contains("{ ./d2/OWNERS:[ d2o@g ] }"); + assertThat(getOwnersResponse(c1)).contains("{./d1/d1/OWNERS:[d1d1o@g]}"); + assertThat(getOwnersResponse(c2)).contains("{./d1/OWNERS:[d1o@g]}"); + assertThat(getOwnersResponse(c3)).contains("{./d2/d1/OWNERS:[d1d1o@g,d2d1o@g]}"); + assertThat(getOwnersResponse(c4)).contains("{./d2/OWNERS:[d2o@g]}"); } @Test @@ -58,15 +58,15 @@ PushOneCommit.Result c5 = addFile("5", "d2/d2/OWNERS", "d2d2@g\ninclude ../../d1/d2/OWNERS"); PushOneCommit.Result c6 = addFile("6", "d2/OWNERS", "d2@g\n"); // d1/d1/OWNERS sets noparent, does not inherit d1/OWNERS - assertThat(getOwnersResponse(c1)).contains("{ ./d1/d1/OWNERS:[ d1d1@g ] }"); + assertThat(getOwnersResponse(c1)).contains("{./d1/d1/OWNERS:[d1d1@g]}"); // d1/d2/OWNERS inherits d1/OWNERS - assertThat(getOwnersResponse(c2)).contains("{ ./d1/d2/OWNERS:[ d1@g, d1d2@g ] }"); - assertThat(getOwnersResponse(c3)).contains("{ ./d1/OWNERS:[ d1@g ] }"); + assertThat(getOwnersResponse(c2)).contains("{./d1/d2/OWNERS:[d1@g,d1d2@g]}"); + assertThat(getOwnersResponse(c3)).contains("{./d1/OWNERS:[d1@g]}"); // d2/d1/OWNERS includes d1/d1/OWNERS, does not inherit d1/OWNERS or d2/OWNERS - assertThat(getOwnersResponse(c4)).contains("{ ./d2/d1/OWNERS:[ d1d1@g, d2d1@g ] }"); + assertThat(getOwnersResponse(c4)).contains("{./d2/d1/OWNERS:[d1d1@g,d2d1@g]}"); // d2/d2/OWNERS includes d1/d1/OWNERS, inherit d2/OWNERS but not d1/OWNERS - assertThat(getOwnersResponse(c5)).contains("{ ./d2/d2/OWNERS:[ d1d2@g, d2@g, d2d2@g ] }"); - assertThat(getOwnersResponse(c6)).contains("{ ./d2/OWNERS:[ d2@g ] }"); + assertThat(getOwnersResponse(c5)).contains("{./d2/d2/OWNERS:[d1d2@g,d2@g,d2d2@g]}"); + assertThat(getOwnersResponse(c6)).contains("{./d2/OWNERS:[d2@g]}"); } @Test @@ -81,32 +81,32 @@ PushOneCommit.Result c2 = createChange("c2", "t.c", "Hello!"); String ownerA = ownerJson("a@a"); String ownerX = ownerJson("x@x"); - assertThat(getOwnersResponse(c2)).contains("owners:[ " + ownerX + " ], files:[ t.c ]"); + assertThat(getOwnersResponse(c2)).contains("owners:[" + ownerX + "],files:[t.c]"); // Add "d1/t.c" file, which is owned by ./d1 and root owners. PushOneCommit.Result c3 = createChange("c3", "d1/t.c", "Hello!"); String ownerX010 = ownerJson("x@x", 0, 1, 0); assertThat(getOwnersResponse(c3)) - .contains("owners:[ " + ownerA + ", " + ownerX010 + " ], files:[ d1/t.c ]"); + .contains("owners:[" + ownerA + "," + ownerX010 + "],files:[d1/t.c]"); // Add "d2/t.c" file, which is owned by ./d2 and root owners. PushOneCommit.Result c4 = createChange("c4", "d2/t.c", "Hello!"); String ownerY = ownerJson("y@y"); assertThat(getOwnersResponse(c4)) - .contains("owners:[ " + ownerY + ", " + ownerX010 + " ], files:[ d2/t.c ]"); + .contains("owners:[" + ownerY + "," + ownerX010 + "],files:[d2/t.c]"); // Add "d2/d1/t.c" file, which is owned by ./d2 and root owners. PushOneCommit.Result c5 = createChange("c5", "d2/d1/t.c", "Hello!"); assertThat(getOwnersResponse(c5)) - .contains("owners:[ " + ownerY + ", " + ownerX010 + " ], files:[ d2/d1/t.c ]"); + .contains("owners:[" + ownerY + "," + ownerX010 + "],files:[d2/d1/t.c]"); // Add "d3/t.c" file, which is owned only by ./d3 owners due to "set noparent". PushOneCommit.Result c6 = createChange("c6", "d3/t.c", "Hello!"); String ownerB = ownerJson("b@b"); - assertThat(getOwnersResponse(c6)).contains("owners:[ " + ownerB + " ], files:[ d3/t.c ]"); + assertThat(getOwnersResponse(c6)).contains("owners:[" + ownerB + "],files:[d3/t.c]"); // Add "d3/d1/t.c" file, which is owned only by ./d3 owners due to "set noparent". PushOneCommit.Result c7 = createChange("c7", "d3/d1/t.c", "Hello!"); - assertThat(getOwnersResponse(c7)).contains("owners:[ " + ownerB + " ], files:[ d3/d1/t.c ]"); + assertThat(getOwnersResponse(c7)).contains("owners:[" + ownerB + "],files:[d3/d1/t.c]"); // Add "d4/t.c" file, which is owned by ./d4 and ./d2 owners, but not root owners. PushOneCommit.Result c8 = createChange("c8", "d4/t.c", "Hello!"); String ownerZ = ownerJson("z@z"); assertThat(getOwnersResponse(c8)) - .contains("owners:[ " + ownerY + ", " + ownerZ + ", " + ownerX010 + " ], files:[ d4/t.c ]"); + .contains("owners:[" + ownerY + "," + ownerZ + "," + ownerX010 + "],files:[d4/t.c]"); } }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/PerFileIT.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/PerFileIT.java index 26fc914..d0fc00b 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/findowners/PerFileIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/PerFileIT.java
@@ -36,12 +36,12 @@ String ownerA = ownerJson("a@a"); String ownerB = ownerJson("b@b"); String ownerC = ownerJson("c@c"); - String ownerABC = "owners:[ " + ownerA + ", " + ownerB + ", " + ownerC; + String ownerABC = "owners:[" + ownerA + "," + ownerB + "," + ownerC; String ownerX = ownerJson("x@x"); - assertThat(getOwnersResponse(c2)).contains(ownerABC + ", " + ownerX + " ], files:[ t.c ]"); + assertThat(getOwnersResponse(c2)).contains(ownerABC + "," + ownerX + "],files:[t.c]"); // Add "t.txt" file, which has only global default owners. PushOneCommit.Result c3 = createChange("3", "t.txt", "Test!"); - assertThat(getOwnersResponse(c3)).contains(ownerABC + " ], files:[ t.txt ]"); + assertThat(getOwnersResponse(c3)).contains(ownerABC + "],files:[t.txt]"); } @Test @@ -54,8 +54,8 @@ PushOneCommit.Result c2 = createChange("c2", "t.c", "test"); String c1Response = getOwnersDebugResponse(c1); String c2Response = getOwnersDebugResponse(c2); - assertThat(c1Response).contains("file2owners:{ ./x.c:[ a@a, x@x ] }"); - assertThat(c2Response).contains("file2owners:{ ./t.c:[ *, a@a, m2@g, m@g, t1@g, x@x ] }"); + assertThat(c1Response).contains("file2owners:{./x.c:[a@a,x@x]}"); + assertThat(c2Response).contains("file2owners:{./t.c:[*,a@a,m2@g,m@g,t1@g,x@x]}"); } @Test @@ -66,11 +66,10 @@ PushOneCommit.Result c3 = addFile("3", "d2/d1/OWNERS", "d2d1@g\ninclude ../../d1/d1/OWNERS\n"); PushOneCommit.Result c4 = addFile("4", "d2/OWNERS", "d2@g\nper-file OWNERS=d2o@g"); // Files that match per-file globs now inherit global default owners. - assertThat(getOwnersResponse(c1)) - .contains("{ ./d1/d1/OWNERS:[ d1@g, d1d1@g, d1d1o@g, d1o@g ] }"); - assertThat(getOwnersResponse(c2)).contains("{ ./d1/OWNERS:[ d1@g, d1o@g ] }"); + assertThat(getOwnersResponse(c1)).contains("{./d1/d1/OWNERS:[d1@g,d1d1@g,d1d1o@g,d1o@g]}"); + assertThat(getOwnersResponse(c2)).contains("{./d1/OWNERS:[d1@g,d1o@g]}"); assertThat(getOwnersResponse(c3)) - .contains("{ ./d2/d1/OWNERS:[ d1d1@g, d1d1o@g, d2@g, d2d1@g, d2o@g ] }"); - assertThat(getOwnersResponse(c4)).contains("{ ./d2/OWNERS:[ d2@g, d2o@g ] }"); + .contains("{./d2/d1/OWNERS:[d1d1@g,d1d1o@g,d2@g,d2d1@g,d2o@g]}"); + assertThat(getOwnersResponse(c4)).contains("{./d2/OWNERS:[d2@g,d2o@g]}"); } }