FAQ
Hi,

I'm writing some unit tests which run code which depends on the Gorilla Web
Toolkit. The tested code requires mux.Vars() to contain some values, but I
don't want to invoke ServeHTTP() in these particular tests, which is where
mux.Vars() is initialised. The nub of the problem lies with the fact that a
private type alias exists in the mux package which is used as the type of
the key for the DefaultContext:

Type alias:

http://code.google.com/p/gorilla/source/browse/mux/mux.go#220

mux.Vars() setting code

http://code.google.com/p/gorilla/source/browse/mux/mux.go#244

If I promote contextKey to exported as ContextKey I can get the correct
behaviour with this code:
var vars = map[string]string{
"doctype": strconv.FormatUint(uint64(doctype), 10),
"docid": strconv.FormatUint(uint64(docid), 10),
}
context.DefaultContext.Set(req, mux.ContextKey(0), vars)

but obviously this involves hacking a library package. Without getting
Rodrigo to alter the mux API, is there another way I can circumvent this
testing issue?

Cheers,
Donovan.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 7, '12 at 9:07a
activeSep 7, '12 at 9:07a
posts1
users1
websitegolang.org

1 user in discussion

Donovan: 1 post

People

Translate

site design / logo © 2022 Grokbase