Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d5e322ca9e | |||
| 18d12ed1b4 | |||
| 1e4b943789 | |||
| 7db3319133 | |||
| ae8f2131e8 | |||
| b4b561b797 | |||
| 102076fd4b | |||
| 772b67344a | |||
| 86f814ee20 | |||
| 683d641caf | |||
| 42beae6b86 | |||
| be92b5ada7 | |||
| 5785fb51d3 | |||
| 2a33733399 | |||
| 41836cebe7 | |||
| 36550f85e6 | |||
| 4e2a280ad1 | |||
| 8bf207511a |
+3
-1
@@ -46,7 +46,9 @@ test:
|
||||
- CGO_ENABLED=1 go test -mod=readonly -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(go list ./... | tr '\n' , | sed 's/,$//') ./...
|
||||
- go tool cover -html=coverage.txt -o coverage.html
|
||||
- go tool cover -func=coverage.txt
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
- curl -Os https://uploader.codecov.io/latest/linux/codecov
|
||||
- chmod +x codecov
|
||||
- ./codecov -t ${CODECOV_TOKEN}
|
||||
artifacts:
|
||||
paths:
|
||||
- coverage.html
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
open-pull-requests-limit: 20
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Unbound Software Development Svenska AB
|
||||
Copyright (c) 2022 Unbound Software Development Svenska AB
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -4,5 +4,5 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/apex/log v1.9.0
|
||||
github.com/sanity-io/litter v1.3.0
|
||||
github.com/stretchr/testify v1.7.2
|
||||
)
|
||||
|
||||
@@ -5,7 +5,6 @@ github.com/aphistic/golf v0.0.0-20180712155816-02c07f170c5a/go.mod h1:3NqKYiepwy
|
||||
github.com/aphistic/sweet v0.2.0/go.mod h1:fWDlIh/isSE9n6EPsRmC0det+whmX6dJid3stzu0Xys=
|
||||
github.com/aws/aws-sdk-go v1.20.6/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
||||
github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I=
|
||||
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -33,21 +32,18 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
|
||||
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/sanity-io/litter v1.3.0 h1:5ZO+weUsqdSWMUng5JnpkW/Oz8iTXiIdeumhQr1sSjs=
|
||||
github.com/sanity-io/litter v1.3.0/go.mod h1:5Z71SvaYy5kcGtyglXOC9rrUi3c1E8CamFWjQsazTh0=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
|
||||
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM=
|
||||
github.com/smartystreets/gunit v1.0.0/go.mod h1:qwPWnhz6pn0NnRBP++URONOVyNkPyr4SauJk4cUOwJs=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
|
||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||
github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0=
|
||||
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
|
||||
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
|
||||
@@ -76,5 +72,6 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c h1:grhR+C34yXImVGp7EzNk+DTIk+323eIUWOmEevy6bDo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2020 Unbound Software Development Svenska AB
|
||||
// Copyright (c) 2022 Unbound Software Development Svenska AB
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
@@ -21,102 +21,48 @@ package apex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/apex/log"
|
||||
"github.com/sanity-io/litter"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// Mock implements `log.Interface` for use in unit-testing
|
||||
// Mock has a Logger for use in unit-testing
|
||||
type Mock struct {
|
||||
*sync.RWMutex
|
||||
log.Interface
|
||||
Logged []string
|
||||
}
|
||||
|
||||
// HandleLog stores the logged entries to be able to check them later
|
||||
func (m *Mock) HandleLog(entry *log.Entry) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
m.Logged = append(m.Logged, fmt.Sprintf("%s: %s", entry.Level.String(), entry.Message))
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ log.Handler = &Mock{}
|
||||
|
||||
// New instantiates a new Mock and sets the log.Handler to it
|
||||
func New() *Mock {
|
||||
mock := &Mock{
|
||||
RWMutex: &sync.RWMutex{},
|
||||
Interface: log.Log,
|
||||
Logged: make([]string, 0),
|
||||
}
|
||||
log.SetHandler(mock)
|
||||
return mock
|
||||
}
|
||||
|
||||
// Check verifies that the application has logged the expected strings
|
||||
func (m *Mock) Check(t testing.TB, wantLogged []string) {
|
||||
t.Helper()
|
||||
if len(m.Logged) != 0 || len(wantLogged) != 0 {
|
||||
got := litter.Sdump(m.Logged)
|
||||
want := litter.Sdump(wantLogged)
|
||||
if got != want {
|
||||
t.Errorf("Mock() got %s, want %s", got, want)
|
||||
}
|
||||
m.RLock()
|
||||
defer m.RUnlock()
|
||||
if wantLogged == nil {
|
||||
wantLogged = []string{}
|
||||
}
|
||||
assert.Equal(t, wantLogged, m.Logged)
|
||||
}
|
||||
|
||||
// Debug implements log.Interface Debug
|
||||
func (m *Mock) Debug(s string) {
|
||||
m.Logged = append(m.Logged, fmt.Sprintf("DEBUG: %s", s))
|
||||
}
|
||||
|
||||
// Info implements log.Interface Info
|
||||
func (m *Mock) Info(s string) {
|
||||
m.Logged = append(m.Logged, fmt.Sprintf("INFO: %s", s))
|
||||
}
|
||||
|
||||
// Warn implements log.Interface Warn
|
||||
func (m *Mock) Warn(s string) {
|
||||
m.Logged = append(m.Logged, fmt.Sprintf("WARN: %s", s))
|
||||
}
|
||||
|
||||
// Error implements log.Interface Error
|
||||
func (m *Mock) Error(s string) {
|
||||
m.Logged = append(m.Logged, fmt.Sprintf("ERROR: %s", s))
|
||||
}
|
||||
|
||||
// Fatal implements log.Interface Fatal
|
||||
func (m *Mock) Fatal(s string) {
|
||||
m.Logged = append(m.Logged, fmt.Sprintf("FATAL: %s", s))
|
||||
}
|
||||
|
||||
// Debugf implements log.Interface Debugf
|
||||
func (m *Mock) Debugf(s string, i ...interface{}) {
|
||||
m.Logged = append(m.Logged, fmt.Sprintf("DEBUG: %s", fmt.Sprintf(s, i...)))
|
||||
}
|
||||
|
||||
// Infof implements log.Interface Infof
|
||||
func (m *Mock) Infof(s string, i ...interface{}) {
|
||||
m.Logged = append(m.Logged, fmt.Sprintf("INFO: %s", fmt.Sprintf(s, i...)))
|
||||
}
|
||||
|
||||
// Warnf implements log.Interface Warnf
|
||||
func (m *Mock) Warnf(s string, i ...interface{}) {
|
||||
m.Logged = append(m.Logged, fmt.Sprintf("WARN: %s", fmt.Sprintf(s, i...)))
|
||||
}
|
||||
|
||||
// Errorf implements log.Interface Errorf
|
||||
func (m *Mock) Errorf(s string, i ...interface{}) {
|
||||
m.Logged = append(m.Logged, fmt.Sprintf("ERROR: %s", fmt.Sprintf(s, i...)))
|
||||
}
|
||||
|
||||
// Fatalf implements log.Interface Fatalf
|
||||
func (m *Mock) Fatalf(s string, i ...interface{}) {
|
||||
m.Logged = append(m.Logged, fmt.Sprintf("FATAL: %s", fmt.Sprintf(s, i...)))
|
||||
}
|
||||
|
||||
// Trace implements log.Interface Trace
|
||||
func (m *Mock) Trace(string) *log.Entry {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithFields implements log.Interface WithFields
|
||||
func (m *Mock) WithFields(log.Fielder) *log.Entry {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithField implements log.Interface WithField
|
||||
func (m *Mock) WithField(string, interface{}) *log.Entry {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithDuration implements log.Interface WithDuration
|
||||
func (m *Mock) WithDuration(time.Duration) *log.Entry {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithError implements log.Interface WithError
|
||||
func (m *Mock) WithError(error) *log.Entry {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ log.Interface = &Mock{}
|
||||
|
||||
+12
-398
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2020 Unbound Software Development Svenska AB
|
||||
// Copyright (c) 2022 Unbound Software Development Svenska AB
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
@@ -21,10 +21,10 @@ package apex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/apex/log"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMock_Check(t *testing.T) {
|
||||
@@ -32,7 +32,6 @@ func TestMock_Check(t *testing.T) {
|
||||
Logged []string
|
||||
}
|
||||
type args struct {
|
||||
t *testing.T
|
||||
wantLogged []string
|
||||
}
|
||||
tests := []struct {
|
||||
@@ -51,411 +50,26 @@ func TestMock_Check(t *testing.T) {
|
||||
name: "different",
|
||||
fields: fields{Logged: []string{"same"}},
|
||||
args: args{wantLogged: []string{"different"}},
|
||||
want: []string{`Mock() got []string{
|
||||
"same",
|
||||
}, want []string{
|
||||
"different",
|
||||
}`},
|
||||
want: []string{"\n\tError Trace:\tmocks.go:67\n\t \t\t\t\tmocks_test.go:63\n\tError: \tNot equal: \n\t \texpected: []string{\"different\"}\n\t \tactual : []string{\"same\"}\n\t \t\n\t \tDiff:\n\t \t--- Expected\n\t \t+++ Actual\n\t \t@@ -1,3 +1,3 @@\n\t \t ([]string) (len=1) {\n\t \t- (string) (len=9) \"different\"\n\t \t+ (string) (len=4) \"same\"\n\t \t }\n\tTest: \t\n"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{
|
||||
Logged: tt.fields.Logged,
|
||||
RWMutex: &sync.RWMutex{},
|
||||
Logged: tt.fields.Logged,
|
||||
}
|
||||
temp := &MockT{}
|
||||
m.Check(temp, tt.args.wantLogged)
|
||||
if !reflect.DeepEqual(temp.errors, tt.want) {
|
||||
t.Errorf("Check() got %+v, want %+v", temp.errors, tt.want)
|
||||
}
|
||||
assert.Equal(t, tt.want, temp.errors)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_Debug(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "debug",
|
||||
args: args{s: "something"},
|
||||
want: []string{"DEBUG: something"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
m.Debug(tt.args.s)
|
||||
m.Check(t, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_Debugf(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
i []interface{}
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "debugf",
|
||||
args: args{
|
||||
s: "%s - %d",
|
||||
i: []interface{}{"a", 5},
|
||||
},
|
||||
want: []string{"DEBUG: a - 5"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
m.Debugf(tt.args.s, tt.args.i...)
|
||||
m.Check(t, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_Error(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "error",
|
||||
args: args{s: "something"},
|
||||
want: []string{"ERROR: something"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
m.Error(tt.args.s)
|
||||
m.Check(t, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_Errorf(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
i []interface{}
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "errorf",
|
||||
args: args{
|
||||
s: "%s - %d",
|
||||
i: []interface{}{"a", 5},
|
||||
},
|
||||
want: []string{"ERROR: a - 5"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
m.Errorf(tt.args.s, tt.args.i...)
|
||||
m.Check(t, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_Fatal(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "fatal",
|
||||
args: args{s: "something"},
|
||||
want: []string{"FATAL: something"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
m.Fatal(tt.args.s)
|
||||
m.Check(t, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_Fatalf(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
i []interface{}
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "fatalf",
|
||||
args: args{
|
||||
s: "%s - %d",
|
||||
i: []interface{}{"a", 5},
|
||||
},
|
||||
want: []string{"FATAL: a - 5"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
m.Fatalf(tt.args.s, tt.args.i...)
|
||||
m.Check(t, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_Info(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "info",
|
||||
args: args{s: "something"},
|
||||
want: []string{"INFO: something"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
m.Info(tt.args.s)
|
||||
m.Check(t, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_Infof(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
i []interface{}
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "infof",
|
||||
args: args{
|
||||
s: "%s - %d",
|
||||
i: []interface{}{"a", 5},
|
||||
},
|
||||
want: []string{"INFO: a - 5"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
m.Infof(tt.args.s, tt.args.i...)
|
||||
m.Check(t, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_Trace(t *testing.T) {
|
||||
type args struct {
|
||||
in0 string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *log.Entry
|
||||
}{
|
||||
{
|
||||
name: "always return nil",
|
||||
args: args{},
|
||||
want: nil,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
if got := m.Trace(tt.args.in0); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("Trace() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_Warn(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "warn",
|
||||
args: args{s: "something"},
|
||||
want: []string{"WARN: something"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
m.Warn(tt.args.s)
|
||||
m.Check(t, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_Warnf(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
i []interface{}
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "warnf",
|
||||
args: args{
|
||||
s: "%s - %d",
|
||||
i: []interface{}{"a", 5},
|
||||
},
|
||||
want: []string{"WARN: a - 5"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
m.Warnf(tt.args.s, tt.args.i...)
|
||||
m.Check(t, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_WithDuration(t *testing.T) {
|
||||
type args struct {
|
||||
in0 time.Duration
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *log.Entry
|
||||
}{
|
||||
{
|
||||
name: "always return nil",
|
||||
args: args{},
|
||||
want: nil,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
if got := m.WithDuration(tt.args.in0); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("WithDuration() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_WithError(t *testing.T) {
|
||||
type args struct {
|
||||
in0 error
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *log.Entry
|
||||
}{
|
||||
{
|
||||
name: "always return nil",
|
||||
args: args{},
|
||||
want: nil,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
if got := m.WithError(tt.args.in0); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("WithError() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_WithField(t *testing.T) {
|
||||
type args struct {
|
||||
in0 string
|
||||
in1 interface{}
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *log.Entry
|
||||
}{
|
||||
{
|
||||
name: "always return nil",
|
||||
args: args{},
|
||||
want: nil,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
if got := m.WithField(tt.args.in0, tt.args.in1); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("WithField() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMock_WithFields(t *testing.T) {
|
||||
type args struct {
|
||||
in0 log.Fielder
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *log.Entry
|
||||
}{
|
||||
{
|
||||
name: "always return nil",
|
||||
args: args{},
|
||||
want: nil,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Mock{}
|
||||
if got := m.WithFields(tt.args.in0); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("WithFields() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
func TestNew(t *testing.T) {
|
||||
logger := New()
|
||||
logger.Info("logging")
|
||||
logger.Check(t, []string{"info: logging"})
|
||||
}
|
||||
|
||||
type MockT struct {
|
||||
|
||||
Reference in New Issue
Block a user