[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionoo/master] Add tests for "unreachable_or_addresses" field.



commit 550d60e01d4e44137739fc6d27c16863793d5a7f
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Thu Nov 16 21:33:56 2017 +0100

    Add tests for "unreachable_or_addresses" field.
---
 .../onionoo/writer/DetailsDocumentWriterTest.java  | 100 +++++++++++++++++++++
 1 file changed, 100 insertions(+)

diff --git a/src/test/java/org/torproject/onionoo/writer/DetailsDocumentWriterTest.java b/src/test/java/org/torproject/onionoo/writer/DetailsDocumentWriterTest.java
new file mode 100644
index 0000000..3356a9c
--- /dev/null
+++ b/src/test/java/org/torproject/onionoo/writer/DetailsDocumentWriterTest.java
@@ -0,0 +1,100 @@
+package org.torproject.onionoo.writer;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.torproject.onionoo.docs.DetailsDocument;
+import org.torproject.onionoo.docs.DetailsStatus;
+import org.torproject.onionoo.docs.DocumentStoreFactory;
+import org.torproject.onionoo.docs.DummyDocumentStore;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.TreeSet;
+
+public class DetailsDocumentWriterTest {
+
+  private DummyDocumentStore documentStore;
+
+  @Before
+  public void createDummyDocumentStore() {
+    this.documentStore = new DummyDocumentStore();
+    DocumentStoreFactory.setDocumentStore(this.documentStore);
+  }
+
+  @Test
+  public void testNoDetailsStatuses() {
+    DetailsDocumentWriter writer = new DetailsDocumentWriter();
+    writer.writeDocuments();
+    assertEquals("Without statuses, no documents should be written.", 0,
+        this.documentStore.getPerformedStoreOperations());
+  }
+
+  private static final String GABELMOO_FINGERPRINT =
+      "F2044413DAC2E02E3D6BCF4735A19BCA1DE97281";
+
+  private static final String GABELMOO_OR_ADDRESS =
+      "[2001:638:a000:4140::ffff:189]:443]";
+
+  @Test
+  public void testAdvertisedAndReachableOrAddress() {
+    DetailsStatus status = new DetailsStatus();
+    status.setRelay(true);
+    status.setAdvertisedOrAddresses(Arrays.asList(GABELMOO_OR_ADDRESS));
+    status.setOrAddressesAndPorts(new TreeSet<>(Arrays.asList(
+        GABELMOO_OR_ADDRESS)));
+    this.documentStore.addDocument(status, GABELMOO_FINGERPRINT);
+    DetailsDocumentWriter writer = new DetailsDocumentWriter();
+    writer.writeDocuments();
+    assertEquals("One document should be written.", 1,
+        this.documentStore.getPerformedStoreOperations());
+    DetailsDocument document = this.documentStore.getDocument(
+        DetailsDocument.class, GABELMOO_FINGERPRINT);
+    assertNotNull("There should be a document for the given fingerprint.",
+        document);
+    assertNull("Document should not contain any unreachable OR addresses.",
+        document.getUnreachableOrAddresses());
+  }
+
+  @Test
+  public void testUnadvertisedButSomehowReachableOrAddress() {
+    DetailsStatus status = new DetailsStatus();
+    status.setRelay(true);
+    status.setOrAddressesAndPorts(new TreeSet<>(Arrays.asList(
+        GABELMOO_OR_ADDRESS)));
+    this.documentStore.addDocument(status, GABELMOO_FINGERPRINT);
+    DetailsDocumentWriter writer = new DetailsDocumentWriter();
+    writer.writeDocuments();
+    assertEquals("One document should be written.", 1,
+        this.documentStore.getPerformedStoreOperations());
+    DetailsDocument document = this.documentStore.getDocument(
+        DetailsDocument.class, GABELMOO_FINGERPRINT);
+    assertNotNull("There should be a document for the given fingerprint.",
+        document);
+    assertNull("Document should not contain unreachable OR addresses.",
+        document.getUnreachableOrAddresses());
+  }
+
+  @Test
+  public void testAdvertisedButUnreachableOrAddress() {
+    DetailsStatus status = new DetailsStatus();
+    status.setRelay(true);
+    status.setAdvertisedOrAddresses(Arrays.asList(GABELMOO_OR_ADDRESS));
+    this.documentStore.addDocument(status, GABELMOO_FINGERPRINT);
+    DetailsDocumentWriter writer = new DetailsDocumentWriter();
+    writer.writeDocuments();
+    assertEquals("One document should be written.", 1,
+        this.documentStore.getPerformedStoreOperations());
+    DetailsDocument document = this.documentStore.getDocument(
+        DetailsDocument.class, GABELMOO_FINGERPRINT);
+    assertNotNull("There should be a document for the given fingerprint.",
+        document);
+    assertEquals("Document should contain one unreachable OR address.",
+        Arrays.asList(GABELMOO_OR_ADDRESS),
+        document.getUnreachableOrAddresses());
+  }
+}
+

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits