Cosmos Nicolaou | 0e4e392 | 2015-06-10 16:30:09 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Vanadium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package logger_test |
| 6 | |
| 7 | import ( |
| 8 | "testing" |
| 9 | |
| 10 | "v.io/x/lib/vlog" |
| 11 | |
Cosmos Nicolaou | 9691e5d | 2015-06-17 12:24:35 -0700 | [diff] [blame] | 12 | "v.io/v23/context" |
Cosmos Nicolaou | 0e4e392 | 2015-06-10 16:30:09 -0700 | [diff] [blame] | 13 | "v.io/v23/logging" |
| 14 | |
| 15 | "v.io/x/ref/internal/logger" |
| 16 | ) |
| 17 | |
| 18 | func TestManager(t *testing.T) { |
| 19 | global := logger.Global() |
| 20 | if _, ok := global.(*vlog.Logger); !ok { |
| 21 | t.Fatalf("global logger is not a vlog.Logger") |
| 22 | } |
| 23 | |
| 24 | manager := logger.Manager(logger.Global()) |
| 25 | if _, ok := manager.(*vlog.Logger); !ok { |
| 26 | t.Fatalf("logger.Manager does not return a vlog.Logger") |
| 27 | } |
| 28 | |
| 29 | // Make sure vlog.Log satisfies the logging interfaces |
| 30 | var _ logger.ManageLog = vlog.Log |
| 31 | var _ logging.Logger = vlog.Log |
Cosmos Nicolaou | 9691e5d | 2015-06-17 12:24:35 -0700 | [diff] [blame] | 32 | |
| 33 | // Make sure context.T implements logging.T |
| 34 | ctx, _ := context.RootContext() |
| 35 | var _ logging.Logger = ctx |
| 36 | |
| 37 | // Make sure that logger.Manager can extract the appropriate management |
| 38 | // interface from a context. |
| 39 | nl := vlog.NewLogger("test") |
| 40 | ctx = context.WithLogger(ctx, nl) |
| 41 | manager = logger.Manager(ctx) |
| 42 | if _, ok := manager.(*vlog.Logger); !ok { |
| 43 | t.Errorf("failed to extract correct manager type") |
| 44 | } |
Cosmos Nicolaou | 0e4e392 | 2015-06-10 16:30:09 -0700 | [diff] [blame] | 45 | } |