| 1 |
/* |
| 2 |
Copyright 2020 The logr Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package logr |
| 18 |
|
| 19 |
import ( |
| 20 |
"errors" |
| 21 |
"reflect" |
| 22 |
"testing" |
| 23 |
) |
| 24 |
|
| 25 |
func TestDiscard(t *testing.T) { |
| 26 |
l := Discard() |
| 27 |
if l.GetSink() != nil { |
| 28 |
t.Error("did not return the expected underlying type") |
| 29 |
} |
| 30 |
// Verify that none of the methods panic, there is not more we can test. |
| 31 |
l.WithName("discard").WithValues("z", 5).Info("Hello world") |
| 32 |
l.Info("Hello world", "x", 1, "y", 2) |
| 33 |
l.V(1).Error(errors.New("foo"), "a", 123) |
| 34 |
if l.Enabled() { |
| 35 |
t.Error("discard loggers must always be disabled") |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
func TestComparable(t *testing.T) { |
| 40 |
a := Discard() |
| 41 |
if !reflect.TypeOf(a).Comparable() { |
| 42 |
t.Fatal("discard loggers must be comparable") |
| 43 |
} |
| 44 |
|
| 45 |
b := Discard() |
| 46 |
if a != b { |
| 47 |
t.Fatal("any two discard Loggers must be equal") |
| 48 |
} |
| 49 |
|
| 50 |
c := Discard().V(2) |
| 51 |
if b != c { |
| 52 |
t.Fatal("any two discard Loggers must be equal") |
| 53 |
} |
| 54 |
} |