arpadboda commented on a change in pull request #657: MINIFICPP-1048 - Add 
PublishKafka docker tests
URL: https://github.com/apache/nifi-minifi-cpp/pull/657#discussion_r336078145
 
 

 ##########
 File path: docker/test/integration/minifi/test/__init__.py
 ##########
 @@ -213,32 +247,80 @@ def __init__(self, expected_content):
         self.valid = False
         self.expected_content = expected_content
 
-    def validate(self):
+    def validate(self, dir=''):
 
-        if self.valid:
-            return True
+        self.valid = False
 
-        listing = listdir(self.output_dir)
+        full_dir = self.output_dir + dir
+        logging.info("Output folder: %s", full_dir)
+
+        listing = listdir(full_dir)
 
         if listing:
+            for l in listing:
+                logging.info("name:: %s", l)
             out_file_name = listing[0]
 
-            with open(join(self.output_dir, out_file_name), 'r') as out_file:
+            with open(join(full_dir, out_file_name), 'r') as out_file:
                 contents = out_file.read()
+                logging.info("dir %s -- name %s", full_dir, out_file_name)
+                logging.info("expected %s -- content %s", 
self.expected_content, contents)
 
-                if contents == self.expected_content:
+                if self.expected_content in contents:
                     self.valid = True
 
         return self.valid
 
+class KafkaValidator(OutputValidator):
+    """
+    Validates PublishKafka
+    """
+
+    def __init__(self, expected_content):
+        self.valid = False
+        self.expected_content = expected_content
+        self.containers = None
+
+    def set_containers(self, containers):
+        self.containers = containers
+
+    def validate(self):
+
+        if self.valid:
+            return True
+        if self.containers is None:
+            return self.valid
+
+        if 'kafka-consumer' not in self.containers:
+            logging.info('Not found kafka container.')
+            return False
+        else:
+            kafka_container = self.containers['kafka-consumer']
+
+        output, stat = kafka_container.get_archive('/heaven_signal.txt')
+        file_obj = BytesIO()
+        for i in output:
+            file_obj.write(i)
+        file_obj.seek(0)
+        tar = tarfile.open(mode='r', fileobj=file_obj)
+        contents = tar.extractfile('heaven_signal.txt').read()
+        logging.info("expected %s -- content %s", self.expected_content, 
contents)
+
+        contents = contents.decode("utf-8")
+        if self.expected_content in contents:
+            self.valid = True
+
+        logging.info("expected %s -- content %s", self.expected_content, 
contents)
+        return self.valid
+
 class EmptyFilesOutPutValidator(FileOutputValidator):
     """
     Validates if all the files in the target directory are empty and at least 
one exists
     """
     def __init__(self):
         self.valid = False
 
-    def validate(self):
+    def validate(self, dir=''):
 
 Review comment:
   I think what this should do is to check if the dir arguments actually 
contains a path and validate that. 
   At least that seems to be consistent with that you did in the other 
validator.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to