Define and test stomp errors

master
Hugo Thunnissen 6 years ago
parent cdb1cacb20
commit be1731190b

@ -23,6 +23,15 @@
(require 'map) (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) (defun stomp-send-frame (process frame)
"Send a message to a STOMP process" "Send a message to a STOMP process"
(process-send-string process (stomp-frame-to-string frame))) (process-send-string process (stomp-frame-to-string frame)))
@ -84,7 +93,7 @@
(let ((header (split-string (thing-at-point 'line) ":"))) (let ((header (split-string (thing-at-point 'line) ":")))
(cond (cond
((= (line-end-position) end-point) headers) ((= (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 (t (stomp-read-headers
buffer buffer
end-point end-point
@ -125,7 +134,7 @@
'command key. Other optional keys are 'headers (another alist) 'command key. Other optional keys are 'headers (another alist)
and 'content" and 'content"
(unless (assq 'command frame) (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) '())) (let ((headers (if (assq 'headers frame) (alist-get 'headers frame) '()))
(content (if (assq 'content frame) (alist-get 'content frame) ""))) (content (if (assq 'content frame) (alist-get 'content frame) "")))
(format "%s\n%s\n%s\u0000" (format "%s\n%s\n%s\u0000"

@ -107,3 +107,20 @@
(setq frame '((headers . (("okay" . "bye"))))) (setq frame '((headers . (("okay" . "bye")))))
(should (equal nil (stomp-frame-header "bla" frame)))) (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)))

Binary file not shown.
Loading…
Cancel
Save