(test-begin "attach") (tick '("create" "--type" "defect" "--summary" "hello" "--body" "Attach me")) ;; Create dummy file to attach (with-output-to-file "dummy" (lambda () (display ""))) (let ((last-ticket (get-last-modified-ticket))) (tick `("attach" "--ticket" ,last-ticket "dummy")) (test-assert "Attached dummy file" (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "attached dummy\n" body))) (test-assert "dummy file is in the ticket attachments dir" (file-exists? (make-pathname (ticket-attachments-dir last-ticket) "dummy"))) ;; Remove dummy attachment (tick `("attach" "--ticket" ,last-ticket "--delete" "dummy")) (test-assert "Delete attached dummy file" (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "removed attachment dummy\n" body))) (test-assert "dummy file got removed from the ticket attachments dir" (not (file-exists? (make-pathname (ticket-attachments-dir last-ticket) "dummy")))) ;; Test attaching a file using its absolute path (tick `("attach" "--ticket" ,last-ticket ,(make-pathname (current-directory) "dummy"))) (test-assert "Attached dummy file with an absolute path" (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "attached dummy\n" body))) (test-assert "dummy file is in the ticket attachments dir" (file-exists? (make-pathname (ticket-attachments-dir last-ticket) "dummy"))) (tick `("attach" "--ticket" ,last-ticket "--delete" "dummy")) (test-assert "Delete dummy file attached with abs path" (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "removed attachment dummy\n" body))) (test-assert "dummy with abs path file got removed from the ticket attachments dir" (not (file-exists? (make-pathname (ticket-attachments-dir last-ticket) "dummy")))) ) ;; end let (delete-file "dummy") (test-end "attach") (test-exit)