Skip to content

Commit

Permalink
Fixed nits
Browse files Browse the repository at this point in the history
  • Loading branch information
anuptalwalkar committed Dec 16, 2016
1 parent bc83703 commit fb5082f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
12 changes: 5 additions & 7 deletions internal/fxcontext/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import (

type contextKey int

const (
contextLogger contextKey = iota
)
const _contextLogger contextKey = iota

var _ fx.Context = &Context{}

Expand All @@ -45,7 +43,7 @@ type Context struct {
func New(ctx gcontext.Context, host service.Host) fx.Context {
if host != nil {
return &Context{
gcontext.WithValue(ctx, contextLogger, host.Logger()),
gcontext.WithValue(ctx, _contextLogger, host.Logger()),
}
}
return &Context{
Expand All @@ -59,8 +57,8 @@ func (c *Context) Logger() ulog.Log {
}

func (c *Context) getLogger() ulog.Log {
if c.Context.Value(contextLogger) == nil {
c.Context = gcontext.WithValue(c.Context, contextLogger, ulog.Logger())
if c.Context.Value(_contextLogger) == nil {
c.Context = gcontext.WithValue(c.Context, _contextLogger, ulog.Logger())
}
return c.Context.Value(contextLogger).(ulog.Log)
return c.Context.Value(_contextLogger).(ulog.Log)
}
8 changes: 1 addition & 7 deletions internal/fxcontext/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestContext_HostAccess(t *testing.T) {
ctx := New(gcontext.Background(), service.NullHost())
assert.NotNil(t, ctx)
assert.NotNil(t, ctx.Logger())
assert.NotNil(t, ctx.Value(_contextLogger))
}

func TestWithContext(t *testing.T) {
Expand All @@ -49,13 +50,6 @@ func TestWithContext(t *testing.T) {
assert.Equal(t, "val1", ctx.Value("key1"))
}

func TestWithContextNil(t *testing.T) {
ctxt := Context{
Context: nil,
}
assert.NotNil(t, ctxt)
}

func TestWithContext_NilHost(t *testing.T) {
ctx := New(gcontext.Background(), nil)
assert.NotNil(t, ctx.Logger())
Expand Down
1 change: 1 addition & 0 deletions modules/uhttp/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func contextFilter(host service.Host) FilterFunc {

func tracingServerFilter(host service.Host) FilterFunc {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, next Handler) {
// TODO:(anup) GFM-257
fxctx := &fxcontext.Context{
Context: ctx,
}
Expand Down
6 changes: 3 additions & 3 deletions modules/uhttp/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (

func TestFilterChain(t *testing.T) {
host := service.NullHost()
chain := newFilterChain([]Filter{}, getNoopFilter(host))
chain := newFilterChain([]Filter{}, getNoopHandler(host))
response := testServeHTTP(chain)
assert.True(t, strings.Contains(response.Body.String(), "filters ok"))
}
Expand All @@ -48,7 +48,7 @@ func TestFilterChainFilters(t *testing.T) {
contextFilter(host),
tracingServerFilter(host),
panicFilter(host)},
getNoopFilter(host))
getNoopHandler(host))
response := testServeHTTP(chain)
assert.Contains(t, response.Body.String(), "filters ok")
}
Expand All @@ -61,7 +61,7 @@ func testServeHTTP(chain filterChain) *httptest.ResponseRecorder {
return response
}

func getNoopFilter(host service.Host) HandlerFunc {
func getNoopHandler(host service.Host) HandlerFunc {
return func(ctx fx.Context, w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "filters ok")
}
Expand Down

0 comments on commit fb5082f

Please sign in to comment.