]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
tests/integration: support 'REPLY' step type
authorMarek Vavruša <marek.vavrusa@nic.cz>
Tue, 10 Feb 2015 21:48:55 +0000 (22:48 +0100)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Tue, 10 Feb 2015 21:48:55 +0000 (22:48 +0100)
tests/pydnstest/scenario.py
tests/test_integration.py

index 27c2a4e77a855d7e2bbb68cf79024a38d0ce1d26..b3b71e68603213be64d651e9125ba2df2ededb06 100644 (file)
@@ -129,7 +129,7 @@ class Entry:
         rdtype = args.pop(0)
         rr = dns.rrset.from_text(owner, ttl, rdclass, rdtype)
         if len(args) > 0:
-            rd = dns.rdata.from_text(rr.rdclass, rr.rdtype, ' '.join(args), origin = dns.name.from_text(self.origin), relativize = False)
+            rd = dns.rdata.from_text(rr.rdclass, rr.rdtype, ' '.join(args), origin=dns.name.from_text(self.origin), relativize=False)
             rr.add(rd)
         return rr
 
@@ -219,6 +219,8 @@ class Step:
             return self.__check_answer(ctx)
         elif self.type == 'TIME_PASSES':
             return self.__time_passes(ctx)
+        elif self.type == 'REPLY':
+            pass
         else:
             raise Exception('step %s unsupported' % self.type)
 
@@ -246,7 +248,6 @@ class Step:
         ctx.scenario.time = int(self.args[1])
         ctx.set_time(ctx.scenario.time)
 
-
 class Scenario:
     def __init__(self, info):
         """ Initialize scenario with description. """
@@ -268,6 +269,17 @@ class Scenario:
         for rng in self.ranges:
             if rng.eligible(step_id, address):
                 return rng.reply(query)
+        # Find any prescripted one-shot replies
+        for step in self.steps:
+            if step.id <= step_id or step.type != 'REPLY':
+                continue
+            try:
+                candidate = step.data[0]
+                candidate.match(query)
+                step.data.remove(candidate)
+                return candidate.adjust_reply(query)
+            except:
+                pass
 
     def play(self, ctx):
         """ Play given scenario. """
@@ -281,5 +293,3 @@ class Scenario:
                 step.play(ctx)
         except Exception as e:
             raise Exception('step #%d %s' % (step.id, str(e)))
-
-
index 6a41c3477054aece4acbd1c34a35764d8978e237..5b10ca9f08f9509dbed39f33dfc89eb7dd91c3dd 100755 (executable)
@@ -1,5 +1,7 @@
 #!/usr/bin/env python
-import sys, os, fileinput
+import sys
+import os
+import fileinput
 from pydnstest import scenario, testserver, test
 import _test_integration as mock_ctx
 
@@ -17,7 +19,7 @@ def get_next(file_in):
             return False
         for csep in (';', '#'):
             if csep in line:
-                line = line[0 : line.index(csep)]
+                line = line[0:line.index(csep)]
         tokens = ' '.join(line.strip().split()).split()
         if len(tokens) == 0:
             continue  # Skip empty lines
@@ -88,6 +90,7 @@ def parse_scenario(op, args, file_in):
             out.steps.append(parse_step(op, args, file_in))
     return out
 
+
 def parse_file(file_in):
     """ Parse scenario from a file. """
     try:
@@ -146,6 +149,7 @@ def play_object(path):
         server.stop()
         mock_ctx.deinit()
 
+
 def test_platform(*args):
     if sys.platform == 'windows':
         raise Exception('not supported at all on Windows')