[Groonga-commit] groonga/groonga-query-log at 5470ea7 [master] Test SMTP request

Back to archive index
Kouhei Sutou null+****@clear*****
Tue Mar 26 16:49:02 JST 2019


Kouhei Sutou	2019-03-26 16:49:02 +0900 (Tue, 26 Mar 2019)

  Revision: 5470ea75e3ea6771fa631eaed39615f6b8efb614
  https://github.com/groonga/groonga-query-log/commit/5470ea75e3ea6771fa631eaed39615f6b8efb614

  Message:
    Test SMTP request

  Modified files:
    test/command/test-run-regression-test.rb

  Modified: test/command/test-run-regression-test.rb (+82 -10)
===================================================================
--- test/command/test-run-regression-test.rb    2019-03-26 16:48:47 +0900 (cbad79a)
+++ test/command/test-run-regression-test.rb    2019-03-26 16:49:02 +0900 (ffeb533)
@@ -23,17 +23,87 @@ class RunRegressionTestCommandTest < Test::Unit::TestCase
     super("regression-test-logs", *components)
   end
 
-  sub_test_case(".new") do
-    def test_notifier
+  class SMTPServer
+    def initialize
+      @socket = TCPServer.open(host, port)
+    end
+  end
+
+  sub_test_case("MailNotifier") do
+    MailNotifier = GroongaQueryLog::Command::RunRegressionTest::MailNotifier
+
+    def setup
+      @smtp_host = "127.0.0.1"
+      @smtp_port = 20025
+      @requests = []
+      @now = "Tue, 26 Mar 2019 16:39:46 +0900"
+      @server = TCPServer.open(@smtp_host, @smtp_port)
+      @thread = Thread.new do
+        client =****@serve*****
+        client.print("220 localhost SMTP server\r\n")
+        client.each_line do |line|
+          @requests << line
+          case line.chomp
+          when /\AEHLO /
+            client.print("250 AUTH\r\n")
+          when /\AMAIL FROM:/
+            client.print("250 2.1.0 Ok\r\n")
+          when /\ARCPT TO:/
+            client.print("250 2.1.0 Ok\r\n")
+          when "DATA"
+            client.print("354 End data with <CR><LF>.<CR><LF>\r\n")
+          when "."
+            client.print("250 2.0.0 Ok\r\n")
+          when "QUIT"
+            client.print("221 2.0.0 Bye\r\n")
+            client.close
+            break
+          end
+        end
+      end
+    end
+
+    def teardown
+      @server.close
+      @thread.kill
+    end
+
+    def normalized_request
+      @requests
+        .join("")
+        .gsub(/^Date: .*\r\n/,
+              "Date: #{@now}\r\n")
+    end
+
+    def test_success
       options = {
-        :mail_to => "noreply@#{Socket.gethostname}",
+        :smtp_server => @smtp_host,
+        :smtp_port => @smtp_port,
+        :mail_from => "groon****@examp*****",
+        :mail_to => "norep****@examp*****",
+        :mail_subject_on_success => "Success",
+        :mail_subject_on_failure => "Failure",
         :path => fixture_path("url-format.log"),
-        :skip_smtp => true
       }
-      notifier = GroongaQueryLog::Command::RunRegressionTest::MailNotifier.new(true, 3000, options)
-      output = StringIO.new
-      notifier.notify(output)
-      expected = <<-OUTPUT
+      notifier = MailNotifier.new(true, 3000, options)
+      notifier.notify
+      assert_equal(<<-REQUEST.gsub(/\n/, "\r\n").b, normalized_request)
+EHLO 127.0.0.1
+MAIL FROM:<#{options[:mail_from]}>
+RCPT TO:<#{options[:mail_to]}>
+DATA
+MIME-Version: 1.0
+X-Mailer: groonga-query-log test reporter #{GroongaQueryLog::VERSION};
+  https://github.com/groonga/groonga-query-log
+Content-Type: text/plain; charset=utf-8
+Content-Transfer-Encoding: 8bit
+From: #{options[:mail_from]}
+To: #{options[:mail_to]}
+Subject: Success
+Date: #{@now}
+
+Elapsed: 0days 00:50:00
+Report:
 Command:
 /d/select?table=Logs&match_columns=message&query=%E7%84%BC%E8%82%89
 Name: select
@@ -49,8 +119,10 @@ Arguments:
    [1, "log message1: 焼肉"],
 -  [2, "log message2: 焼肉"]]]
 +  [3, "log message3: 焼肉"]]]
-      OUTPUT
-      assert_equal(expected, output.string)
+
+.
+QUIT
+      REQUEST
     end
   end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190326/a71d668c/attachment-0001.html>


More information about the Groonga-commit mailing list
Back to archive index