You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
914 B
Go
47 lines
914 B
Go
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
|
// Use of this source code is governed by the Parity Public License
|
|
// that can be found in the LICENSE file.
|
|
|
|
package logger
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func TestContext(t *testing.T) {
|
|
entry := Discard()
|
|
|
|
ctx := WithContext(context.Background(), entry)
|
|
got := FromContext(ctx)
|
|
|
|
if got != entry {
|
|
t.Errorf("Expected Logger from context")
|
|
}
|
|
}
|
|
|
|
func TestEmptyContext(t *testing.T) {
|
|
got := FromContext(context.Background())
|
|
if got == nil {
|
|
t.Errorf("Expected Logger from context")
|
|
}
|
|
if _, ok := got.(*discard); !ok {
|
|
t.Errorf("Expected discard Logger from context")
|
|
}
|
|
}
|
|
|
|
func TestRequest(t *testing.T) {
|
|
entry := Discard()
|
|
|
|
ctx := WithContext(context.Background(), entry)
|
|
req := new(http.Request)
|
|
req = req.WithContext(ctx)
|
|
|
|
got := FromRequest(req)
|
|
|
|
if got != entry {
|
|
t.Errorf("Expected Logger from http.Request")
|
|
}
|
|
}
|