github.com/drone/runner-go@v1.12.0/logger/context_test.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package logger 6 7 import ( 8 "context" 9 "net/http" 10 "testing" 11 ) 12 13 func TestContext(t *testing.T) { 14 entry := Discard() 15 16 ctx := WithContext(context.Background(), entry) 17 got := FromContext(ctx) 18 19 if got != entry { 20 t.Errorf("Expected Logger from context") 21 } 22 } 23 24 func TestEmptyContext(t *testing.T) { 25 got := FromContext(context.Background()) 26 if got == nil { 27 t.Errorf("Expected Logger from context") 28 } 29 if _, ok := got.(*discard); !ok { 30 t.Errorf("Expected discard Logger from context") 31 } 32 } 33 34 func TestRequest(t *testing.T) { 35 entry := Discard() 36 37 ctx := WithContext(context.Background(), entry) 38 req := new(http.Request) 39 req = req.WithContext(ctx) 40 41 got := FromRequest(req) 42 43 if got != entry { 44 t.Errorf("Expected Logger from http.Request") 45 } 46 }