Browse Source

minor cleanups for tests:
- generate queries in the code instead of using wire-format data.
it doesn't make much sense to use wire-format test data for valid
messages in terms of readability and maintainability.
- don't use a public name in tests. we should use reserved domains
for doc/tests.

I'm directly committing this to trunk. The changes may not be super trivial,
but they are basically straightforward translation (+ minor change of a
test domain name). so I think it's not worth wasting time of other developers.
the tests pass with these changes, of course.


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@2510 e5f2f494-b856-4b98-b285-d166d9295462

JINMEI Tatuya 14 years ago
parent
commit
d827adcf61

+ 50 - 30
src/lib/datasrc/tests/datasrc_unittest.cc

@@ -193,8 +193,8 @@ TEST_F(DataSrcTest, QueryClassAny) {
 }
 
 TEST_F(DataSrcTest, NSQuery) {
-    readAndProcessQuery("q_example_ns");
-
+    createAndProcessQuery(Name("example.com"), RRClass::IN(),
+                          RRType::NS());
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 0, 6);
 
     RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -216,7 +216,8 @@ TEST_F(DataSrcTest, NSQuery) {
 
 // Make sure two successive queries have the same result
 TEST_F(DataSrcTest, DuplicateQuery) {
-    readAndProcessQuery("q_example_ns");
+    createAndProcessQuery(Name("example.com"), RRClass::IN(),
+                          RRType::NS());
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 0, 6);
 
     RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -236,7 +237,8 @@ TEST_F(DataSrcTest, DuplicateQuery) {
     EXPECT_TRUE(it->isLast());
 
     msg.clear(Message::PARSE);
-    readAndProcessQuery("q_example_ns");
+    createAndProcessQuery(Name("example.com"), RRClass::IN(),
+                          RRType::NS());
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 0, 6);
 
     rit = msg.beginSection(Section::ANSWER());
@@ -257,7 +259,8 @@ TEST_F(DataSrcTest, DuplicateQuery) {
 }
 
 TEST_F(DataSrcTest, DNSKEYQuery) {
-    readAndProcessQuery("q_example_dnskey");
+    createAndProcessQuery(Name("example.com"), RRClass::IN(),
+                          RRType::DNSKEY());
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 4, 6);
 
     RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -271,7 +274,8 @@ TEST_F(DataSrcTest, DNSKEYQuery) {
 // We query for a record at a zone cut to ensure the REFERRAL flag doesn't
 // cause incorrect behavior.
 TEST_F(DataSrcTest, DNSKEYDuplicateQuery) {
-    readAndProcessQuery("q_example_dnskey");
+    createAndProcessQuery(Name("example.com"), RRClass::IN(),
+                          RRType::DNSKEY());
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 4, 6);
 
     RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -281,9 +285,8 @@ TEST_F(DataSrcTest, DNSKEYDuplicateQuery) {
     EXPECT_EQ(RRClass::IN(), rrset->getClass());
 
     msg.clear(Message::PARSE);
-    readAndProcessQuery("q_example_dnskey");
-    headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 4, 6);
-
+    createAndProcessQuery(Name("example.com"), RRClass::IN(),
+                          RRType::DNSKEY());
     rit = msg.beginSection(Section::ANSWER());
     rrset = *rit;
     EXPECT_EQ(Name("example.com"), rrset->getName());
@@ -292,7 +295,8 @@ TEST_F(DataSrcTest, DNSKEYDuplicateQuery) {
 }
 
 TEST_F(DataSrcTest, NxRRset) {
-    readAndProcessQuery("q_example_ptr");
+    createAndProcessQuery(Name("example.com"), RRClass::IN(),
+                          RRType::PTR());
 
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 0, 4, 0);
 
@@ -303,7 +307,8 @@ TEST_F(DataSrcTest, NxRRset) {
 }
 
 TEST_F(DataSrcTest, Nxdomain) {
-    readAndProcessQuery("q_glork");
+    createAndProcessQuery(Name("glork.example.com"), RRClass::IN(),
+                          RRType::A());
 
     headerCheck(msg, Rcode::NXDOMAIN(), true, true, true, 0, 6, 0);
 
@@ -316,7 +321,8 @@ TEST_F(DataSrcTest, Nxdomain) {
 }
 
 TEST_F(DataSrcTest, NxZone) {
-    readAndProcessQuery("q_spork");
+    createAndProcessQuery(Name("spork.example"), RRClass::IN(),
+                          RRType::A());
 
     headerCheck(msg, Rcode::REFUSED(), true, false, true, 0, 0, 0);
 
@@ -327,7 +333,8 @@ TEST_F(DataSrcTest, NxZone) {
 }
 
 TEST_F(DataSrcTest, Wildcard) {
-    readAndProcessQuery("q_wild_a");
+    createAndProcessQuery(Name("www.wild.example.com"), RRClass::IN(),
+                          RRType::A());
 
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 6, 6);
 
@@ -380,17 +387,18 @@ TEST_F(DataSrcTest, Wildcard) {
 }
 
 TEST_F(DataSrcTest, WildcardNodata) {
-
     // Check that a query for a data type not covered by the wildcard
     // returns NOERROR
-    readAndProcessQuery("q_wild_aaaa");
+    createAndProcessQuery(Name("www.wild.example.com"), RRClass::IN(),
+                          RRType::AAAA());
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 0, 2, 0);
 }
 
 TEST_F(DataSrcTest, WildcardCname) {
     // Check that wildcard answers containing CNAMES are followed
     // correctly
-    readAndProcessQuery("q_wild2_a");
+    createAndProcessQuery(Name("www.wild2.example.com"), RRClass::IN(),
+                          RRType::A());
 
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 6, 6);
 
@@ -458,7 +466,8 @@ TEST_F(DataSrcTest, WildcardCname) {
 TEST_F(DataSrcTest, WildcardCnameNodata) {
     // A wildcard containing a CNAME whose target does not include
     // data of this type.
-    readAndProcessQuery("q_wild2_aaaa");
+    createAndProcessQuery(Name("www.wild2.example.com"), RRClass::IN(),
+                          RRType::AAAA());
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 4, 0);
 
     RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -489,7 +498,8 @@ TEST_F(DataSrcTest, WildcardCnameNodata) {
 
 TEST_F(DataSrcTest, WildcardCnameNxdomain) {
     // A wildcard containing a CNAME whose target does not exist
-    readAndProcessQuery("q_wild3_a");
+    createAndProcessQuery(Name("www.wild3.example.com"), RRClass::IN(),
+                          RRType::A());
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 6, 0);
 
     RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -525,7 +535,8 @@ TEST_F(DataSrcTest, WildcardCnameNxdomain) {
     EXPECT_EQ(RRClass::IN(), rrset->getClass());
 }
 TEST_F(DataSrcTest, AuthDelegation) {
-    readAndProcessQuery("q_sql1");
+    createAndProcessQuery(Name("www.sql1.example.com"), RRClass::IN(),
+                          RRType::A());
 
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 4, 6);
 
@@ -571,7 +582,8 @@ TEST_F(DataSrcTest, AuthDelegation) {
 }
 
 TEST_F(DataSrcTest, Dname) {
-    readAndProcessQuery("q_dname");
+    createAndProcessQuery(Name("www.dname.example.com"), RRClass::IN(),
+                          RRType::A());
 
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 5, 4, 6);
 
@@ -628,7 +640,8 @@ TEST_F(DataSrcTest, DnameExact) {
 }
 
 TEST_F(DataSrcTest, Cname) {
-    readAndProcessQuery("q_cname");
+    createAndProcessQuery(Name("foo.example.com"), RRClass::IN(),
+                          RRType::A());
 
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 0, 0);
 
@@ -646,7 +659,8 @@ TEST_F(DataSrcTest, Cname) {
 }
 
 TEST_F(DataSrcTest, CnameInt) {
-    readAndProcessQuery("q_cname_int");
+    createAndProcessQuery(Name("cname-int.example.com"), RRClass::IN(),
+                          RRType::A());
 
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 4, 6);
 
@@ -672,7 +686,8 @@ TEST_F(DataSrcTest, CnameInt) {
 }
 
 TEST_F(DataSrcTest, CnameExt) {
-    readAndProcessQuery("q_cname_ext");
+    createAndProcessQuery(Name("cname-ext.example.com"), RRClass::IN(),
+                          RRType::A());
 
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 4, 6);
 
@@ -696,7 +711,8 @@ TEST_F(DataSrcTest, CnameExt) {
 }
 
 TEST_F(DataSrcTest, Delegation) {
-    readAndProcessQuery("q_subzone");
+    createAndProcessQuery(Name("www.subzone.example.com"), RRClass::IN(),
+                          RRType::A());
 
     headerCheck(msg, Rcode::NOERROR(), true, false, true, 0, 5, 2);
 
@@ -726,7 +742,8 @@ TEST_F(DataSrcTest, Delegation) {
 }
 
 TEST_F(DataSrcTest, NSDelegation) {
-    readAndProcessQuery("q_subzone_ns");
+    createAndProcessQuery(Name("subzone.example.com"), RRClass::IN(),
+                          RRType::NS());
 
     headerCheck(msg, Rcode::NOERROR(), true, false, true, 0, 5, 2);
 
@@ -758,12 +775,13 @@ TEST_F(DataSrcTest, NSDelegation) {
 TEST_F(DataSrcTest, ANYZonecut) {
     // An ANY query at a zone cut should behave the same as any other
     // delegation
-    readAndProcessQuery("q_subzone_any");
-
+    createAndProcessQuery(Name("subzone.example.com"), RRClass::IN(),
+                          RRType::ANY());
 }
 
 TEST_F(DataSrcTest, NSECZonecut) {
-    readAndProcessQuery("q_subzone_nsec");
+    createAndProcessQuery(Name("subzone.example.com"), RRClass::IN(),
+                          RRType::NSEC());
 
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 4, 6);
 
@@ -791,7 +809,8 @@ TEST_F(DataSrcTest, NSECZonecut) {
 }
 
 TEST_F(DataSrcTest, DNAMEZonecut) {
-    readAndProcessQuery("q_subzone_dname");
+    createAndProcessQuery(Name("subzone.example.com"), RRClass::IN(),
+                          RRType::DNAME());
 
     headerCheck(msg, Rcode::NOERROR(), true, false, true, 0, 5, 2);
     RRsetIterator rit = msg.beginSection(Section::AUTHORITY());
@@ -820,7 +839,8 @@ TEST_F(DataSrcTest, DNAMEZonecut) {
 }
 
 TEST_F(DataSrcTest, DS) {
-    readAndProcessQuery("q_subzone_ds");
+    createAndProcessQuery(Name("subzone.example.com"), RRClass::IN(),
+                          RRType::DS());
 
     headerCheck(msg, Rcode::NOERROR(), true, true, true, 3, 4, 6);
 

+ 14 - 18
src/lib/datasrc/tests/query_unittest.cc

@@ -32,20 +32,13 @@ using namespace isc::datasrc;
 
 namespace {
 
-class QueryTest : public ::testing::Test {
-protected:
-    void readQuery(Message& m, const char* datafile);
-
-    HotCache cache;
-};
-
 void
-QueryTest::readQuery(Message& m, const char* datafile) {
-    std::vector<unsigned char> data;
-    UnitTestUtil::readWireData(datafile, data);
-
-    InputBuffer buffer(&data[0], data.size());
-    m.fromWire(buffer);
+createQuery(Message& m, const Name& qname, const RRClass& qclass,
+            const RRType& qtype)
+{
+    m.setOpcode(Opcode::QUERY());
+    m.setHeaderFlag(MessageFlag::RD());
+    m.addQuestion(Question(qname, qclass, qtype));
 }
 
 QueryTaskPtr
@@ -58,15 +51,18 @@ createTask(Message& m, const Name& name, const RRType& rrtype0, HotCache& c) {
 
 // Check the QueryTask created using a temporary RRType object will remain
 // valid.
-TEST_F(QueryTest, constructWithTemporary) {
-    Message m1(Message::PARSE);
-    readQuery(m1, "q_wild_a");
+TEST(QueryTest, constructWithTemporary) {
+    HotCache cache;
+
+    Message m1(Message::RENDER);
+    createQuery(m1, Name("www.wild.example.com"), RRClass::IN(), RRType::A()); 
     QueryTaskPtr task_a = createTask(m1, Name("www.wild.example.com"),
                                         RRType::A(), cache);
     EXPECT_EQ(RRType::A(), task_a->qtype);
 
-    Message m2(Message::PARSE);
-    readQuery(m2, "q_wild_aaaa");
+    Message m2(Message::RENDER);
+    createQuery(m2, Name("www.wild.example.com"), RRClass::IN(),
+                RRType::AAAA());
     QueryTaskPtr task_aaaa = createTask(m2, Name("www.wild.example.com"),
                                         RRType::AAAA(), cache);
     EXPECT_EQ(RRType::AAAA(), task_aaaa->qtype);

+ 0 - 4
src/lib/datasrc/tests/testdata/q_cname

@@ -1,4 +0,0 @@
-# foo.example.com/A (cname to outside zone)
-  9d 57 01 00 00 01 00 00 00 00 00 00 03 66 6f 6f
-  07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 00 01 00
-  01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_cname_ext

@@ -1,4 +0,0 @@
-# cname-ext.example.com/A (cname to local authoritative zone)
-  ed 42 01 00 00 01 00 00 00 00 00 00 09 63 6e 61
-  6d 65 2d 65 78 74 07 65 78 61 6d 70 6c 65 03 63
-  6f 6d 00 00 01 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_cname_int

@@ -1,4 +0,0 @@
-# cname-int.example.com/A (cname to same zone)
-  51 b2 01 00 00 01 00 00 00 00 00 00 09 63 6e 61
-  6d 65 2d 69 6e 74 07 65 78 61 6d 70 6c 65 03 63
-  6f 6d 00 00 01 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_dname

@@ -1,4 +0,0 @@
-# www.dname.example.com/A (dname)
-  3c 71 01 00 00 01 00 00 00 00 00 00 03 77 77 77
-  05 64 6e 61 6d 65 07 65 78 61 6d 70 6c 65 03 63
-  6f 6d 00 00 01 00 01

+ 0 - 3
src/lib/datasrc/tests/testdata/q_example_dnskey

@@ -1,3 +0,0 @@
-# example.com/DNSKEY (normal lookup, positive answer)
-  dd 6b 01 00 00 01 00 00 00 00 00 00 07 65 78 61
-  6d 70 6c 65 03 63 6f 6d 00 00 30 00 01

+ 0 - 3
src/lib/datasrc/tests/testdata/q_example_ns

@@ -1,3 +0,0 @@
-# example.com/NS (normal lookup, positive answer)
-  dd 6b 01 00 00 01 00 00 00 00 00 00 07 65 78 61
-  6d 70 6c 65 03 63 6f 6d 00 00 02 00 01

+ 0 - 3
src/lib/datasrc/tests/testdata/q_example_ptr

@@ -1,3 +0,0 @@
-# example.com/PTR (NOERROR/NODATA)
-  4d 2a 01 00 00 01 00 00 00 00 00 00 07 65 78 61
-  6d 70 6c 65 03 63 6f 6d 00 00 0c 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_glork

@@ -1,4 +0,0 @@
-# glork.example.com/A (NXDOMAIN)
-  c1 11 01 00 00 01 00 00 00 00 00 00 05 67 6c 6f
-  72 6b 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 00
-  01 00 01

+ 0 - 3
src/lib/datasrc/tests/testdata/q_spork

@@ -1,3 +0,0 @@
-# spork.com/a (REFUSED)
-  a8 8a 01 00 00 01 00 00 00 00 00 00 05 73 70 6f 72 6b 03 63
-  6f 6d 00 00 01 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_sql1

@@ -1,4 +0,0 @@
-# www.sql1.example.com/A (delegation to local authoritative zone)
-  75 b3 01 00 00 01 00 00 00 00 00 00 03 77 77 77
-  04 73 71 6c 31 07 65 78 61 6d 70 6c 65 03 63 6f
-  6d 00 00 01 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_subzone

@@ -1,4 +0,0 @@
-# www.subzone.example.com/A (delegation to non-local zone)
-  00 7c 01 00 00 01 00 00 00 00 00 00 03 77 77 77
-  07 73 75 62 7a 6f 6e 65 07 65 78 61 6d 70 6c 65
-  03 63 6f 6d 00 00 01 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_subzone_any

@@ -1,4 +0,0 @@
-# subzone.example.com/ANY (ANY query at zone cut)
-  14 f0 01 00 00 01 00 00 00 00 00 00 07 73 75 62
-  7a 6f 6e 65 07 65 78 61 6d 70 6c 65 03 63 6f 6d
-  00 00 ff 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_subzone_dname

@@ -1,4 +0,0 @@
-# subzone.example.com/DNAME (DNAME query at zone cut)
-  14 f0 01 00 00 01 00 00 00 00 00 00 07 73 75 62
-  7a 6f 6e 65 07 65 78 61 6d 70 6c 65 03 63 6f 6d
-  00 00 27 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_subzone_ds

@@ -1,4 +0,0 @@
-# subzone.example.com/DS (delegation signer)
-  14 f0 01 00 00 01 00 00 00 00 00 00 07 73 75 62
-  7a 6f 6e 65 07 65 78 61 6d 70 6c 65 03 63 6f 6d
-  00 00 2b 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_subzone_ns

@@ -1,4 +0,0 @@
-# subzone.example.com/NS (delegation to non-local zone)
-  14 f0 01 00 00 01 00 00 00 00 00 00 07 73 75 62
-  7a 6f 6e 65 07 65 78 61 6d 70 6c 65 03 63 6f 6d
-  00 00 02 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_subzone_nsec

@@ -1,4 +0,0 @@
-# subzone.example.com/NSEC (NSEC query at zone cut)
-  14 f0 01 00 00 01 00 00 00 00 00 00 07 73 75 62
-  7a 6f 6e 65 07 65 78 61 6d 70 6c 65 03 63 6f 6d
-  00 00 2f 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_wild2_a

@@ -1,4 +0,0 @@
-# www.wild2.example.com/A (wildcard)
-  d8 ef 01 00 00 01 00 00 00 00 00 00 03 77 77 77
-  05 77 69 6c 64 32 07 65 78 61 6d 70 6c 65 03 63
-  6f 6d 00 00 01 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_wild2_aaaa

@@ -1,4 +0,0 @@
-# www.wild2.example.com/AAAA (wildcard CNAME NXRRSET)
-  d8 ef 01 00 00 01 00 00 00 00 00 00 03 77 77 77
-  05 77 69 6c 64 32 07 65 78 61 6d 70 6c 65 03 63
-  6f 6d 00 00 1c 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_wild3_a

@@ -1,4 +0,0 @@
-# www.wild3.example.com/A (wildcard, CNAME, target does not exist)
-  d8 ef 01 00 00 01 00 00 00 00 00 00 03 77 77 77
-  05 77 69 6c 64 33 07 65 78 61 6d 70 6c 65 03 63
-  6f 6d 00 00 01 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_wild_a

@@ -1,4 +0,0 @@
-# www.wild.example.com/A (wildcard)
-  d8 ef 01 00 00 01 00 00 00 00 00 00 03 77 77 77
-  04 77 69 6c 64 07 65 78 61 6d 70 6c 65 03 63 6f
-  6d 00 00 01 00 01

+ 0 - 4
src/lib/datasrc/tests/testdata/q_wild_aaaa

@@ -1,4 +0,0 @@
-# www.wild.example.com/A (wildcard)
-  d8 ef 01 00 00 01 00 00 00 00 00 00 03 77 77 77
-  04 77 69 6c 64 07 65 78 61 6d 70 6c 65 03 63 6f
-  6d 00 00 1c 00 01