From 994325db4f172b06f1307215df681cabd550c6ce Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Mon, 16 Jan 2017 18:30:44 +0100 Subject: [PATCH] add test to context --- http/ctx/context_test.go | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 http/ctx/context_test.go diff --git a/http/ctx/context_test.go b/http/ctx/context_test.go new file mode 100644 index 0000000..ae5915d --- /dev/null +++ b/http/ctx/context_test.go @@ -0,0 +1,47 @@ +package ctx + +import ( + "net/http" + "reflect" + "testing" +) + +func generateRequest(qs string) *http.Request { + r, err := http.NewRequest("GET", "?"+qs, nil) + if err != nil { + panic(err) + } + return r +} + +func TestContext_QueryIntMultiple(t *testing.T) { + tests := []struct { + Request *http.Request + arg string + want []int + }{ + { + Request: generateRequest("t=1"), + want: []int{1}, + }, + { + Request: generateRequest("t=1&t=3"), + want: []int{1, 3}, + }, + { + Request: generateRequest("t=3&t=1"), + want: []int{3, 1}, + }, + } + for i, tt := range tests { + if tt.arg == "" { + tt.arg = "t" + } + r := &Context{ + Request: tt.Request, + } + if got := r.QueryIntMultiple(tt.arg); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%d. Context.QueryIntMultiple() = %v, want %v", i, got, tt.want) + } + } +} -- GitLab