| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
package verbosity |
| 19 |
|
| 20 |
import ( |
| 21 |
"testing" |
| 22 |
|
| 23 |
"k8s.io/klog/v2/internal/test/require" |
| 24 |
) |
| 25 |
|
| 26 |
func TestV(t *testing.T) { |
| 27 |
vs := New() |
| 28 |
require.NoError(t, vs.verbosity.Set("2")) |
| 29 |
depth := 0 |
| 30 |
if !vs.Enabled(1, depth) { |
| 31 |
t.Error("not enabled for 1") |
| 32 |
} |
| 33 |
if !vs.Enabled(2, depth) { |
| 34 |
t.Error("not enabled for 2") |
| 35 |
} |
| 36 |
if vs.Enabled(3, depth) { |
| 37 |
t.Error("enabled for 3") |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
func TestVmoduleOn(t *testing.T) { |
| 42 |
vs := New() |
| 43 |
require.NoError(t, vs.vmodule.Set("verbosity_test=2")) |
| 44 |
depth := 0 |
| 45 |
if !vs.Enabled(1, depth) { |
| 46 |
t.Error("not enabled for 1") |
| 47 |
} |
| 48 |
if !vs.Enabled(2, depth) { |
| 49 |
t.Error("not enabled for 2") |
| 50 |
} |
| 51 |
if vs.Enabled(3, depth) { |
| 52 |
t.Error("enabled for 3") |
| 53 |
} |
| 54 |
if enabledInHelper(vs, 1) { |
| 55 |
t.Error("enabled for helper at 1") |
| 56 |
} |
| 57 |
if enabledInHelper(vs, 2) { |
| 58 |
t.Error("enabled for helper at 2") |
| 59 |
} |
| 60 |
if enabledInHelper(vs, 3) { |
| 61 |
t.Error("enabled for helper at 3") |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
var vGlobs = map[string]bool{ |
| 67 |
|
| 68 |
"verbosity_test=1": false, |
| 69 |
"verbosity_test=2": true, |
| 70 |
"verbosity_test=3": true, |
| 71 |
|
| 72 |
"*=2": true, |
| 73 |
"?e*=2": true, |
| 74 |
"?????????_*=2": true, |
| 75 |
"??[arx]??????_*t=2": true, |
| 76 |
|
| 77 |
"*x=2": false, |
| 78 |
"m*=2": false, |
| 79 |
"??_*=2": false, |
| 80 |
"?[abc]?_*t=2": false, |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
func testVmoduleGlob(pat string, match bool, t *testing.T) { |
| 85 |
vs := New() |
| 86 |
require.NoError(t, vs.vmodule.Set(pat)) |
| 87 |
depth := 0 |
| 88 |
actual := vs.Enabled(2, depth) |
| 89 |
if actual != match { |
| 90 |
t.Errorf("incorrect match for %q: got %#v expected %#v", pat, actual, match) |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
func TestVmoduleGlob(t *testing.T) { |
| 96 |
for glob, match := range vGlobs { |
| 97 |
testVmoduleGlob(glob, match, t) |
| 98 |
} |
| 99 |
} |