Debian Codegraph @

logging_test.go

raw symbols SCIP
1 // Copyright 2015 Matthew Holt and The Caddy Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package caddy
16
17 import "testing"
18
19 func TestCustomLog_loggerAllowed(t *testing.T) {
20 type fields struct {
21 BaseLog BaseLog
22 Include []string
23 Exclude []string
24 }
25 type args struct {
26 name string
27 isModule bool
28 }
29 tests := []struct {
30 name string
31 fields fields
32 args args
33 want bool
34 }{
35 {
36 name: "include",
37 fields: fields{
38 Include: []string{"foo"},
39 },
40 args: args{
41 name: "foo",
42 isModule: true,
43 },
44 want: true,
45 },
46 {
47 name: "exclude",
48 fields: fields{
49 Exclude: []string{"foo"},
50 },
51 args: args{
52 name: "foo",
53 isModule: true,
54 },
55 want: false,
56 },
57 {
58 name: "include and exclude",
59 fields: fields{
60 Include: []string{"foo"},
61 Exclude: []string{"foo"},
62 },
63 args: args{
64 name: "foo",
65 isModule: true,
66 },
67 want: false,
68 },
69 {
70 name: "include and exclude (longer namespace)",
71 fields: fields{
72 Include: []string{"foo.bar"},
73 Exclude: []string{"foo"},
74 },
75 args: args{
76 name: "foo.bar",
77 isModule: true,
78 },
79 want: true,
80 },
81 {
82 name: "excluded module is not printed",
83 fields: fields{
84 Include: []string{"admin.api.load"},
85 Exclude: []string{"admin.api"},
86 },
87 args: args{
88 name: "admin.api",
89 isModule: false,
90 },
91 want: false,
92 },
93 }
94 for _, tt := range tests {
95 t.Run(tt.name, func(t *testing.T) {
96 cl := &CustomLog{
97 BaseLog: tt.fields.BaseLog,
98 Include: tt.fields.Include,
99 Exclude: tt.fields.Exclude,
100 }
101 if got := cl.loggerAllowed(tt.args.name, tt.args.isModule); got != tt.want {
102 t.Errorf("CustomLog.loggerAllowed() = %v, want %v", got, tt.want)
103 }
104 })
105 }
106 }