harness-drone/logger/logger_test.go

48 lines
947 B
Go
Raw Normal View History

2019-02-19 23:56:41 +00:00
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
2019-02-28 07:07:13 +00:00
// +build !oss
2019-02-19 23:56:41 +00:00
package logger
import (
"context"
"net/http"
"testing"
"github.com/sirupsen/logrus"
)
func TestContext(t *testing.T) {
entry := logrus.NewEntry(logrus.StandardLogger())
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 != L {
t.Errorf("Expected default Logger from context")
}
}
func TestRequest(t *testing.T) {
entry := logrus.NewEntry(logrus.StandardLogger())
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")
}
}