32 Commits

Author SHA1 Message Date
Renovate add66f7268 fix(deps): update module github.com/stretchr/testify to v1.9.0 2024-03-01 12:56:52 +00:00
Renovate 0e64561a0b chore(deps): update golang docker tag to v1.22 2024-02-24 13:49:01 +01:00
Renovate dd7462897e Add renovate.json 2024-02-23 23:27:30 +01:00
argoyle 8fab5ff4b7 chore(deps): bump github.com/stretchr/testify from 1.8.3 to 1.8.4
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.3 to 1.8.4.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.3...v1.8.4)
2023-05-30 19:07:28 +00:00
argoyle c659ddd2f9 chore(deps): bump github.com/stretchr/testify from 1.8.2 to 1.8.3
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.2 to 1.8.3.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.2...v1.8.3)
2023-05-20 08:59:12 +02:00
argoyle 47c83d1a02 ci: replace golint with golangci-lint 2023-05-20 08:57:01 +02:00
argoyle 7f85b25a31 chore(deps): bump github.com/stretchr/testify from 1.8.1 to 1.8.2
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.1 to 1.8.2.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.1...v1.8.2)
2023-02-25 19:07:28 +00:00
argoyle b144473111 ci: switch to manual rebases for Dependabot 2023-02-10 11:25:01 +01:00
argoyle fff864a741 chore(deps): bump github.com/stretchr/testify from 1.8.0 to 1.8.1
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.0...v1.8.1)
2022-10-24 19:07:13 +00:00
argoyle 7642d7e9c1 fix: ugly hack to ignore error trace 2022-06-30 08:29:20 +02:00
argoyle 359692e6ea chore(deps): bump github.com/stretchr/testify from 1.7.5 to 1.8.0
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.5 to 1.8.0.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.5...v1.8.0)
2022-06-29 19:07:13 +00:00
argoyle 3a53016092 chore(deps): bump github.com/stretchr/testify from 1.7.4 to 1.7.5
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.4 to 1.7.5.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.4...v1.7.5)
2022-06-24 19:07:14 +00:00
argoyle 30ee12f789 chore(deps): bump github.com/stretchr/testify from 1.7.3 to 1.7.4
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.3 to 1.7.4.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.3...v1.7.4)
2022-06-21 19:07:15 +00:00
argoyle 56f1273747 chore(deps): bump github.com/stretchr/testify from 1.7.2 to 1.7.3
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.2 to 1.7.3.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.2...v1.7.3)
2022-06-20 19:07:10 +00:00
argoyle d5e322ca9e chore: inline log.Interface and handle empty and nil slices the same 2022-06-17 09:54:48 +02:00
argoyle 18d12ed1b4 chore(deps): bump github.com/stretchr/testify from 1.6.1 to 1.7.2
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.6.1 to 1.7.2.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.6.1...v1.7.2)
2022-06-16 19:07:34 +00:00
argoyle 1e4b943789 fix: add mutex to fix race conditions for consumers 2022-06-16 11:54:32 +02:00
argoyle 7db3319133 Merge branch 'dependabot-go_modules-github.com-sanity-io-litter-1.5.5' into 'master'
chore(deps): bump github.com/sanity-io/litter from 1.5.4 to 1.5.5

See merge request unboundsoftware/apex-mocks!6
2022-04-28 20:44:47 +00:00
argoyle ae8f2131e8 chore(deps): bump github.com/sanity-io/litter from 1.5.4 to 1.5.5
Bumps [github.com/sanity-io/litter](https://github.com/sanity-io/litter) from 1.5.4 to 1.5.5.
- [Release notes](https://github.com/sanity-io/litter/releases)
- [Changelog](https://github.com/sanity-io/litter/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sanity-io/litter/compare/v1.5.4...v1.5.5)
2022-04-28 19:07:14 +00:00
argoyle b4b561b797 Merge branch 'dependabot-go_modules-github.com-sanity-io-litter-1.5.4' into 'master'
chore(deps): bump github.com/sanity-io/litter from 1.5.2 to 1.5.4

See merge request unboundsoftware/apex-mocks!5
2022-03-15 07:12:35 +00:00
argoyle 102076fd4b chore(deps): bump github.com/sanity-io/litter from 1.5.2 to 1.5.4
Bumps [github.com/sanity-io/litter](https://github.com/sanity-io/litter) from 1.5.2 to 1.5.4.
- [Release notes](https://github.com/sanity-io/litter/releases)
- [Changelog](https://github.com/sanity-io/litter/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sanity-io/litter/compare/v1.5.2...v1.5.4)
2022-03-14 19:08:10 +00:00
argoyle 772b67344a Merge branch 'dependabot-go_modules-github.com-sanity-io-litter-1.5.2' into 'master'
chore(deps): bump github.com/sanity-io/litter from 1.5.1 to 1.5.2

See merge request unboundsoftware/apex-mocks!4
2022-01-08 14:46:41 +00:00
argoyle 86f814ee20 chore(deps): bump github.com/sanity-io/litter from 1.5.1 to 1.5.2
Bumps [github.com/sanity-io/litter](https://github.com/sanity-io/litter) from 1.5.1 to 1.5.2.
- [Release notes](https://github.com/sanity-io/litter/releases)
- [Changelog](https://github.com/sanity-io/litter/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sanity-io/litter/compare/v1.5.1...v1.5.2)
2022-01-07 19:07:42 +00:00
argoyle 683d641caf Merge branch 'codecov' into 'master'
ci: change to codecov binary instead of bash uploader

See merge request unboundsoftware/apex-mocks!3
2021-11-17 05:41:48 +00:00
argoyle 42beae6b86 ci: change to codecov binary instead of bash uploader 2021-11-17 06:39:59 +01:00
argoyle be92b5ada7 Merge branch 'dependabot-go_modules-github.com-sanity-io-litter-1.5.1' into 'master'
chore(deps): bump github.com/sanity-io/litter from 1.3.0 to 1.5.1

See merge request unboundsoftware/apex-mocks!2
2021-11-04 10:11:38 +00:00
argoyle 5785fb51d3 chore(deps): bump github.com/sanity-io/litter from 1.3.0 to 1.5.1
Bumps [github.com/sanity-io/litter](https://github.com/sanity-io/litter) from 1.3.0 to 1.5.1.
- [Release notes](https://github.com/sanity-io/litter/releases)
- [Changelog](https://github.com/sanity-io/litter/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sanity-io/litter/compare/v1.3.0...v1.5.1)
2021-11-04 07:47:17 +00:00
argoyle 2a33733399 Merge branch 'dependabot' into 'master'
ci: add dependabot config

See merge request unboundsoftware/apex-mocks!1
2021-11-03 18:10:39 +00:00
argoyle 41836cebe7 ci: add dependabot config 2021-11-03 19:08:49 +01:00
argoyle 36550f85e6 fix: document New-func 2021-01-27 09:12:05 +01:00
argoyle 4e2a280ad1 chore: change implementation to be able to handle WithFields etc. 2021-01-27 09:07:03 +01:00
argoyle 8bf207511a chore: change Mock to Logger to me error source more clear 2021-01-18 13:06:00 +01:00
8 changed files with 82 additions and 500 deletions
+6 -4
View File
@@ -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
+2
View File
@@ -0,0 +1,2 @@
run:
allow-parallel-runners: true
+1 -1
View File
@@ -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
+9 -2
View File
@@ -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
) )
+4 -7
View File
@@ -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=
+34 -88
View File
@@ -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
View File
@@ -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...))
} }
+6
View File
@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
]
}