From be1731190b9e96385a3c7f36fe94748f6f37a39d Mon Sep 17 00:00:00 2001 From: Hugo Thunnissen Date: Mon, 5 Nov 2018 21:21:53 +0100 Subject: [PATCH] Define and test stomp errors --- stomp.el | 13 +++++++++++-- test/test.el | 17 +++++++++++++++++ test/testdata/invalid_header_frame.txt | Bin 0 -> 51 bytes 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/testdata/invalid_header_frame.txt diff --git a/stomp.el b/stomp.el index 55a6a7c..20e6c8d 100644 --- a/stomp.el +++ b/stomp.el @@ -23,6 +23,15 @@ (require 'map) +(define-error 'stomp-error + "Error encountered in implementation of the STOMP protocol") + +(define-error 'stomp-invalid-header + "Invalid STOMP frame header encounterd") + +(define-error 'stomp-invalid-frame + "Invalid STOMP frame encountered") + (defun stomp-send-frame (process frame) "Send a message to a STOMP process" (process-send-string process (stomp-frame-to-string frame))) @@ -84,7 +93,7 @@ (let ((header (split-string (thing-at-point 'line) ":"))) (cond ((= (line-end-position) end-point) headers) - ((> (length header) 2) (throw 'invalid-header nil)) + ((> (length header) 2) (signal 'stomp-invalid-header (list header))) (t (stomp-read-headers buffer end-point @@ -125,7 +134,7 @@ 'command key. Other optional keys are 'headers (another alist) and 'content" (unless (assq 'command frame) - (throw 'invalid-frame "A STOMP frame must define a command")) + (signal 'stomp-invalid-frame (list "Expected frame to have a command" frame))) (let ((headers (if (assq 'headers frame) (alist-get 'headers frame) '())) (content (if (assq 'content frame) (alist-get 'content frame) ""))) (format "%s\n%s\n%s\u0000" diff --git a/test/test.el b/test/test.el index 5c84768..504d8c0 100755 --- a/test/test.el +++ b/test/test.el @@ -107,3 +107,20 @@ (setq frame '((headers . (("okay" . "bye"))))) (should (equal nil (stomp-frame-header "bla" frame)))) + +(ert-deftest will-signal-invald-frame () + "`stomp-frame-to-string` should signal an invalid frame error +when attempting to send a frame without a command defined in it" + (should-error (stomp-frame-to-string '()) :type 'stomp-invalid-frame)) + +(ert-deftest will-signal-wrong-type-filter-function () + "`stomp-filter-function` should signal a `wrong-type-argument` + error when `callback` is not a callback" + (should-error (stomp-filter-function '(not a function) :type 'wrong-type-argument))) + +(ert-deftest will-signal-invalid-header () + "`stomp-read-headers` should signal a `stomp-invalid-frame` +error when a header containing colons is encountered" + (with-testing-buffer + "invalid_header_frame.txt" + (should-error (stomp-read-headers (current-buffer) (point-max)) :type 'stomp-invalid-header))) diff --git a/test/testdata/invalid_header_frame.txt b/test/testdata/invalid_header_frame.txt new file mode 100644 index 0000000000000000000000000000000000000000..9e8a10e36aa5b3f1b4f600ee447ff4fde353836b GIT binary patch literal 51 zcmZ?rapWq_&rQ|MNKH&hEwU<0%qdN^$}h=CEdn#S^0TdyDpR?*lJoOQQu9i<7`On| CJ`r^Q literal 0 HcmV?d00001