aboutsummaryrefslogtreecommitdiff
path: root/status_test.go
diff options
context:
space:
mode:
authorGravatar kiyon <kiyon@gofiber.io> 2020-08-03 01:18:57 +0800
committerGravatar GitHub <noreply@github.com> 2020-08-02 19:18:57 +0200
commit2509c12e7794859d16e359be0fe62a08a5d382d3 (patch)
treeab6611d1f3e70f8b745df5464d1a6d5538553a4a /status_test.go
parentFix comment typo (diff)
downloadfasthttp-2509c12e7794859d16e359be0fe62a08a5d382d3.tar.gz
fasthttp-2509c12e7794859d16e359be0fe62a08a5d382d3.tar.bz2
fasthttp-2509c12e7794859d16e359be0fe62a08a5d382d3.zip
improve statusLine and StatusMessage by using slice instead of map (#855)
* 🚀 improve statusLine and StatusMessage by using slice instead of map Co-authored-by: Fenny <fenny@gofiber.io> Co-authored-by: ReneWerner87 <rene@gofiber.io> * for cli stuff * make invalidStatusLine() just return the formatted line * for ci stuff Co-authored-by: Fenny <fenny@gofiber.io> Co-authored-by: ReneWerner87 <rene@gofiber.io>
Diffstat (limited to 'status_test.go')
-rw-r--r--status_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/status_test.go b/status_test.go
new file mode 100644
index 0000000..e3bfa8a
--- /dev/null
+++ b/status_test.go
@@ -0,0 +1,24 @@
+package fasthttp
+
+import (
+ "bytes"
+ "testing"
+)
+
+func TestStatusLine(t *testing.T) {
+ t.Parallel()
+
+ testStatusLine(t, -1, []byte("HTTP/1.1 -1 Unknown Status Code\r\n"))
+ testStatusLine(t, 99, []byte("HTTP/1.1 99 Unknown Status Code\r\n"))
+ testStatusLine(t, 200, []byte("HTTP/1.1 200 OK\r\n"))
+ testStatusLine(t, 512, []byte("HTTP/1.1 512 Unknown Status Code\r\n"))
+ testStatusLine(t, 512, []byte("HTTP/1.1 512 Unknown Status Code\r\n"))
+ testStatusLine(t, 520, []byte("HTTP/1.1 520 Unknown Status Code\r\n"))
+}
+
+func testStatusLine(t *testing.T, statusCode int, expected []byte) {
+ line := statusLine(statusCode)
+ if !bytes.Equal(expected, line) {
+ t.Fatalf("unexpected status line %s. Expecting %s", string(line), string(expected))
+ }
+}