mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-23 02:29:59 +08:00

Some checks failed
Lint / lint (macos-14, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy, ~1.24.1, macos-14, 0, 1.24, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy, ~1.24.1, ubuntu-latest, 0, 1.24, linux) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy.exe, ~1.24.1, windows-latest, True, 1.24, windows) (push) Has been cancelled
Tests / test (s390x on IBM Z) (push) Has been cancelled
Tests / goreleaser-check (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, aix) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, darwin) (push) Has been cancelled
Lint / lint (ubuntu-latest, linux) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, dragonfly) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, freebsd) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, illumos) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, linux) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, netbsd) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, openbsd) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, solaris) (push) Has been cancelled
Cross-Build / build (~1.24.1, 1.24, windows) (push) Has been cancelled
Lint / lint (windows-latest, windows) (push) Has been cancelled
Lint / govulncheck (push) Has been cancelled
* log: default logger should respect `{in,ex}clude` Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> * add tests Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com> --------- Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>
107 lines
2.2 KiB
Go
107 lines
2.2 KiB
Go
// Copyright 2015 Matthew Holt and The Caddy Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package caddy
|
|
|
|
import "testing"
|
|
|
|
func TestCustomLog_loggerAllowed(t *testing.T) {
|
|
type fields struct {
|
|
BaseLog BaseLog
|
|
Include []string
|
|
Exclude []string
|
|
}
|
|
type args struct {
|
|
name string
|
|
isModule bool
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
want bool
|
|
}{
|
|
{
|
|
name: "include",
|
|
fields: fields{
|
|
Include: []string{"foo"},
|
|
},
|
|
args: args{
|
|
name: "foo",
|
|
isModule: true,
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "exclude",
|
|
fields: fields{
|
|
Exclude: []string{"foo"},
|
|
},
|
|
args: args{
|
|
name: "foo",
|
|
isModule: true,
|
|
},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "include and exclude",
|
|
fields: fields{
|
|
Include: []string{"foo"},
|
|
Exclude: []string{"foo"},
|
|
},
|
|
args: args{
|
|
name: "foo",
|
|
isModule: true,
|
|
},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "include and exclude (longer namespace)",
|
|
fields: fields{
|
|
Include: []string{"foo.bar"},
|
|
Exclude: []string{"foo"},
|
|
},
|
|
args: args{
|
|
name: "foo.bar",
|
|
isModule: true,
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "excluded module is not printed",
|
|
fields: fields{
|
|
Include: []string{"admin.api.load"},
|
|
Exclude: []string{"admin.api"},
|
|
},
|
|
args: args{
|
|
name: "admin.api",
|
|
isModule: false,
|
|
},
|
|
want: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
cl := &CustomLog{
|
|
BaseLog: tt.fields.BaseLog,
|
|
Include: tt.fields.Include,
|
|
Exclude: tt.fields.Exclude,
|
|
}
|
|
if got := cl.loggerAllowed(tt.args.name, tt.args.isModule); got != tt.want {
|
|
t.Errorf("CustomLog.loggerAllowed() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|