Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Oct 31, 2020
1 parent 668a701 commit 4c9315e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rest/internal/context/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func WithPathVars(r *http.Request, params map[string]string) *http.Request {
type contextKey string

func (c contextKey) String() string {
return "rest/internal/context context key" + string(c)
return "rest/internal/context key: " + string(c)
}
32 changes: 32 additions & 0 deletions rest/internal/context/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package context

import (
"context"
"net/http"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestVars(t *testing.T) {
expect := map[string]string{
"a": "1",
"b": "2",
}
r, err := http.NewRequest(http.MethodGet, "/", nil)
assert.Nil(t, err)
r = r.WithContext(context.WithValue(context.Background(), pathVars, expect))
assert.EqualValues(t, expect, Vars(r))
}

func TestVarsNil(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "/", nil)
assert.Nil(t, err)
assert.Nil(t, Vars(r))
}

func TestContextKey(t *testing.T) {
ck := contextKey("hello")
assert.True(t, strings.Contains(ck.String(), "hello"))
}

0 comments on commit 4c9315e

Please sign in to comment.