aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@verizonmedia.com>2020-01-20 00:04:36 +0100
committerValerij Fredriksen <valerijf@verizonmedia.com>2020-01-20 00:04:36 +0100
commitd03be2f4d75065076c4c117f279dcef32967b4fb (patch)
tree434c8ce6f0e8b88cb7f0159e7e5eaa0eb15c6c05 /node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl
parent9a693a19ee2fd6668da4cda58db6e56e108f2a5c (diff)
Produce smaller diff in FilterTableLineEditor
Diffstat (limited to 'node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl')
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditorTest.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditorTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditorTest.java
index 192422492c8..495c1318b71 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditorTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditorTest.java
@@ -6,6 +6,7 @@ import com.yahoo.vespa.hosted.node.admin.task.util.file.Editor;
import com.yahoo.vespa.hosted.node.admin.task.util.network.IPVersion;
import org.junit.Test;
+import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
@@ -37,6 +38,25 @@ public class FilterTableLineEditorTest {
"-A INPUT -j REJECT --reject-with icmp6-port-unreachable");
}
+ @Test
+ public void produces_minimal_diff_simple() {
+ assertFilterTableDiff(List.of(2, 5, 3, 6, 1, 4), List.of(2, 5, 6, 1, 4),
+ "Patching file table:\n" +
+ "--A INPUT -s 2001::3/128 -j ACCEPT\n");
+ }
+
+ @Test
+ public void produces_minimal_diff_complex() {
+ assertFilterTableDiff(List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), List.of(5, 11, 6, 3, 10, 4, 8, 12),
+ "Patching file table:\n" +
+ "--A INPUT -s 2001::1/128 -j ACCEPT\n" +
+ "--A INPUT -s 2001::2/128 -j ACCEPT\n" +
+ "+-A INPUT -s 2001::11/128 -j ACCEPT\n" +
+ "+-A INPUT -s 2001::12/128 -j ACCEPT\n" +
+ "--A INPUT -s 2001::7/128 -j ACCEPT\n" +
+ "--A INPUT -s 2001::9/128 -j ACCEPT\n");
+ }
+
private static void assertFilterTableLineEditorResult(
Acl acl, IPVersion ipVersion, String currentFilterTable, String expectedRestoreFileContent) {
FilterTableLineEditor filterLineEditor = FilterTableLineEditor.from(acl, ipVersion);
@@ -47,4 +67,19 @@ public class FilterTableLineEditorTest {
filterLineEditor);
editor.edit(m -> {});
}
+
+ private static void assertFilterTableDiff(List<Integer> currentIpSuffix, List<Integer> wantedIpSuffix, String diff) {
+ Acl.Builder currentAcl = new Acl.Builder();
+ currentIpSuffix.forEach(i -> currentAcl.withTrustedNode("host" + i, "2001::" + i));
+ List<String> currentTable = new ArrayList<>();
+
+ Acl.Builder wantedAcl = new Acl.Builder();
+ wantedIpSuffix.forEach(i -> wantedAcl.withTrustedNode("host" + i, "2001::" + i));
+
+ new Editor("table", List::of, currentTable::addAll, FilterTableLineEditor.from(currentAcl.build(), IPVersion.IPv6))
+ .edit(log -> {});
+
+ new Editor("table", () -> currentTable, result -> {}, FilterTableLineEditor.from(wantedAcl.build(), IPVersion.IPv6))
+ .edit(log -> assertEquals(diff, log));
+ }
} \ No newline at end of file