aboutsummaryrefslogtreecommitdiff
path: root/lib/http/requestmethod_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-03-14 21:20:21 +0700
committerShulhan <ms@kilabit.info>2021-03-14 21:20:21 +0700
commiteacddcae5fcdec55b2225d95473d153543b5bea8 (patch)
treea480a3266e93662a45f0d624483458bf204c7669 /lib/http/requestmethod_test.go
parent9836de834e95dbd1b9c8cd629392075ab6c7133b (diff)
downloadpakakeh.go-eacddcae5fcdec55b2225d95473d153543b5bea8.tar.xz
http: fix use of iota on list of RequestMethod
Using iota on the second list of constants does not start the iota value from 0, but start from the current index of list. In previous code, the value of RequestMethodConnect is not "1 << 0" or 1 but 2; this is not what we expected, it should be 1.
Diffstat (limited to 'lib/http/requestmethod_test.go')
-rw-r--r--lib/http/requestmethod_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/http/requestmethod_test.go b/lib/http/requestmethod_test.go
new file mode 100644
index 00000000..dde4b0fd
--- /dev/null
+++ b/lib/http/requestmethod_test.go
@@ -0,0 +1,42 @@
+// Copyright 2021, Shulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package http
+
+import (
+ "testing"
+
+ "github.com/shuLhan/share/lib/test"
+)
+
+func TestRequestMethod_String(t *testing.T) {
+ cases := []struct {
+ m RequestMethod
+ exp string
+ }{
+ {0, "GET"},
+ {1, "CONNECT"},
+ {2, "DELETE"},
+ {3, "HEAD"},
+ {4, "OPTIONS"},
+ {5, "PATCH"},
+ {6, "POST"},
+ {7, "PUT"},
+ {8, "TRACE"},
+ {9, ""},
+ {RequestMethodGet, "GET"},
+ {RequestMethodConnect, "CONNECT"},
+ {RequestMethodDelete, "DELETE"},
+ {RequestMethodHead, "HEAD"},
+ {RequestMethodOptions, "OPTIONS"},
+ {RequestMethodPatch, "PATCH"},
+ {RequestMethodPost, "POST"},
+ {RequestMethodPut, "PUT"},
+ {RequestMethodTrace, "TRACE"},
+ }
+
+ for _, c := range cases {
+ test.Assert(t, "RequestMethod.String", c.exp, c.m.String(), true)
+ }
+}