30 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
8 changed files with 63 additions and 37 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=
+18 -11
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,28 +21,36 @@ package apex
import ( import (
"fmt" "fmt"
"github.com/apex/log" "sync"
"github.com/sanity-io/litter"
"testing" "testing"
"github.com/apex/log"
"github.com/stretchr/testify/assert"
) )
// Mock has a Logger for use in unit-testing // Mock has a Logger for use in unit-testing
type Mock struct { type Mock struct {
Logger log.Interface *sync.RWMutex
log.Interface
Logged []string Logged []string
} }
// HandleLog stores the logged entries to be able to check them later // HandleLog stores the logged entries to be able to check them later
func (m *Mock) HandleLog(entry *log.Entry) error { 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)) m.Logged = append(m.Logged, fmt.Sprintf("%s: %s", entry.Level.String(), entry.Message))
return nil return nil
} }
var _ log.Handler = &Mock{} var _ log.Handler = &Mock{}
// New instantiates a new Mock and sets the log.Handler to it
func New() *Mock { func New() *Mock {
mock := &Mock{ mock := &Mock{
Logger: log.Log, RWMutex: &sync.RWMutex{},
Interface: log.Log,
Logged: make([]string, 0),
} }
log.SetHandler(mock) log.SetHandler(mock)
return mock return mock
@@ -51,11 +59,10 @@ func New() *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("Logger() got %s, want %s", got, want)
}
} }
assert.Equal(t, wantLogged, m.Logged)
} }
+17 -12
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,8 +21,11 @@ package apex
import ( import (
"fmt" "fmt"
"reflect" "regexp"
"sync"
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
func TestMock_Check(t *testing.T) { func TestMock_Check(t *testing.T) {
@@ -48,30 +51,25 @@ 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{`Logger() 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 TestNew(t *testing.T) { func TestNew(t *testing.T) {
logger := New() logger := New()
logger.Logger.Info("logging") logger.Info("logging")
logger.Check(t, []string{"info: logging"}) logger.Check(t, []string{"info: logging"})
} }
@@ -81,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"
]
}