Commits

David Krentzlin committed b58aac9

refactord better testing code

  • Participants
  • Parent commits 3e71f80

Comments (0)

Files changed (2)

File tests/run2.scm

 ;; 
 
 (use test)
-(load "spec-helper")
+(load "test-helper")
 (use sendfile)
 
+
 (with-running-server
  
- (let ((kb-buffer (generate-buffer (kibibytes 1)))
-       (mb-buffer (generate-buffer (mibibytes 1))))
- 
-   (test-group "sendfile main interface"
-               (call-with-temporary-file/checksum
-                mb-buffer
-                (lambda (temp-file-path content-checksum)
-                  (let ((file-input (file-open temp-file-path (bitwise-ior open/rdonly open/binary))))
-                    (test content-checksum
-                          (call-with-connection-to-server
-                           (lambda (server-in server-out)
-                             (display (mibibytes 1) server-out)
-                             (newline server-out)
-                             (sendfile file-input server-out)
-                             (flush-output server-out)
-                             (read-line server-in)))))))))
+ (test-group "sendfile main interface"
 
-  (test-group "regression")
+             (call-with-temporary-file/checksum
+              (generate-buffer (mibibytes 1))
+              (lambda (temp-file expected-checksum)
+
+                (test "sendfile"
+                      expected-checksum
+                      (stream-file temp-file sendfile)))))
+
+ (test-group "regression")
 
  )
 

File tests/test-helper.scm

         (close-output-port output)
         result))))
 
-(define (stream-file path size)
-  (call-with-connection-to-server
-   (lambda (input output)
-     (display size output)
-     (newline output)
-     (call-with-input-file path
-       (lambda (input-file)
-         (sendfile input-file output)))
-     (read-line input))))
+(define (stream-file path streamer)
+  (let ((size (file-size path))
+        (file-port (file-open path (bitwise-ior open/rdonly open/binary))))
+    (call-with-connection-to-server
+     (lambda (server-input server-output)
+       (display size server-output)
+       (newline server-output)
+       
+       (streamer file-port server-output)
+       
+       (flush-output server-output)
+       (read-line server-input)))))
 
 ;generate a string of bytes bytes
 (define (with-buffer bytes proc)
 
 
 
-
 (define (mibibytes amount)
   (* amount (kibibytes 1024)))