Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| add66f7268 | |||
| 0e64561a0b | |||
| dd7462897e | |||
| 8fab5ff4b7 | |||
| c659ddd2f9 | |||
| 47c83d1a02 | |||
| 7f85b25a31 | |||
| b144473111 | |||
| fff864a741 | |||
| 7642d7e9c1 | |||
| 359692e6ea | |||
| 3a53016092 | |||
| 30ee12f789 | |||
| 56f1273747 | |||
| d5e322ca9e | |||
| 18d12ed1b4 | |||
| 1e4b943789 | |||
| 7db3319133 | |||
| ae8f2131e8 | |||
| b4b561b797 | |||
| 102076fd4b | |||
| 772b67344a | |||
| 86f814ee20 | |||
| 683d641caf | |||
| 42beae6b86 | |||
| be92b5ada7 | |||
| 5785fb51d3 | |||
| 2a33733399 | |||
| 41836cebe7 | |||
| 36550f85e6 | |||
| 4e2a280ad1 | |||
| 8bf207511a |
+6
-4
@@ -20,7 +20,7 @@
|
|||||||
include:
|
include:
|
||||||
- template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml'
|
- template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml'
|
||||||
|
|
||||||
image: golang:1.15
|
image: golang:1.22
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
GOFLAGS: -mod=readonly
|
GOFLAGS: -mod=readonly
|
||||||
@@ -39,14 +39,16 @@ test:
|
|||||||
dependencies:
|
dependencies:
|
||||||
- deps
|
- deps
|
||||||
script:
|
script:
|
||||||
- go get golang.org/x/lint/golint
|
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.56.2
|
||||||
- go fmt $(go list ./...)
|
- go fmt $(go list ./...)
|
||||||
- go vet $(go list ./...)
|
- go vet $(go list ./...)
|
||||||
- golint -set_exit_status ./...
|
- golangci-lint run
|
||||||
- CGO_ENABLED=1 go test -mod=readonly -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(go list ./... | tr '\n' , | sed 's/,$//') ./...
|
- 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 -html=coverage.txt -o coverage.html
|
||||||
- go tool cover -func=coverage.txt
|
- 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:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- coverage.html
|
- coverage.html
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
run:
|
||||||
|
allow-parallel-runners: true
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
module gitlab.com/unboundsoftware/apex-mocks
|
module gitlab.com/unboundsoftware/apex-mocks
|
||||||
|
|
||||||
go 1.15
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/apex/log v1.9.0
|
github.com/apex/log v1.9.0
|
||||||
github.com/sanity-io/litter v1.3.0
|
github.com/stretchr/testify v1.9.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/pkg/errors v0.8.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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/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/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/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.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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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/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 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
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/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/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/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/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/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/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.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.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0=
|
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 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
|
||||||
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
|
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.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.2/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-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.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
|
// 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
|
// this software and associated documentation files (the "Software"), to deal in
|
||||||
@@ -21,102 +21,48 @@ package apex
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/apex/log"
|
"sync"
|
||||||
"github.com/sanity-io/litter"
|
|
||||||
"testing"
|
"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 {
|
type Mock struct {
|
||||||
|
*sync.RWMutex
|
||||||
|
log.Interface
|
||||||
Logged []string
|
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
|
// Check verifies that the application has logged the expected strings
|
||||||
func (m *Mock) Check(t testing.TB, wantLogged []string) {
|
func (m *Mock) Check(t testing.TB, wantLogged []string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if len(m.Logged) != 0 || len(wantLogged) != 0 {
|
m.RLock()
|
||||||
got := litter.Sdump(m.Logged)
|
defer m.RUnlock()
|
||||||
want := litter.Sdump(wantLogged)
|
if wantLogged == nil {
|
||||||
if got != want {
|
wantLogged = []string{}
|
||||||
t.Errorf("Mock() got %s, want %s", got, want)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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{}
|
|
||||||
|
|||||||
+20
-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
|
// 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
|
// this software and associated documentation files (the "Software"), to deal in
|
||||||
@@ -21,10 +21,11 @@ package apex
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/apex/log"
|
"regexp"
|
||||||
"reflect"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMock_Check(t *testing.T) {
|
func TestMock_Check(t *testing.T) {
|
||||||
@@ -32,7 +33,6 @@ func TestMock_Check(t *testing.T) {
|
|||||||
Logged []string
|
Logged []string
|
||||||
}
|
}
|
||||||
type args struct {
|
type args struct {
|
||||||
t *testing.T
|
|
||||||
wantLogged []string
|
wantLogged []string
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@@ -51,411 +51,26 @@ func TestMock_Check(t *testing.T) {
|
|||||||
name: "different",
|
name: "different",
|
||||||
fields: fields{Logged: []string{"same"}},
|
fields: fields{Logged: []string{"same"}},
|
||||||
args: args{wantLogged: []string{"different"}},
|
args: args{wantLogged: []string{"different"}},
|
||||||
want: []string{`Mock() got []string{
|
want: []string{"\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"},
|
||||||
"same",
|
|
||||||
}, want []string{
|
|
||||||
"different",
|
|
||||||
}`},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
m := &Mock{
|
m := &Mock{
|
||||||
Logged: tt.fields.Logged,
|
RWMutex: &sync.RWMutex{},
|
||||||
|
Logged: tt.fields.Logged,
|
||||||
}
|
}
|
||||||
temp := &MockT{}
|
temp := &MockT{}
|
||||||
m.Check(temp, tt.args.wantLogged)
|
m.Check(temp, tt.args.wantLogged)
|
||||||
if !reflect.DeepEqual(temp.errors, tt.want) {
|
assert.Equal(t, tt.want, temp.errors)
|
||||||
t.Errorf("Check() got %+v, want %+v", temp.errors, tt.want)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMock_Debug(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
type args struct {
|
logger := New()
|
||||||
s string
|
logger.Info("logging")
|
||||||
}
|
logger.Check(t, []string{"info: logging"})
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MockT struct {
|
type MockT struct {
|
||||||
@@ -464,5 +79,12 @@ type MockT struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockT) Errorf(format string, args ...interface{}) {
|
func (m *MockT) Errorf(format string, args ...interface{}) {
|
||||||
|
re, err := regexp.Compile(`(?s)^\tError Trace:.*(\tError:.*)$`)
|
||||||
|
assert.NoError(m, err)
|
||||||
|
for i, a := range args {
|
||||||
|
if s, ok := a.(string); ok {
|
||||||
|
args[i] = re.ReplaceAllString(s, "$1")
|
||||||
|
}
|
||||||
|
}
|
||||||
m.errors = append(m.errors, fmt.Sprintf(format, args...))
|
m.errors = append(m.errors, fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"config:recommended"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user