Switch to stretchr/testify / mockery for mocks

testify is used throughout the codebase; this switches mocks from
gomock to testify with the help of mockery for code generation.

Handlers and mocks in test/utils/oidc are moved to a new package:
mockery operates package by package, and requires packages to build
correctly; test/utils/oidc/testserver.go relies on the mocks and fails
to build when they are removed. Moving the interface and mocks to a
different package allows mockery to process that package without
having to build testserver.go.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
This commit is contained in:
Stephen Kitt 2024-06-04 19:29:42 +02:00
parent 78377c4d10
commit 3f36c83c68
No known key found for this signature in database
GPG Key ID: 1CC5FA453662A71D
97 changed files with 12593 additions and 5640 deletions

26
LICENSES/vendor/github.com/stretchr/objx/LICENSE generated vendored Normal file
View File

@ -0,0 +1,26 @@
= vendor/github.com/stretchr/objx licensed under: =
The MIT License
Copyright (c) 2014 Stretchr, Inc.
Copyright (c) 2017-2018 objx contributors
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 the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
= vendor/github.com/stretchr/objx/LICENSE d023fd31d3ca39ec61eec65a91732735

View File

@ -1,206 +0,0 @@
= vendor/go.uber.org/mock licensed under: =
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
= vendor/go.uber.org/mock/LICENSE 3b83ef96387f14655fc854ddc3c6bd57

2
go.mod
View File

@ -69,7 +69,6 @@ require (
go.opentelemetry.io/otel/trace v1.20.0
go.opentelemetry.io/proto/otlp v1.0.0
go.uber.org/goleak v1.3.0
go.uber.org/mock v0.4.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.23.0
golang.org/x/net v0.25.0
@ -192,6 +191,7 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 // indirect
github.com/x448/float16 v0.8.4 // indirect

2
go.sum
View File

@ -717,8 +717,6 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=

View File

@ -8,8 +8,8 @@ require (
github.com/client9/misspell v0.3.4
github.com/golangci/golangci-lint v1.56.2
github.com/jcchavezs/porto v0.6.0
github.com/vektra/mockery/v2 v2.40.3
go.uber.org/automaxprocs v1.5.2
go.uber.org/mock v0.4.0
gotest.tools/gotestsum v1.6.4
honnef.co/go/tools v0.4.6
sigs.k8s.io/logtools v0.8.1
@ -47,6 +47,7 @@ require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/charithe/durationcheck v0.0.10 // indirect
github.com/chavacava/garif v0.1.0 // indirect
github.com/chigopher/pathlib v0.19.1 // indirect
github.com/curioswitch/go-reassign v0.2.0 // indirect
github.com/daixiang0/gci v0.12.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
@ -57,7 +58,7 @@ require (
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/firefart/nonamedreturns v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fzipp/gocyclo v0.6.0 // indirect
github.com/ghostiam/protogetter v0.3.4 // indirect
github.com/go-critic/go-critic v0.11.1 // indirect
@ -92,9 +93,12 @@ require (
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jgautheron/goconst v1.7.0 // indirect
github.com/jingyugao/rowserrcheck v1.1.1 // indirect
github.com/jinzhu/copier v0.3.5 // indirect
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect
github.com/jjti/go-spancheck v0.5.2 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
@ -110,7 +114,7 @@ require (
github.com/leonklingele/grouper v1.1.1 // indirect
github.com/lufeee/execinquery v1.2.1 // indirect
github.com/macabu/inamedparam v0.1.3 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/maratori/testableexamples v1.0.0 // indirect
github.com/maratori/testpackage v1.1.1 // indirect
github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26 // indirect
@ -124,13 +128,11 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moricho/tparallel v0.3.1 // indirect
github.com/nakabonne/nestif v0.3.1 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/nishanths/exhaustive v0.12.0 // indirect
github.com/nishanths/predeclared v0.2.2 // indirect
github.com/nunnatsa/ginkgolinter v0.15.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polyfloyd/go-errorlint v1.4.8 // indirect
@ -142,6 +144,7 @@ require (
github.com/quasilyte/gogrep v0.5.0 // indirect
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
github.com/rs/zerolog v1.29.0 // indirect
github.com/ryancurrah/gomodguard v1.3.0 // indirect
github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect
github.com/sanposhiho/wastedassign/v2 v2.0.7 // indirect
@ -160,12 +163,12 @@ require (
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.13.0 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect
github.com/tdakkota/asciicheck v0.2.0 // indirect
github.com/tetafro/godot v1.4.16 // indirect
@ -183,8 +186,8 @@ require (
gitlab.com/bosi/decorder v0.4.1 // indirect
go-simpler.org/musttag v0.8.0 // indirect
go-simpler.org/sloglint v0.4.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
@ -196,7 +199,6 @@ require (
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.18.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect

View File

@ -114,12 +114,15 @@ github.com/charithe/durationcheck v0.0.10 h1:wgw73BiocdBDQPik+zcEoBG/ob8uyBHf2iy
github.com/charithe/durationcheck v0.0.10/go.mod h1:bCWXb7gYRysD1CU3C+u4ceO49LoGOY1C1L6uouGNreQ=
github.com/chavacava/garif v0.1.0 h1:2JHa3hbYf5D9dsgseMKAmc/MZ109otzgNFk5s87H9Pc=
github.com/chavacava/garif v0.1.0/go.mod h1:XMyYCkEL58DF0oyW4qDjjnPWONs2HBqYKI+UIPD+Gww=
github.com/chigopher/pathlib v0.19.1 h1:RoLlUJc0CqBGwq239cilyhxPNLXTK+HXoASGyGznx5A=
github.com/chigopher/pathlib v0.19.1/go.mod h1:tzC1dZLW8o33UQpWkNkhvPwL5n4yyFRFm/jL1YGWFvY=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/curioswitch/go-reassign v0.2.0 h1:G9UZyOcpk/d7Gd6mqYgd8XYWFMw/znxwGDUstnC9DIo=
github.com/curioswitch/go-reassign v0.2.0/go.mod h1:x6OpXuWvgfQaMGks2BZybTngWjT84hqJfKoO8Tt/Roc=
@ -150,8 +153,8 @@ github.com/firefart/nonamedreturns v1.0.4/go.mod h1:TDhe/tjI1BXo48CmYbUduTV7BdIg
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fzipp/gocyclo v0.6.0 h1:lsblElZG7d3ALtGMx9fmxeTKZaLLpU8mET09yN4BBLo=
github.com/fzipp/gocyclo v0.6.0/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA=
github.com/ghostiam/protogetter v0.3.4 h1:5SZ+lZSNmNkSbGVSF9hUHhv/b7ELF9Rwchoq7btYo6c=
@ -198,6 +201,7 @@ github.com/go-xmlfmt/xmlfmt v1.1.2 h1:Nea7b4icn8s57fTx1M5AI4qQT5HEM3rVUO8MuE6g80
github.com/go-xmlfmt/xmlfmt v1.1.2/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@ -306,6 +310,10 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
@ -315,6 +323,8 @@ github.com/jgautheron/goconst v1.7.0 h1:cEqH+YBKLsECnRSd4F4TK5ri8t/aXtt/qoL0Ft25
github.com/jgautheron/goconst v1.7.0/go.mod h1:aAosetZ5zaeC/2EfMeRswtxUFBpe2Hr7HzkgX4fanO4=
github.com/jingyugao/rowserrcheck v1.1.1 h1:zibz55j/MJtLsjP1OF4bSdgXxwL1b+Vn7Tjzq7gFzUs=
github.com/jingyugao/rowserrcheck v1.1.1/go.mod h1:4yvlZSDb3IyDTUZJUmpZfm2Hwok+Dtp+nu2qOq+er9c=
github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg=
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af h1:KA9BjwUk7KlCh6S9EAGWBt1oExIUv9WyNCiRz5amv48=
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af/go.mod h1:HEWGJkRDzjJY2sqdDwxccsGicWEf9BQOZsq2tV+xzM0=
github.com/jjti/go-spancheck v0.5.2 h1:WXTZG3efY/ji1Vi8mkH+23O3bLeKR6hp3tI3YB7XwKk=
@ -364,8 +374,8 @@ github.com/lufeee/execinquery v1.2.1 h1:hf0Ems4SHcUGBxpGN7Jz78z1ppVkP/837ZlETPCE
github.com/lufeee/execinquery v1.2.1/go.mod h1:EC7DrEKView09ocscGHC+apXMIaorh4xqSxS/dy8SbM=
github.com/macabu/inamedparam v0.1.3 h1:2tk/phHkMlEL/1GNe/Yf6kkR/hkcUdAEY3L0hjYV1Mk=
github.com/macabu/inamedparam v0.1.3/go.mod h1:93FLICAIk/quk7eaPPQvbzihUdn/QkGDwIZEoLtpH6I=
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s93SLMxb2vI=
github.com/maratori/testableexamples v1.0.0/go.mod h1:4rhjL1n20TUTT4vdh3RDqSizKLyXp7K2u6HgraZCGzE=
github.com/maratori/testpackage v1.1.1 h1:S58XVV5AD7HADMmD0fNnziNHqKvSdDuEKdPD1rNTU04=
@ -375,9 +385,11 @@ github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26/go.mod h1:1BELzlh859
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
@ -425,10 +437,8 @@ github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJ
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@ -472,6 +482,9 @@ github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567/go.mod h1:DWNGW8
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w=
github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryancurrah/gomodguard v1.3.0 h1:q15RT/pd6UggBXVBuLps8BXRvl5GPBcwVA7BJHMLuTw=
github.com/ryancurrah/gomodguard v1.3.0/go.mod h1:ggBxb3luypPEzqVtq33ee7YSN35V28XeGnid8dnni50=
@ -516,8 +529,8 @@ github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.13.0 h1:BWSJ/M+f+3nmdz9bxB+bWX28kkALN2ok11D0rSo8EJU=
github.com/spf13/viper v1.13.0/go.mod h1:Icm2xNL3/8uyh/wFuB1jI7TiTNKp8632Nwegu+zgdYw=
github.com/spf13/viper v1.15.0 h1:js3yy885G8xwJa6iOISGFwd+qlUo5AvyXb7CiihdtiU=
github.com/spf13/viper v1.15.0/go.mod h1:fFcTBJxvhhzSJiZy8n+PeW6t8l+KeT/uTARa0jHOQLA=
github.com/ssgreg/nlreturn/v2 v2.2.1 h1:X4XDI7jstt3ySqGU86YGAURbxw3oTDPK9sPEi6YEwQ0=
github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRkkxBiELzh2I=
github.com/stbenjam/no-sprintf-host-port v0.1.1 h1:tYugd/yrm1O0dV+ThCbaKZh195Dfm07ysF0U6JQXczc=
@ -535,10 +548,11 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c h1:+aPplBwWcHBo6q9xrfWdMrT9o4kltkmmvpemgIjep/8=
github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c/go.mod h1:SbErYREK7xXdsRiigaQiQkI9McGRzYMvlKYaP3Nimdk=
github.com/tdakkota/asciicheck v0.2.0 h1:o8jvnUANo0qXtnslk2d3nMKTFNlOnJjRrNcj0j9qkHM=
@ -563,6 +577,8 @@ github.com/ultraware/whitespace v0.1.0 h1:O1HKYoh0kIeqE8sFqZf1o0qbORXUCOQFrlaQyZ
github.com/ultraware/whitespace v0.1.0/go.mod h1:/se4r3beMFNmewJ4Xmz0nMQ941GJt+qmSHGP9emHYe0=
github.com/uudashr/gocognit v1.1.2 h1:l6BAEKJqQH2UpKAPKdMfZf5kE4W/2xk8pfU1OVLvniI=
github.com/uudashr/gocognit v1.1.2/go.mod h1:aAVdLURqcanke8h3vg35BC++eseDm66Z7KmchI5et4k=
github.com/vektra/mockery/v2 v2.40.3 h1:IZ2lydSDFsY0khnEsbSu13VLcqSsa6UYSS/8F+uOJmo=
github.com/vektra/mockery/v2 v2.40.3/go.mod h1:KYBZF/7sqOa86BaOZPYsoCZWEWLS90a5oBLg2pVudxY=
github.com/xen0n/gosmopolitan v1.2.2 h1:/p2KTnMzwRexIW8GlKawsTWOxn7UHA+jCMF/V8HHtvU=
github.com/xen0n/gosmopolitan v1.2.2/go.mod h1:7XX7Mj61uLYrj0qmeN0zi7XDon9JRAEhYQqAPLVNTeg=
github.com/yagipy/maintidx v1.0.0 h1:h5NvIsCz+nRDapQ0exNv4aJ0yXSI0420omVANTv3GJM=
@ -591,16 +607,15 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/automaxprocs v1.5.2 h1:2LxUOGiR3O6tw8ui5sZa2LAaHnsviZdVOUZw4fvbnME=
go.uber.org/automaxprocs v1.5.2/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@ -762,15 +777,17 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211105183446-c75c47738b0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220702020025-31831981b65f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@ -964,6 +981,7 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/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=
gotest.tools/gotestsum v1.6.4 h1:HFkapG0hK/HWiOxWS78SbR/JK5EpbH8hFzUuCvvfbfQ=

View File

@ -31,8 +31,8 @@ import (
_ "github.com/cespare/prettybench"
_ "gotest.tools/gotestsum"
// mockgen
_ "go.uber.org/mock/mockgen"
// mockery
_ "github.com/vektra/mockery/v2"
// tools like cpu
_ "go.uber.org/automaxprocs"

View File

@ -26,8 +26,8 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
kube::golang::setup_env
echo 'installing mockgen'
go -C "${KUBE_ROOT}/hack/tools" install go.uber.org/mock/mockgen
echo 'installing mockery'
go -C "${KUBE_ROOT}/hack/tools" install github.com/vektra/mockery/v2
function git_grep() {
git grep --untracked --exclude-standard \
@ -42,7 +42,7 @@ function git_grep() {
cd "${KUBE_ROOT}"
GENERATED_MOCK_FILE_REGEX="^// Code generated by MockGen. DO NOT EDIT.$"
GENERATED_MOCK_FILE_REGEX="^// Code generated by mockery v[0-9.]\+. DO NOT EDIT.$"
# pick a tempfile path for writing to
tmp=$(mktemp)
@ -52,7 +52,7 @@ git_grep -l -z "${GENERATED_MOCK_FILE_REGEX}" | xargs -0 rm -f
echo 'executing go generate command on below files'
git_grep -l -z "//go:generate mockgen" | while read -r -d $'\0' file; do
git_grep -l -z "//go:generate mockery" | while read -r -d $'\0' file; do
echo "- ${file}"
temp_file_name="$(kube::realpath "$(mktemp -t "$(basename "$0").XXXXXX")")"

View File

@ -0,0 +1,16 @@
---
dir: testing
filename: "{{.InterfaceName | snakecase}}.go"
boilerplate-file: ../../../../hack/boilerplate/boilerplate.generatego.txt
outpkg: testing
with-expecter: true
packages:
k8s.io/kubernetes/pkg/kubelet/apis/podresources:
interfaces:
CPUsProvider:
config:
filename: cpus_provider.go
DevicesProvider:
DynamicResourcesProvider:
MemoryProvider:
PodsProvider:

View File

@ -23,7 +23,6 @@ import (
"sort"
"testing"
"go.uber.org/mock/gomock"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@ -43,9 +42,6 @@ func TestListPodResourcesV1(t *testing.T) {
containerName := "container-name"
numaID := int64(1)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
devs := []*podresourcesapi.ContainerDevices{
{
ResourceName: "resource",
@ -215,21 +211,21 @@ func TestListPodResourcesV1(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(mockCtrl)
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(mockCtrl)
mockMemoryProvider := podresourcetest.NewMockMemoryProvider(mockCtrl)
mockDynamicResourcesProvider := podresourcetest.NewMockDynamicResourcesProvider(mockCtrl)
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(t)
mockPodsProvider := podresourcetest.NewMockPodsProvider(t)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(t)
mockMemoryProvider := podresourcetest.NewMockMemoryProvider(t)
mockDynamicResourcesProvider := podresourcetest.NewMockDynamicResourcesProvider(t)
mockPodsProvider.EXPECT().GetPods().Return(tc.pods).AnyTimes()
mockDevicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(tc.devices).AnyTimes()
mockCPUsProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(tc.cpus).AnyTimes()
mockMemoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(tc.memory).AnyTimes()
mockDynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &containers[0]).Return(tc.dynamicResources).AnyTimes()
mockDevicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
mockCPUsProvider.EXPECT().GetAllocatableCPUs().Return([]int64{}).AnyTimes()
mockDevicesProvider.EXPECT().GetAllocatableDevices().Return([]*podresourcesapi.ContainerDevices{}).AnyTimes()
mockMemoryProvider.EXPECT().GetAllocatableMemory().Return([]*podresourcesapi.ContainerMemory{}).AnyTimes()
mockPodsProvider.EXPECT().GetPods().Return(tc.pods).Maybe()
mockDevicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(tc.devices).Maybe()
mockCPUsProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(tc.cpus).Maybe()
mockMemoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(tc.memory).Maybe()
mockDynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &containers[0]).Return(tc.dynamicResources).Maybe()
mockDevicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
mockCPUsProvider.EXPECT().GetAllocatableCPUs().Return([]int64{}).Maybe()
mockDevicesProvider.EXPECT().GetAllocatableDevices().Return([]*podresourcesapi.ContainerDevices{}).Maybe()
mockMemoryProvider.EXPECT().GetAllocatableMemory().Return([]*podresourcesapi.ContainerMemory{}).Maybe()
providers := PodResourcesProviders{
Pods: mockPodsProvider,
@ -327,11 +323,11 @@ func TestListPodResourcesWithInitContainersV1(t *testing.T) {
cpusProvider *podresourcetest.MockCPUsProvider,
memoryProvider *podresourcetest.MockMemoryProvider,
dynamicResourcesProvider *podresourcetest.MockDynamicResourcesProvider) {
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).AnyTimes()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).AnyTimes()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).AnyTimes()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &pods[0].Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).AnyTimes()
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).Maybe()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).Maybe()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).Maybe()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &pods[0].Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).Maybe()
},
expectedResponse: &podresourcesapi.ListPodResourcesResponse{
@ -377,11 +373,11 @@ func TestListPodResourcesWithInitContainersV1(t *testing.T) {
cpusProvider *podresourcetest.MockCPUsProvider,
memoryProvider *podresourcetest.MockMemoryProvider,
dynamicResourcesProvider *podresourcetest.MockDynamicResourcesProvider) {
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).AnyTimes()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).AnyTimes()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).AnyTimes()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &pods[0].Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).AnyTimes()
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).Maybe()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).Maybe()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).Maybe()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &pods[0].Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).Maybe()
},
sidecarContainersEnabled: true,
@ -429,12 +425,12 @@ func TestListPodResourcesWithInitContainersV1(t *testing.T) {
cpusProvider *podresourcetest.MockCPUsProvider,
memoryProvider *podresourcetest.MockMemoryProvider,
dynamicResourcesProvider *podresourcetest.MockDynamicResourcesProvider) {
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).AnyTimes()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).AnyTimes()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).AnyTimes()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &pods[0].Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).AnyTimes()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).Maybe()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).Maybe()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).Maybe()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &pods[0].Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).Maybe()
},
expectedResponse: &podresourcesapi.ListPodResourcesResponse{
@ -481,17 +477,17 @@ func TestListPodResourcesWithInitContainersV1(t *testing.T) {
cpusProvider *podresourcetest.MockCPUsProvider,
memoryProvider *podresourcetest.MockMemoryProvider,
dynamicResourcesProvider *podresourcetest.MockDynamicResourcesProvider) {
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
devicesProvider.EXPECT().GetDevices(string(podUID), initContainerName).Return(devs).AnyTimes()
cpusProvider.EXPECT().GetCPUs(string(podUID), initContainerName).Return(cpus).AnyTimes()
memoryProvider.EXPECT().GetMemory(string(podUID), initContainerName).Return(memory).AnyTimes()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &pods[0].Spec.InitContainers[0]).Return([]*podresourcesapi.DynamicResource{}).AnyTimes()
devicesProvider.EXPECT().GetDevices(string(podUID), initContainerName).Return(devs).Maybe()
cpusProvider.EXPECT().GetCPUs(string(podUID), initContainerName).Return(cpus).Maybe()
memoryProvider.EXPECT().GetMemory(string(podUID), initContainerName).Return(memory).Maybe()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &pods[0].Spec.InitContainers[0]).Return([]*podresourcesapi.DynamicResource{}).Maybe()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).AnyTimes()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).AnyTimes()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).AnyTimes()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &pods[0].Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).AnyTimes()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).Maybe()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).Maybe()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).Maybe()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pods[0], &pods[0].Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).Maybe()
},
sidecarContainersEnabled: true,
@ -524,16 +520,13 @@ func TestListPodResourcesWithInitContainersV1(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.SidecarContainers, tc.sidecarContainersEnabled)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(t)
mockPodsProvider := podresourcetest.NewMockPodsProvider(t)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(t)
mockMemoryProvider := podresourcetest.NewMockMemoryProvider(t)
mockDynamicResourcesProvider := podresourcetest.NewMockDynamicResourcesProvider(t)
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(mockCtrl)
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(mockCtrl)
mockMemoryProvider := podresourcetest.NewMockMemoryProvider(mockCtrl)
mockDynamicResourcesProvider := podresourcetest.NewMockDynamicResourcesProvider(mockCtrl)
mockPodsProvider.EXPECT().GetPods().Return(tc.pods).AnyTimes()
mockPodsProvider.EXPECT().GetPods().Return(tc.pods).Maybe()
tc.mockFunc(tc.pods, mockDevicesProvider, mockCPUsProvider, mockMemoryProvider, mockDynamicResourcesProvider)
providers := PodResourcesProviders{
@ -556,9 +549,6 @@ func TestListPodResourcesWithInitContainersV1(t *testing.T) {
}
func TestAllocatableResources(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
allDevs := []*podresourcesapi.ContainerDevices{
{
ResourceName: "resource",
@ -815,18 +805,18 @@ func TestAllocatableResources(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(mockCtrl)
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(mockCtrl)
mockMemoryProvider := podresourcetest.NewMockMemoryProvider(mockCtrl)
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(t)
mockPodsProvider := podresourcetest.NewMockPodsProvider(t)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(t)
mockMemoryProvider := podresourcetest.NewMockMemoryProvider(t)
mockDevicesProvider.EXPECT().GetDevices("", "").Return([]*podresourcesapi.ContainerDevices{}).AnyTimes()
mockCPUsProvider.EXPECT().GetCPUs("", "").Return([]int64{}).AnyTimes()
mockMemoryProvider.EXPECT().GetMemory("", "").Return([]*podresourcesapi.ContainerMemory{}).AnyTimes()
mockDevicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
mockDevicesProvider.EXPECT().GetAllocatableDevices().Return(tc.allDevices).AnyTimes()
mockCPUsProvider.EXPECT().GetAllocatableCPUs().Return(tc.allCPUs).AnyTimes()
mockMemoryProvider.EXPECT().GetAllocatableMemory().Return(tc.allMemory).AnyTimes()
mockDevicesProvider.EXPECT().GetDevices("", "").Return([]*podresourcesapi.ContainerDevices{}).Maybe()
mockCPUsProvider.EXPECT().GetCPUs("", "").Return([]int64{}).Maybe()
mockMemoryProvider.EXPECT().GetMemory("", "").Return([]*podresourcesapi.ContainerMemory{}).Maybe()
mockDevicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
mockDevicesProvider.EXPECT().GetAllocatableDevices().Return(tc.allDevices).Maybe()
mockCPUsProvider.EXPECT().GetAllocatableCPUs().Return(tc.allCPUs).Maybe()
mockMemoryProvider.EXPECT().GetAllocatableMemory().Return(tc.allMemory).Maybe()
providers := PodResourcesProviders{
Pods: mockPodsProvider,
@ -858,9 +848,6 @@ func TestGetPodResourcesV1(t *testing.T) {
containerName := "container-name"
numaID := int64(1)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
devs := []*podresourcesapi.ContainerDevices{
{
ResourceName: "resource",
@ -984,21 +971,21 @@ func TestGetPodResourcesV1(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(mockCtrl)
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(mockCtrl)
mockMemoryProvider := podresourcetest.NewMockMemoryProvider(mockCtrl)
mockDynamicResourcesProvider := podresourcetest.NewMockDynamicResourcesProvider(mockCtrl)
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(t)
mockPodsProvider := podresourcetest.NewMockPodsProvider(t)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(t)
mockMemoryProvider := podresourcetest.NewMockMemoryProvider(t)
mockDynamicResourcesProvider := podresourcetest.NewMockDynamicResourcesProvider(t)
mockPodsProvider.EXPECT().GetPodByName(podNamespace, podName).Return(tc.pod, tc.exist).AnyTimes()
mockDevicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(tc.devices).AnyTimes()
mockCPUsProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(tc.cpus).AnyTimes()
mockMemoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(tc.memory).AnyTimes()
mockDynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &containers[0]).Return(tc.dynamicResources).AnyTimes()
mockDevicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
mockCPUsProvider.EXPECT().GetAllocatableCPUs().Return([]int64{}).AnyTimes()
mockDevicesProvider.EXPECT().GetAllocatableDevices().Return([]*podresourcesapi.ContainerDevices{}).AnyTimes()
mockMemoryProvider.EXPECT().GetAllocatableMemory().Return([]*podresourcesapi.ContainerMemory{}).AnyTimes()
mockPodsProvider.EXPECT().GetPodByName(podNamespace, podName).Return(tc.pod, tc.exist).Maybe()
mockDevicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(tc.devices).Maybe()
mockCPUsProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(tc.cpus).Maybe()
mockMemoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(tc.memory).Maybe()
mockDynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &containers[0]).Return(tc.dynamicResources).Maybe()
mockDevicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
mockCPUsProvider.EXPECT().GetAllocatableCPUs().Return([]int64{}).Maybe()
mockDevicesProvider.EXPECT().GetAllocatableDevices().Return([]*podresourcesapi.ContainerDevices{}).Maybe()
mockMemoryProvider.EXPECT().GetAllocatableMemory().Return([]*podresourcesapi.ContainerMemory{}).Maybe()
providers := PodResourcesProviders{
Pods: mockPodsProvider,
@ -1105,11 +1092,11 @@ func TestGetPodResourcesWithInitContainersV1(t *testing.T) {
cpusProvider *podresourcetest.MockCPUsProvider,
memoryProvider *podresourcetest.MockMemoryProvider,
dynamicResourcesProvider *podresourcetest.MockDynamicResourcesProvider) {
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).AnyTimes()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).AnyTimes()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).AnyTimes()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &pod.Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).AnyTimes()
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).Maybe()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).Maybe()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).Maybe()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &pod.Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).Maybe()
},
expectedResponse: &podresourcesapi.GetPodResourcesResponse{
@ -1151,11 +1138,11 @@ func TestGetPodResourcesWithInitContainersV1(t *testing.T) {
cpusProvider *podresourcetest.MockCPUsProvider,
memoryProvider *podresourcetest.MockMemoryProvider,
dynamicResourcesProvider *podresourcetest.MockDynamicResourcesProvider) {
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).AnyTimes()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).AnyTimes()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).AnyTimes()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &pod.Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).AnyTimes()
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).Maybe()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).Maybe()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).Maybe()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &pod.Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).Maybe()
},
sidecarContainersEnabled: true,
@ -1199,12 +1186,12 @@ func TestGetPodResourcesWithInitContainersV1(t *testing.T) {
cpusProvider *podresourcetest.MockCPUsProvider,
memoryProvider *podresourcetest.MockMemoryProvider,
dynamicResourcesProvider *podresourcetest.MockDynamicResourcesProvider) {
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).AnyTimes()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).AnyTimes()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).AnyTimes()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &pod.Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).AnyTimes()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).Maybe()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).Maybe()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).Maybe()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &pod.Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).Maybe()
},
expectedResponse: &podresourcesapi.GetPodResourcesResponse{
@ -1247,17 +1234,17 @@ func TestGetPodResourcesWithInitContainersV1(t *testing.T) {
cpusProvider *podresourcetest.MockCPUsProvider,
memoryProvider *podresourcetest.MockMemoryProvider,
dynamicResourcesProvider *podresourcetest.MockDynamicResourcesProvider) {
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
devicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
devicesProvider.EXPECT().GetDevices(string(podUID), initContainerName).Return(devs).AnyTimes()
cpusProvider.EXPECT().GetCPUs(string(podUID), initContainerName).Return(cpus).AnyTimes()
memoryProvider.EXPECT().GetMemory(string(podUID), initContainerName).Return(memory).AnyTimes()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &pod.Spec.InitContainers[0]).Return([]*podresourcesapi.DynamicResource{}).AnyTimes()
devicesProvider.EXPECT().GetDevices(string(podUID), initContainerName).Return(devs).Maybe()
cpusProvider.EXPECT().GetCPUs(string(podUID), initContainerName).Return(cpus).Maybe()
memoryProvider.EXPECT().GetMemory(string(podUID), initContainerName).Return(memory).Maybe()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &pod.Spec.InitContainers[0]).Return([]*podresourcesapi.DynamicResource{}).Maybe()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).AnyTimes()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).AnyTimes()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).AnyTimes()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &pod.Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).AnyTimes()
devicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(devs).Maybe()
cpusProvider.EXPECT().GetCPUs(string(podUID), containerName).Return(cpus).Maybe()
memoryProvider.EXPECT().GetMemory(string(podUID), containerName).Return(memory).Maybe()
dynamicResourcesProvider.EXPECT().GetDynamicResources(pod, &pod.Spec.Containers[0]).Return([]*podresourcesapi.DynamicResource{}).Maybe()
},
sidecarContainersEnabled: true,
@ -1288,16 +1275,13 @@ func TestGetPodResourcesWithInitContainersV1(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.SidecarContainers, tc.sidecarContainersEnabled)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(t)
mockPodsProvider := podresourcetest.NewMockPodsProvider(t)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(t)
mockMemoryProvider := podresourcetest.NewMockMemoryProvider(t)
mockDynamicResourcesProvider := podresourcetest.NewMockDynamicResourcesProvider(t)
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(mockCtrl)
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(mockCtrl)
mockMemoryProvider := podresourcetest.NewMockMemoryProvider(mockCtrl)
mockDynamicResourcesProvider := podresourcetest.NewMockDynamicResourcesProvider(mockCtrl)
mockPodsProvider.EXPECT().GetPodByName(podNamespace, podName).Return(tc.pod, true).AnyTimes()
mockPodsProvider.EXPECT().GetPodByName(podNamespace, podName).Return(tc.pod, true).Maybe()
tc.mockFunc(tc.pod, mockDevicesProvider, mockCPUsProvider, mockMemoryProvider, mockDynamicResourcesProvider)
providers := PodResourcesProviders{

View File

@ -20,7 +20,6 @@ import (
"context"
"testing"
"go.uber.org/mock/gomock"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@ -42,9 +41,6 @@ func TestListPodResourcesV1alpha1(t *testing.T) {
},
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
for _, tc := range []struct {
desc string
pods []*v1.Pod
@ -127,12 +123,12 @@ func TestListPodResourcesV1alpha1(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(mockCtrl)
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(t)
mockPodsProvider := podresourcetest.NewMockPodsProvider(t)
mockPodsProvider.EXPECT().GetPods().Return(tc.pods).AnyTimes()
mockDevicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(tc.devices).AnyTimes()
mockDevicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
mockPodsProvider.EXPECT().GetPods().Return(tc.pods).Maybe()
mockDevicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(tc.devices).Maybe()
mockDevicesProvider.EXPECT().UpdateAllocatedDevices().Return().Maybe()
providers := PodResourcesProviders{
Pods: mockPodsProvider,

View File

@ -0,0 +1,144 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package testing
import mock "github.com/stretchr/testify/mock"
// MockCPUsProvider is an autogenerated mock type for the CPUsProvider type
type MockCPUsProvider struct {
mock.Mock
}
type MockCPUsProvider_Expecter struct {
mock *mock.Mock
}
func (_m *MockCPUsProvider) EXPECT() *MockCPUsProvider_Expecter {
return &MockCPUsProvider_Expecter{mock: &_m.Mock}
}
// GetAllocatableCPUs provides a mock function with given fields:
func (_m *MockCPUsProvider) GetAllocatableCPUs() []int64 {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for GetAllocatableCPUs")
}
var r0 []int64
if rf, ok := ret.Get(0).(func() []int64); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]int64)
}
}
return r0
}
// MockCPUsProvider_GetAllocatableCPUs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllocatableCPUs'
type MockCPUsProvider_GetAllocatableCPUs_Call struct {
*mock.Call
}
// GetAllocatableCPUs is a helper method to define mock.On call
func (_e *MockCPUsProvider_Expecter) GetAllocatableCPUs() *MockCPUsProvider_GetAllocatableCPUs_Call {
return &MockCPUsProvider_GetAllocatableCPUs_Call{Call: _e.mock.On("GetAllocatableCPUs")}
}
func (_c *MockCPUsProvider_GetAllocatableCPUs_Call) Run(run func()) *MockCPUsProvider_GetAllocatableCPUs_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockCPUsProvider_GetAllocatableCPUs_Call) Return(_a0 []int64) *MockCPUsProvider_GetAllocatableCPUs_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockCPUsProvider_GetAllocatableCPUs_Call) RunAndReturn(run func() []int64) *MockCPUsProvider_GetAllocatableCPUs_Call {
_c.Call.Return(run)
return _c
}
// GetCPUs provides a mock function with given fields: podUID, containerName
func (_m *MockCPUsProvider) GetCPUs(podUID string, containerName string) []int64 {
ret := _m.Called(podUID, containerName)
if len(ret) == 0 {
panic("no return value specified for GetCPUs")
}
var r0 []int64
if rf, ok := ret.Get(0).(func(string, string) []int64); ok {
r0 = rf(podUID, containerName)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]int64)
}
}
return r0
}
// MockCPUsProvider_GetCPUs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCPUs'
type MockCPUsProvider_GetCPUs_Call struct {
*mock.Call
}
// GetCPUs is a helper method to define mock.On call
// - podUID string
// - containerName string
func (_e *MockCPUsProvider_Expecter) GetCPUs(podUID interface{}, containerName interface{}) *MockCPUsProvider_GetCPUs_Call {
return &MockCPUsProvider_GetCPUs_Call{Call: _e.mock.On("GetCPUs", podUID, containerName)}
}
func (_c *MockCPUsProvider_GetCPUs_Call) Run(run func(podUID string, containerName string)) *MockCPUsProvider_GetCPUs_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(string), args[1].(string))
})
return _c
}
func (_c *MockCPUsProvider_GetCPUs_Call) Return(_a0 []int64) *MockCPUsProvider_GetCPUs_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockCPUsProvider_GetCPUs_Call) RunAndReturn(run func(string, string) []int64) *MockCPUsProvider_GetCPUs_Call {
_c.Call.Return(run)
return _c
}
// NewMockCPUsProvider creates a new instance of MockCPUsProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockCPUsProvider(t interface {
mock.TestingT
Cleanup(func())
}) *MockCPUsProvider {
mock := &MockCPUsProvider{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -0,0 +1,180 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package testing
import (
mock "github.com/stretchr/testify/mock"
v1 "k8s.io/kubelet/pkg/apis/podresources/v1"
)
// MockDevicesProvider is an autogenerated mock type for the DevicesProvider type
type MockDevicesProvider struct {
mock.Mock
}
type MockDevicesProvider_Expecter struct {
mock *mock.Mock
}
func (_m *MockDevicesProvider) EXPECT() *MockDevicesProvider_Expecter {
return &MockDevicesProvider_Expecter{mock: &_m.Mock}
}
// GetAllocatableDevices provides a mock function with given fields:
func (_m *MockDevicesProvider) GetAllocatableDevices() []*v1.ContainerDevices {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for GetAllocatableDevices")
}
var r0 []*v1.ContainerDevices
if rf, ok := ret.Get(0).(func() []*v1.ContainerDevices); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*v1.ContainerDevices)
}
}
return r0
}
// MockDevicesProvider_GetAllocatableDevices_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllocatableDevices'
type MockDevicesProvider_GetAllocatableDevices_Call struct {
*mock.Call
}
// GetAllocatableDevices is a helper method to define mock.On call
func (_e *MockDevicesProvider_Expecter) GetAllocatableDevices() *MockDevicesProvider_GetAllocatableDevices_Call {
return &MockDevicesProvider_GetAllocatableDevices_Call{Call: _e.mock.On("GetAllocatableDevices")}
}
func (_c *MockDevicesProvider_GetAllocatableDevices_Call) Run(run func()) *MockDevicesProvider_GetAllocatableDevices_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockDevicesProvider_GetAllocatableDevices_Call) Return(_a0 []*v1.ContainerDevices) *MockDevicesProvider_GetAllocatableDevices_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockDevicesProvider_GetAllocatableDevices_Call) RunAndReturn(run func() []*v1.ContainerDevices) *MockDevicesProvider_GetAllocatableDevices_Call {
_c.Call.Return(run)
return _c
}
// GetDevices provides a mock function with given fields: podUID, containerName
func (_m *MockDevicesProvider) GetDevices(podUID string, containerName string) []*v1.ContainerDevices {
ret := _m.Called(podUID, containerName)
if len(ret) == 0 {
panic("no return value specified for GetDevices")
}
var r0 []*v1.ContainerDevices
if rf, ok := ret.Get(0).(func(string, string) []*v1.ContainerDevices); ok {
r0 = rf(podUID, containerName)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*v1.ContainerDevices)
}
}
return r0
}
// MockDevicesProvider_GetDevices_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDevices'
type MockDevicesProvider_GetDevices_Call struct {
*mock.Call
}
// GetDevices is a helper method to define mock.On call
// - podUID string
// - containerName string
func (_e *MockDevicesProvider_Expecter) GetDevices(podUID interface{}, containerName interface{}) *MockDevicesProvider_GetDevices_Call {
return &MockDevicesProvider_GetDevices_Call{Call: _e.mock.On("GetDevices", podUID, containerName)}
}
func (_c *MockDevicesProvider_GetDevices_Call) Run(run func(podUID string, containerName string)) *MockDevicesProvider_GetDevices_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(string), args[1].(string))
})
return _c
}
func (_c *MockDevicesProvider_GetDevices_Call) Return(_a0 []*v1.ContainerDevices) *MockDevicesProvider_GetDevices_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockDevicesProvider_GetDevices_Call) RunAndReturn(run func(string, string) []*v1.ContainerDevices) *MockDevicesProvider_GetDevices_Call {
_c.Call.Return(run)
return _c
}
// UpdateAllocatedDevices provides a mock function with given fields:
func (_m *MockDevicesProvider) UpdateAllocatedDevices() {
_m.Called()
}
// MockDevicesProvider_UpdateAllocatedDevices_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateAllocatedDevices'
type MockDevicesProvider_UpdateAllocatedDevices_Call struct {
*mock.Call
}
// UpdateAllocatedDevices is a helper method to define mock.On call
func (_e *MockDevicesProvider_Expecter) UpdateAllocatedDevices() *MockDevicesProvider_UpdateAllocatedDevices_Call {
return &MockDevicesProvider_UpdateAllocatedDevices_Call{Call: _e.mock.On("UpdateAllocatedDevices")}
}
func (_c *MockDevicesProvider_UpdateAllocatedDevices_Call) Run(run func()) *MockDevicesProvider_UpdateAllocatedDevices_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockDevicesProvider_UpdateAllocatedDevices_Call) Return() *MockDevicesProvider_UpdateAllocatedDevices_Call {
_c.Call.Return()
return _c
}
func (_c *MockDevicesProvider_UpdateAllocatedDevices_Call) RunAndReturn(run func()) *MockDevicesProvider_UpdateAllocatedDevices_Call {
_c.Call.Return(run)
return _c
}
// NewMockDevicesProvider creates a new instance of MockDevicesProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockDevicesProvider(t interface {
mock.TestingT
Cleanup(func())
}) *MockDevicesProvider {
mock := &MockDevicesProvider{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -0,0 +1,103 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package testing
import (
mock "github.com/stretchr/testify/mock"
podresourcesv1 "k8s.io/kubelet/pkg/apis/podresources/v1"
v1 "k8s.io/api/core/v1"
)
// MockDynamicResourcesProvider is an autogenerated mock type for the DynamicResourcesProvider type
type MockDynamicResourcesProvider struct {
mock.Mock
}
type MockDynamicResourcesProvider_Expecter struct {
mock *mock.Mock
}
func (_m *MockDynamicResourcesProvider) EXPECT() *MockDynamicResourcesProvider_Expecter {
return &MockDynamicResourcesProvider_Expecter{mock: &_m.Mock}
}
// GetDynamicResources provides a mock function with given fields: pod, container
func (_m *MockDynamicResourcesProvider) GetDynamicResources(pod *v1.Pod, container *v1.Container) []*podresourcesv1.DynamicResource {
ret := _m.Called(pod, container)
if len(ret) == 0 {
panic("no return value specified for GetDynamicResources")
}
var r0 []*podresourcesv1.DynamicResource
if rf, ok := ret.Get(0).(func(*v1.Pod, *v1.Container) []*podresourcesv1.DynamicResource); ok {
r0 = rf(pod, container)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*podresourcesv1.DynamicResource)
}
}
return r0
}
// MockDynamicResourcesProvider_GetDynamicResources_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDynamicResources'
type MockDynamicResourcesProvider_GetDynamicResources_Call struct {
*mock.Call
}
// GetDynamicResources is a helper method to define mock.On call
// - pod *v1.Pod
// - container *v1.Container
func (_e *MockDynamicResourcesProvider_Expecter) GetDynamicResources(pod interface{}, container interface{}) *MockDynamicResourcesProvider_GetDynamicResources_Call {
return &MockDynamicResourcesProvider_GetDynamicResources_Call{Call: _e.mock.On("GetDynamicResources", pod, container)}
}
func (_c *MockDynamicResourcesProvider_GetDynamicResources_Call) Run(run func(pod *v1.Pod, container *v1.Container)) *MockDynamicResourcesProvider_GetDynamicResources_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(*v1.Pod), args[1].(*v1.Container))
})
return _c
}
func (_c *MockDynamicResourcesProvider_GetDynamicResources_Call) Return(_a0 []*podresourcesv1.DynamicResource) *MockDynamicResourcesProvider_GetDynamicResources_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockDynamicResourcesProvider_GetDynamicResources_Call) RunAndReturn(run func(*v1.Pod, *v1.Container) []*podresourcesv1.DynamicResource) *MockDynamicResourcesProvider_GetDynamicResources_Call {
_c.Call.Return(run)
return _c
}
// NewMockDynamicResourcesProvider creates a new instance of MockDynamicResourcesProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockDynamicResourcesProvider(t interface {
mock.TestingT
Cleanup(func())
}) *MockDynamicResourcesProvider {
mock := &MockDynamicResourcesProvider{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -0,0 +1,148 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package testing
import (
mock "github.com/stretchr/testify/mock"
v1 "k8s.io/kubelet/pkg/apis/podresources/v1"
)
// MockMemoryProvider is an autogenerated mock type for the MemoryProvider type
type MockMemoryProvider struct {
mock.Mock
}
type MockMemoryProvider_Expecter struct {
mock *mock.Mock
}
func (_m *MockMemoryProvider) EXPECT() *MockMemoryProvider_Expecter {
return &MockMemoryProvider_Expecter{mock: &_m.Mock}
}
// GetAllocatableMemory provides a mock function with given fields:
func (_m *MockMemoryProvider) GetAllocatableMemory() []*v1.ContainerMemory {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for GetAllocatableMemory")
}
var r0 []*v1.ContainerMemory
if rf, ok := ret.Get(0).(func() []*v1.ContainerMemory); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*v1.ContainerMemory)
}
}
return r0
}
// MockMemoryProvider_GetAllocatableMemory_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllocatableMemory'
type MockMemoryProvider_GetAllocatableMemory_Call struct {
*mock.Call
}
// GetAllocatableMemory is a helper method to define mock.On call
func (_e *MockMemoryProvider_Expecter) GetAllocatableMemory() *MockMemoryProvider_GetAllocatableMemory_Call {
return &MockMemoryProvider_GetAllocatableMemory_Call{Call: _e.mock.On("GetAllocatableMemory")}
}
func (_c *MockMemoryProvider_GetAllocatableMemory_Call) Run(run func()) *MockMemoryProvider_GetAllocatableMemory_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockMemoryProvider_GetAllocatableMemory_Call) Return(_a0 []*v1.ContainerMemory) *MockMemoryProvider_GetAllocatableMemory_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockMemoryProvider_GetAllocatableMemory_Call) RunAndReturn(run func() []*v1.ContainerMemory) *MockMemoryProvider_GetAllocatableMemory_Call {
_c.Call.Return(run)
return _c
}
// GetMemory provides a mock function with given fields: podUID, containerName
func (_m *MockMemoryProvider) GetMemory(podUID string, containerName string) []*v1.ContainerMemory {
ret := _m.Called(podUID, containerName)
if len(ret) == 0 {
panic("no return value specified for GetMemory")
}
var r0 []*v1.ContainerMemory
if rf, ok := ret.Get(0).(func(string, string) []*v1.ContainerMemory); ok {
r0 = rf(podUID, containerName)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*v1.ContainerMemory)
}
}
return r0
}
// MockMemoryProvider_GetMemory_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMemory'
type MockMemoryProvider_GetMemory_Call struct {
*mock.Call
}
// GetMemory is a helper method to define mock.On call
// - podUID string
// - containerName string
func (_e *MockMemoryProvider_Expecter) GetMemory(podUID interface{}, containerName interface{}) *MockMemoryProvider_GetMemory_Call {
return &MockMemoryProvider_GetMemory_Call{Call: _e.mock.On("GetMemory", podUID, containerName)}
}
func (_c *MockMemoryProvider_GetMemory_Call) Run(run func(podUID string, containerName string)) *MockMemoryProvider_GetMemory_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(string), args[1].(string))
})
return _c
}
func (_c *MockMemoryProvider_GetMemory_Call) Return(_a0 []*v1.ContainerMemory) *MockMemoryProvider_GetMemory_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockMemoryProvider_GetMemory_Call) RunAndReturn(run func(string, string) []*v1.ContainerMemory) *MockMemoryProvider_GetMemory_Call {
_c.Call.Return(run)
return _c
}
// NewMockMemoryProvider creates a new instance of MockMemoryProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockMemoryProvider(t interface {
mock.TestingT
Cleanup(func())
}) *MockMemoryProvider {
mock := &MockMemoryProvider{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -0,0 +1,158 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package testing
import (
mock "github.com/stretchr/testify/mock"
v1 "k8s.io/api/core/v1"
)
// MockPodsProvider is an autogenerated mock type for the PodsProvider type
type MockPodsProvider struct {
mock.Mock
}
type MockPodsProvider_Expecter struct {
mock *mock.Mock
}
func (_m *MockPodsProvider) EXPECT() *MockPodsProvider_Expecter {
return &MockPodsProvider_Expecter{mock: &_m.Mock}
}
// GetPodByName provides a mock function with given fields: namespace, name
func (_m *MockPodsProvider) GetPodByName(namespace string, name string) (*v1.Pod, bool) {
ret := _m.Called(namespace, name)
if len(ret) == 0 {
panic("no return value specified for GetPodByName")
}
var r0 *v1.Pod
var r1 bool
if rf, ok := ret.Get(0).(func(string, string) (*v1.Pod, bool)); ok {
return rf(namespace, name)
}
if rf, ok := ret.Get(0).(func(string, string) *v1.Pod); ok {
r0 = rf(namespace, name)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Pod)
}
}
if rf, ok := ret.Get(1).(func(string, string) bool); ok {
r1 = rf(namespace, name)
} else {
r1 = ret.Get(1).(bool)
}
return r0, r1
}
// MockPodsProvider_GetPodByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodByName'
type MockPodsProvider_GetPodByName_Call struct {
*mock.Call
}
// GetPodByName is a helper method to define mock.On call
// - namespace string
// - name string
func (_e *MockPodsProvider_Expecter) GetPodByName(namespace interface{}, name interface{}) *MockPodsProvider_GetPodByName_Call {
return &MockPodsProvider_GetPodByName_Call{Call: _e.mock.On("GetPodByName", namespace, name)}
}
func (_c *MockPodsProvider_GetPodByName_Call) Run(run func(namespace string, name string)) *MockPodsProvider_GetPodByName_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(string), args[1].(string))
})
return _c
}
func (_c *MockPodsProvider_GetPodByName_Call) Return(_a0 *v1.Pod, _a1 bool) *MockPodsProvider_GetPodByName_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockPodsProvider_GetPodByName_Call) RunAndReturn(run func(string, string) (*v1.Pod, bool)) *MockPodsProvider_GetPodByName_Call {
_c.Call.Return(run)
return _c
}
// GetPods provides a mock function with given fields:
func (_m *MockPodsProvider) GetPods() []*v1.Pod {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for GetPods")
}
var r0 []*v1.Pod
if rf, ok := ret.Get(0).(func() []*v1.Pod); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*v1.Pod)
}
}
return r0
}
// MockPodsProvider_GetPods_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPods'
type MockPodsProvider_GetPods_Call struct {
*mock.Call
}
// GetPods is a helper method to define mock.On call
func (_e *MockPodsProvider_Expecter) GetPods() *MockPodsProvider_GetPods_Call {
return &MockPodsProvider_GetPods_Call{Call: _e.mock.On("GetPods")}
}
func (_c *MockPodsProvider_GetPods_Call) Run(run func()) *MockPodsProvider_GetPods_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockPodsProvider_GetPods_Call) Return(_a0 []*v1.Pod) *MockPodsProvider_GetPods_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockPodsProvider_GetPods_Call) RunAndReturn(run func() []*v1.Pod) *MockPodsProvider_GetPods_Call {
_c.Call.Return(run)
return _c
}
// NewMockPodsProvider creates a new instance of MockPodsProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockPodsProvider(t interface {
mock.TestingT
Cleanup(func())
}) *MockPodsProvider {
mock := &MockPodsProvider{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -1,288 +0,0 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: types.go
//
// Generated by this command:
//
// mockgen -source=types.go -destination=testing/provider_mock.go -package=testing DevicesProvider,PodsProvider,CPUsProvider,MemoryProvider
//
// Package testing is a generated GoMock package.
package testing
import (
reflect "reflect"
gomock "go.uber.org/mock/gomock"
v1 "k8s.io/api/core/v1"
v10 "k8s.io/kubelet/pkg/apis/podresources/v1"
)
// MockDevicesProvider is a mock of DevicesProvider interface.
type MockDevicesProvider struct {
ctrl *gomock.Controller
recorder *MockDevicesProviderMockRecorder
}
// MockDevicesProviderMockRecorder is the mock recorder for MockDevicesProvider.
type MockDevicesProviderMockRecorder struct {
mock *MockDevicesProvider
}
// NewMockDevicesProvider creates a new mock instance.
func NewMockDevicesProvider(ctrl *gomock.Controller) *MockDevicesProvider {
mock := &MockDevicesProvider{ctrl: ctrl}
mock.recorder = &MockDevicesProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockDevicesProvider) EXPECT() *MockDevicesProviderMockRecorder {
return m.recorder
}
// GetAllocatableDevices mocks base method.
func (m *MockDevicesProvider) GetAllocatableDevices() []*v10.ContainerDevices {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllocatableDevices")
ret0, _ := ret[0].([]*v10.ContainerDevices)
return ret0
}
// GetAllocatableDevices indicates an expected call of GetAllocatableDevices.
func (mr *MockDevicesProviderMockRecorder) GetAllocatableDevices() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllocatableDevices", reflect.TypeOf((*MockDevicesProvider)(nil).GetAllocatableDevices))
}
// GetDevices mocks base method.
func (m *MockDevicesProvider) GetDevices(podUID, containerName string) []*v10.ContainerDevices {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetDevices", podUID, containerName)
ret0, _ := ret[0].([]*v10.ContainerDevices)
return ret0
}
// GetDevices indicates an expected call of GetDevices.
func (mr *MockDevicesProviderMockRecorder) GetDevices(podUID, containerName any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDevices", reflect.TypeOf((*MockDevicesProvider)(nil).GetDevices), podUID, containerName)
}
// UpdateAllocatedDevices mocks base method.
func (m *MockDevicesProvider) UpdateAllocatedDevices() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "UpdateAllocatedDevices")
}
// UpdateAllocatedDevices indicates an expected call of UpdateAllocatedDevices.
func (mr *MockDevicesProviderMockRecorder) UpdateAllocatedDevices() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateAllocatedDevices", reflect.TypeOf((*MockDevicesProvider)(nil).UpdateAllocatedDevices))
}
// MockPodsProvider is a mock of PodsProvider interface.
type MockPodsProvider struct {
ctrl *gomock.Controller
recorder *MockPodsProviderMockRecorder
}
// MockPodsProviderMockRecorder is the mock recorder for MockPodsProvider.
type MockPodsProviderMockRecorder struct {
mock *MockPodsProvider
}
// NewMockPodsProvider creates a new mock instance.
func NewMockPodsProvider(ctrl *gomock.Controller) *MockPodsProvider {
mock := &MockPodsProvider{ctrl: ctrl}
mock.recorder = &MockPodsProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockPodsProvider) EXPECT() *MockPodsProviderMockRecorder {
return m.recorder
}
// GetPodByName mocks base method.
func (m *MockPodsProvider) GetPodByName(namespace, name string) (*v1.Pod, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPodByName", namespace, name)
ret0, _ := ret[0].(*v1.Pod)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetPodByName indicates an expected call of GetPodByName.
func (mr *MockPodsProviderMockRecorder) GetPodByName(namespace, name any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodByName", reflect.TypeOf((*MockPodsProvider)(nil).GetPodByName), namespace, name)
}
// GetPods mocks base method.
func (m *MockPodsProvider) GetPods() []*v1.Pod {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPods")
ret0, _ := ret[0].([]*v1.Pod)
return ret0
}
// GetPods indicates an expected call of GetPods.
func (mr *MockPodsProviderMockRecorder) GetPods() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPods", reflect.TypeOf((*MockPodsProvider)(nil).GetPods))
}
// MockCPUsProvider is a mock of CPUsProvider interface.
type MockCPUsProvider struct {
ctrl *gomock.Controller
recorder *MockCPUsProviderMockRecorder
}
// MockCPUsProviderMockRecorder is the mock recorder for MockCPUsProvider.
type MockCPUsProviderMockRecorder struct {
mock *MockCPUsProvider
}
// NewMockCPUsProvider creates a new mock instance.
func NewMockCPUsProvider(ctrl *gomock.Controller) *MockCPUsProvider {
mock := &MockCPUsProvider{ctrl: ctrl}
mock.recorder = &MockCPUsProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockCPUsProvider) EXPECT() *MockCPUsProviderMockRecorder {
return m.recorder
}
// GetAllocatableCPUs mocks base method.
func (m *MockCPUsProvider) GetAllocatableCPUs() []int64 {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllocatableCPUs")
ret0, _ := ret[0].([]int64)
return ret0
}
// GetAllocatableCPUs indicates an expected call of GetAllocatableCPUs.
func (mr *MockCPUsProviderMockRecorder) GetAllocatableCPUs() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllocatableCPUs", reflect.TypeOf((*MockCPUsProvider)(nil).GetAllocatableCPUs))
}
// GetCPUs mocks base method.
func (m *MockCPUsProvider) GetCPUs(podUID, containerName string) []int64 {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetCPUs", podUID, containerName)
ret0, _ := ret[0].([]int64)
return ret0
}
// GetCPUs indicates an expected call of GetCPUs.
func (mr *MockCPUsProviderMockRecorder) GetCPUs(podUID, containerName any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCPUs", reflect.TypeOf((*MockCPUsProvider)(nil).GetCPUs), podUID, containerName)
}
// MockMemoryProvider is a mock of MemoryProvider interface.
type MockMemoryProvider struct {
ctrl *gomock.Controller
recorder *MockMemoryProviderMockRecorder
}
// MockMemoryProviderMockRecorder is the mock recorder for MockMemoryProvider.
type MockMemoryProviderMockRecorder struct {
mock *MockMemoryProvider
}
// NewMockMemoryProvider creates a new mock instance.
func NewMockMemoryProvider(ctrl *gomock.Controller) *MockMemoryProvider {
mock := &MockMemoryProvider{ctrl: ctrl}
mock.recorder = &MockMemoryProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockMemoryProvider) EXPECT() *MockMemoryProviderMockRecorder {
return m.recorder
}
// GetAllocatableMemory mocks base method.
func (m *MockMemoryProvider) GetAllocatableMemory() []*v10.ContainerMemory {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllocatableMemory")
ret0, _ := ret[0].([]*v10.ContainerMemory)
return ret0
}
// GetAllocatableMemory indicates an expected call of GetAllocatableMemory.
func (mr *MockMemoryProviderMockRecorder) GetAllocatableMemory() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllocatableMemory", reflect.TypeOf((*MockMemoryProvider)(nil).GetAllocatableMemory))
}
// GetMemory mocks base method.
func (m *MockMemoryProvider) GetMemory(podUID, containerName string) []*v10.ContainerMemory {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetMemory", podUID, containerName)
ret0, _ := ret[0].([]*v10.ContainerMemory)
return ret0
}
// GetMemory indicates an expected call of GetMemory.
func (mr *MockMemoryProviderMockRecorder) GetMemory(podUID, containerName any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMemory", reflect.TypeOf((*MockMemoryProvider)(nil).GetMemory), podUID, containerName)
}
// MockDynamicResourcesProvider is a mock of DynamicResourcesProvider interface.
type MockDynamicResourcesProvider struct {
ctrl *gomock.Controller
recorder *MockDynamicResourcesProviderMockRecorder
}
// MockDynamicResourcesProviderMockRecorder is the mock recorder for MockDynamicResourcesProvider.
type MockDynamicResourcesProviderMockRecorder struct {
mock *MockDynamicResourcesProvider
}
// NewMockDynamicResourcesProvider creates a new mock instance.
func NewMockDynamicResourcesProvider(ctrl *gomock.Controller) *MockDynamicResourcesProvider {
mock := &MockDynamicResourcesProvider{ctrl: ctrl}
mock.recorder = &MockDynamicResourcesProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockDynamicResourcesProvider) EXPECT() *MockDynamicResourcesProviderMockRecorder {
return m.recorder
}
// GetDynamicResources mocks base method.
func (m *MockDynamicResourcesProvider) GetDynamicResources(pod *v1.Pod, container *v1.Container) []*v10.DynamicResource {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetDynamicResources", pod, container)
ret0, _ := ret[0].([]*v10.DynamicResource)
return ret0
}
// GetDynamicResources indicates an expected call of GetDynamicResources.
func (mr *MockDynamicResourcesProviderMockRecorder) GetDynamicResources(pod, container any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDynamicResources", reflect.TypeOf((*MockDynamicResourcesProvider)(nil).GetDynamicResources), pod, container)
}

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate mockgen -source=types.go -destination=testing/provider_mock.go -package=testing DevicesProvider,PodsProvider,CPUsProvider,MemoryProvider
//go:generate mockery
package podresources
import (

View File

@ -0,0 +1,10 @@
---
dir: testing
filename: cadvisor_mock.go
boilerplate-file: ../../../hack/boilerplate/boilerplate.generatego.txt
outpkg: testing
with-expecter: true
packages:
k8s.io/kubernetes/pkg/kubelet/cadvisor:
interfaces:
Interface:

View File

@ -14,231 +14,538 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: types.go
//
// Generated by this command:
//
// mockgen -source=types.go -destination=testing/cadvisor_mock.go -package=testing Interface
//
// Code generated by mockery v2.40.3. DO NOT EDIT.
// Package testing is a generated GoMock package.
package testing
import (
reflect "reflect"
v1 "github.com/google/cadvisor/info/v1"
mock "github.com/stretchr/testify/mock"
v2 "github.com/google/cadvisor/info/v2"
gomock "go.uber.org/mock/gomock"
)
// MockInterface is a mock of Interface interface.
// MockInterface is an autogenerated mock type for the Interface type
type MockInterface struct {
ctrl *gomock.Controller
recorder *MockInterfaceMockRecorder
mock.Mock
}
// MockInterfaceMockRecorder is the mock recorder for MockInterface.
type MockInterfaceMockRecorder struct {
mock *MockInterface
type MockInterface_Expecter struct {
mock *mock.Mock
}
// NewMockInterface creates a new mock instance.
func NewMockInterface(ctrl *gomock.Controller) *MockInterface {
mock := &MockInterface{ctrl: ctrl}
mock.recorder = &MockInterfaceMockRecorder{mock}
func (_m *MockInterface) EXPECT() *MockInterface_Expecter {
return &MockInterface_Expecter{mock: &_m.Mock}
}
// ContainerFsInfo provides a mock function with given fields:
func (_m *MockInterface) ContainerFsInfo() (v2.FsInfo, error) {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for ContainerFsInfo")
}
var r0 v2.FsInfo
var r1 error
if rf, ok := ret.Get(0).(func() (v2.FsInfo, error)); ok {
return rf()
}
if rf, ok := ret.Get(0).(func() v2.FsInfo); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(v2.FsInfo)
}
if rf, ok := ret.Get(1).(func() error); ok {
r1 = rf()
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockInterface_ContainerFsInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ContainerFsInfo'
type MockInterface_ContainerFsInfo_Call struct {
*mock.Call
}
// ContainerFsInfo is a helper method to define mock.On call
func (_e *MockInterface_Expecter) ContainerFsInfo() *MockInterface_ContainerFsInfo_Call {
return &MockInterface_ContainerFsInfo_Call{Call: _e.mock.On("ContainerFsInfo")}
}
func (_c *MockInterface_ContainerFsInfo_Call) Run(run func()) *MockInterface_ContainerFsInfo_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockInterface_ContainerFsInfo_Call) Return(_a0 v2.FsInfo, _a1 error) *MockInterface_ContainerFsInfo_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockInterface_ContainerFsInfo_Call) RunAndReturn(run func() (v2.FsInfo, error)) *MockInterface_ContainerFsInfo_Call {
_c.Call.Return(run)
return _c
}
// ContainerInfoV2 provides a mock function with given fields: name, options
func (_m *MockInterface) ContainerInfoV2(name string, options v2.RequestOptions) (map[string]v2.ContainerInfo, error) {
ret := _m.Called(name, options)
if len(ret) == 0 {
panic("no return value specified for ContainerInfoV2")
}
var r0 map[string]v2.ContainerInfo
var r1 error
if rf, ok := ret.Get(0).(func(string, v2.RequestOptions) (map[string]v2.ContainerInfo, error)); ok {
return rf(name, options)
}
if rf, ok := ret.Get(0).(func(string, v2.RequestOptions) map[string]v2.ContainerInfo); ok {
r0 = rf(name, options)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(map[string]v2.ContainerInfo)
}
}
if rf, ok := ret.Get(1).(func(string, v2.RequestOptions) error); ok {
r1 = rf(name, options)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockInterface_ContainerInfoV2_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ContainerInfoV2'
type MockInterface_ContainerInfoV2_Call struct {
*mock.Call
}
// ContainerInfoV2 is a helper method to define mock.On call
// - name string
// - options v2.RequestOptions
func (_e *MockInterface_Expecter) ContainerInfoV2(name interface{}, options interface{}) *MockInterface_ContainerInfoV2_Call {
return &MockInterface_ContainerInfoV2_Call{Call: _e.mock.On("ContainerInfoV2", name, options)}
}
func (_c *MockInterface_ContainerInfoV2_Call) Run(run func(name string, options v2.RequestOptions)) *MockInterface_ContainerInfoV2_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(string), args[1].(v2.RequestOptions))
})
return _c
}
func (_c *MockInterface_ContainerInfoV2_Call) Return(_a0 map[string]v2.ContainerInfo, _a1 error) *MockInterface_ContainerInfoV2_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockInterface_ContainerInfoV2_Call) RunAndReturn(run func(string, v2.RequestOptions) (map[string]v2.ContainerInfo, error)) *MockInterface_ContainerInfoV2_Call {
_c.Call.Return(run)
return _c
}
// GetDirFsInfo provides a mock function with given fields: path
func (_m *MockInterface) GetDirFsInfo(path string) (v2.FsInfo, error) {
ret := _m.Called(path)
if len(ret) == 0 {
panic("no return value specified for GetDirFsInfo")
}
var r0 v2.FsInfo
var r1 error
if rf, ok := ret.Get(0).(func(string) (v2.FsInfo, error)); ok {
return rf(path)
}
if rf, ok := ret.Get(0).(func(string) v2.FsInfo); ok {
r0 = rf(path)
} else {
r0 = ret.Get(0).(v2.FsInfo)
}
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(path)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockInterface_GetDirFsInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDirFsInfo'
type MockInterface_GetDirFsInfo_Call struct {
*mock.Call
}
// GetDirFsInfo is a helper method to define mock.On call
// - path string
func (_e *MockInterface_Expecter) GetDirFsInfo(path interface{}) *MockInterface_GetDirFsInfo_Call {
return &MockInterface_GetDirFsInfo_Call{Call: _e.mock.On("GetDirFsInfo", path)}
}
func (_c *MockInterface_GetDirFsInfo_Call) Run(run func(path string)) *MockInterface_GetDirFsInfo_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(string))
})
return _c
}
func (_c *MockInterface_GetDirFsInfo_Call) Return(_a0 v2.FsInfo, _a1 error) *MockInterface_GetDirFsInfo_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockInterface_GetDirFsInfo_Call) RunAndReturn(run func(string) (v2.FsInfo, error)) *MockInterface_GetDirFsInfo_Call {
_c.Call.Return(run)
return _c
}
// GetRequestedContainersInfo provides a mock function with given fields: containerName, options
func (_m *MockInterface) GetRequestedContainersInfo(containerName string, options v2.RequestOptions) (map[string]*v1.ContainerInfo, error) {
ret := _m.Called(containerName, options)
if len(ret) == 0 {
panic("no return value specified for GetRequestedContainersInfo")
}
var r0 map[string]*v1.ContainerInfo
var r1 error
if rf, ok := ret.Get(0).(func(string, v2.RequestOptions) (map[string]*v1.ContainerInfo, error)); ok {
return rf(containerName, options)
}
if rf, ok := ret.Get(0).(func(string, v2.RequestOptions) map[string]*v1.ContainerInfo); ok {
r0 = rf(containerName, options)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(map[string]*v1.ContainerInfo)
}
}
if rf, ok := ret.Get(1).(func(string, v2.RequestOptions) error); ok {
r1 = rf(containerName, options)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockInterface_GetRequestedContainersInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRequestedContainersInfo'
type MockInterface_GetRequestedContainersInfo_Call struct {
*mock.Call
}
// GetRequestedContainersInfo is a helper method to define mock.On call
// - containerName string
// - options v2.RequestOptions
func (_e *MockInterface_Expecter) GetRequestedContainersInfo(containerName interface{}, options interface{}) *MockInterface_GetRequestedContainersInfo_Call {
return &MockInterface_GetRequestedContainersInfo_Call{Call: _e.mock.On("GetRequestedContainersInfo", containerName, options)}
}
func (_c *MockInterface_GetRequestedContainersInfo_Call) Run(run func(containerName string, options v2.RequestOptions)) *MockInterface_GetRequestedContainersInfo_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(string), args[1].(v2.RequestOptions))
})
return _c
}
func (_c *MockInterface_GetRequestedContainersInfo_Call) Return(_a0 map[string]*v1.ContainerInfo, _a1 error) *MockInterface_GetRequestedContainersInfo_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockInterface_GetRequestedContainersInfo_Call) RunAndReturn(run func(string, v2.RequestOptions) (map[string]*v1.ContainerInfo, error)) *MockInterface_GetRequestedContainersInfo_Call {
_c.Call.Return(run)
return _c
}
// ImagesFsInfo provides a mock function with given fields:
func (_m *MockInterface) ImagesFsInfo() (v2.FsInfo, error) {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for ImagesFsInfo")
}
var r0 v2.FsInfo
var r1 error
if rf, ok := ret.Get(0).(func() (v2.FsInfo, error)); ok {
return rf()
}
if rf, ok := ret.Get(0).(func() v2.FsInfo); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(v2.FsInfo)
}
if rf, ok := ret.Get(1).(func() error); ok {
r1 = rf()
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockInterface_ImagesFsInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ImagesFsInfo'
type MockInterface_ImagesFsInfo_Call struct {
*mock.Call
}
// ImagesFsInfo is a helper method to define mock.On call
func (_e *MockInterface_Expecter) ImagesFsInfo() *MockInterface_ImagesFsInfo_Call {
return &MockInterface_ImagesFsInfo_Call{Call: _e.mock.On("ImagesFsInfo")}
}
func (_c *MockInterface_ImagesFsInfo_Call) Run(run func()) *MockInterface_ImagesFsInfo_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockInterface_ImagesFsInfo_Call) Return(_a0 v2.FsInfo, _a1 error) *MockInterface_ImagesFsInfo_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockInterface_ImagesFsInfo_Call) RunAndReturn(run func() (v2.FsInfo, error)) *MockInterface_ImagesFsInfo_Call {
_c.Call.Return(run)
return _c
}
// MachineInfo provides a mock function with given fields:
func (_m *MockInterface) MachineInfo() (*v1.MachineInfo, error) {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for MachineInfo")
}
var r0 *v1.MachineInfo
var r1 error
if rf, ok := ret.Get(0).(func() (*v1.MachineInfo, error)); ok {
return rf()
}
if rf, ok := ret.Get(0).(func() *v1.MachineInfo); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.MachineInfo)
}
}
if rf, ok := ret.Get(1).(func() error); ok {
r1 = rf()
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockInterface_MachineInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MachineInfo'
type MockInterface_MachineInfo_Call struct {
*mock.Call
}
// MachineInfo is a helper method to define mock.On call
func (_e *MockInterface_Expecter) MachineInfo() *MockInterface_MachineInfo_Call {
return &MockInterface_MachineInfo_Call{Call: _e.mock.On("MachineInfo")}
}
func (_c *MockInterface_MachineInfo_Call) Run(run func()) *MockInterface_MachineInfo_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockInterface_MachineInfo_Call) Return(_a0 *v1.MachineInfo, _a1 error) *MockInterface_MachineInfo_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockInterface_MachineInfo_Call) RunAndReturn(run func() (*v1.MachineInfo, error)) *MockInterface_MachineInfo_Call {
_c.Call.Return(run)
return _c
}
// RootFsInfo provides a mock function with given fields:
func (_m *MockInterface) RootFsInfo() (v2.FsInfo, error) {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for RootFsInfo")
}
var r0 v2.FsInfo
var r1 error
if rf, ok := ret.Get(0).(func() (v2.FsInfo, error)); ok {
return rf()
}
if rf, ok := ret.Get(0).(func() v2.FsInfo); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(v2.FsInfo)
}
if rf, ok := ret.Get(1).(func() error); ok {
r1 = rf()
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockInterface_RootFsInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RootFsInfo'
type MockInterface_RootFsInfo_Call struct {
*mock.Call
}
// RootFsInfo is a helper method to define mock.On call
func (_e *MockInterface_Expecter) RootFsInfo() *MockInterface_RootFsInfo_Call {
return &MockInterface_RootFsInfo_Call{Call: _e.mock.On("RootFsInfo")}
}
func (_c *MockInterface_RootFsInfo_Call) Run(run func()) *MockInterface_RootFsInfo_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockInterface_RootFsInfo_Call) Return(_a0 v2.FsInfo, _a1 error) *MockInterface_RootFsInfo_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockInterface_RootFsInfo_Call) RunAndReturn(run func() (v2.FsInfo, error)) *MockInterface_RootFsInfo_Call {
_c.Call.Return(run)
return _c
}
// Start provides a mock function with given fields:
func (_m *MockInterface) Start() error {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Start")
}
var r0 error
if rf, ok := ret.Get(0).(func() error); ok {
r0 = rf()
} else {
r0 = ret.Error(0)
}
return r0
}
// MockInterface_Start_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Start'
type MockInterface_Start_Call struct {
*mock.Call
}
// Start is a helper method to define mock.On call
func (_e *MockInterface_Expecter) Start() *MockInterface_Start_Call {
return &MockInterface_Start_Call{Call: _e.mock.On("Start")}
}
func (_c *MockInterface_Start_Call) Run(run func()) *MockInterface_Start_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockInterface_Start_Call) Return(_a0 error) *MockInterface_Start_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockInterface_Start_Call) RunAndReturn(run func() error) *MockInterface_Start_Call {
_c.Call.Return(run)
return _c
}
// VersionInfo provides a mock function with given fields:
func (_m *MockInterface) VersionInfo() (*v1.VersionInfo, error) {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for VersionInfo")
}
var r0 *v1.VersionInfo
var r1 error
if rf, ok := ret.Get(0).(func() (*v1.VersionInfo, error)); ok {
return rf()
}
if rf, ok := ret.Get(0).(func() *v1.VersionInfo); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.VersionInfo)
}
}
if rf, ok := ret.Get(1).(func() error); ok {
r1 = rf()
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockInterface_VersionInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VersionInfo'
type MockInterface_VersionInfo_Call struct {
*mock.Call
}
// VersionInfo is a helper method to define mock.On call
func (_e *MockInterface_Expecter) VersionInfo() *MockInterface_VersionInfo_Call {
return &MockInterface_VersionInfo_Call{Call: _e.mock.On("VersionInfo")}
}
func (_c *MockInterface_VersionInfo_Call) Run(run func()) *MockInterface_VersionInfo_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockInterface_VersionInfo_Call) Return(_a0 *v1.VersionInfo, _a1 error) *MockInterface_VersionInfo_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockInterface_VersionInfo_Call) RunAndReturn(run func() (*v1.VersionInfo, error)) *MockInterface_VersionInfo_Call {
_c.Call.Return(run)
return _c
}
// NewMockInterface creates a new instance of MockInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockInterface(t interface {
mock.TestingT
Cleanup(func())
}) *MockInterface {
mock := &MockInterface{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder {
return m.recorder
}
// ContainerFsInfo mocks base method.
func (m *MockInterface) ContainerFsInfo() (v2.FsInfo, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ContainerFsInfo")
ret0, _ := ret[0].(v2.FsInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ContainerFsInfo indicates an expected call of ContainerFsInfo.
func (mr *MockInterfaceMockRecorder) ContainerFsInfo() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerFsInfo", reflect.TypeOf((*MockInterface)(nil).ContainerFsInfo))
}
// ContainerInfoV2 mocks base method.
func (m *MockInterface) ContainerInfoV2(name string, options v2.RequestOptions) (map[string]v2.ContainerInfo, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ContainerInfoV2", name, options)
ret0, _ := ret[0].(map[string]v2.ContainerInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ContainerInfoV2 indicates an expected call of ContainerInfoV2.
func (mr *MockInterfaceMockRecorder) ContainerInfoV2(name, options any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerInfoV2", reflect.TypeOf((*MockInterface)(nil).ContainerInfoV2), name, options)
}
// GetDirFsInfo mocks base method.
func (m *MockInterface) GetDirFsInfo(path string) (v2.FsInfo, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetDirFsInfo", path)
ret0, _ := ret[0].(v2.FsInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetDirFsInfo indicates an expected call of GetDirFsInfo.
func (mr *MockInterfaceMockRecorder) GetDirFsInfo(path any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDirFsInfo", reflect.TypeOf((*MockInterface)(nil).GetDirFsInfo), path)
}
// GetRequestedContainersInfo mocks base method.
func (m *MockInterface) GetRequestedContainersInfo(containerName string, options v2.RequestOptions) (map[string]*v1.ContainerInfo, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetRequestedContainersInfo", containerName, options)
ret0, _ := ret[0].(map[string]*v1.ContainerInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetRequestedContainersInfo indicates an expected call of GetRequestedContainersInfo.
func (mr *MockInterfaceMockRecorder) GetRequestedContainersInfo(containerName, options any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRequestedContainersInfo", reflect.TypeOf((*MockInterface)(nil).GetRequestedContainersInfo), containerName, options)
}
// ImagesFsInfo mocks base method.
func (m *MockInterface) ImagesFsInfo() (v2.FsInfo, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ImagesFsInfo")
ret0, _ := ret[0].(v2.FsInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ImagesFsInfo indicates an expected call of ImagesFsInfo.
func (mr *MockInterfaceMockRecorder) ImagesFsInfo() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImagesFsInfo", reflect.TypeOf((*MockInterface)(nil).ImagesFsInfo))
}
// MachineInfo mocks base method.
func (m *MockInterface) MachineInfo() (*v1.MachineInfo, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "MachineInfo")
ret0, _ := ret[0].(*v1.MachineInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// MachineInfo indicates an expected call of MachineInfo.
func (mr *MockInterfaceMockRecorder) MachineInfo() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MachineInfo", reflect.TypeOf((*MockInterface)(nil).MachineInfo))
}
// RootFsInfo mocks base method.
func (m *MockInterface) RootFsInfo() (v2.FsInfo, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "RootFsInfo")
ret0, _ := ret[0].(v2.FsInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// RootFsInfo indicates an expected call of RootFsInfo.
func (mr *MockInterfaceMockRecorder) RootFsInfo() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RootFsInfo", reflect.TypeOf((*MockInterface)(nil).RootFsInfo))
}
// Start mocks base method.
func (m *MockInterface) Start() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Start")
ret0, _ := ret[0].(error)
return ret0
}
// Start indicates an expected call of Start.
func (mr *MockInterfaceMockRecorder) Start() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockInterface)(nil).Start))
}
// VersionInfo mocks base method.
func (m *MockInterface) VersionInfo() (*v1.VersionInfo, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "VersionInfo")
ret0, _ := ret[0].(*v1.VersionInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// VersionInfo indicates an expected call of VersionInfo.
func (mr *MockInterfaceMockRecorder) VersionInfo() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VersionInfo", reflect.TypeOf((*MockInterface)(nil).VersionInfo))
}
// MockImageFsInfoProvider is a mock of ImageFsInfoProvider interface.
type MockImageFsInfoProvider struct {
ctrl *gomock.Controller
recorder *MockImageFsInfoProviderMockRecorder
}
// MockImageFsInfoProviderMockRecorder is the mock recorder for MockImageFsInfoProvider.
type MockImageFsInfoProviderMockRecorder struct {
mock *MockImageFsInfoProvider
}
// NewMockImageFsInfoProvider creates a new mock instance.
func NewMockImageFsInfoProvider(ctrl *gomock.Controller) *MockImageFsInfoProvider {
mock := &MockImageFsInfoProvider{ctrl: ctrl}
mock.recorder = &MockImageFsInfoProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockImageFsInfoProvider) EXPECT() *MockImageFsInfoProviderMockRecorder {
return m.recorder
}
// ContainerFsInfoLabel mocks base method.
func (m *MockImageFsInfoProvider) ContainerFsInfoLabel() (string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ContainerFsInfoLabel")
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ContainerFsInfoLabel indicates an expected call of ContainerFsInfoLabel.
func (mr *MockImageFsInfoProviderMockRecorder) ContainerFsInfoLabel() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerFsInfoLabel", reflect.TypeOf((*MockImageFsInfoProvider)(nil).ContainerFsInfoLabel))
}
// ImageFsInfoLabel mocks base method.
func (m *MockImageFsInfoProvider) ImageFsInfoLabel() (string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ImageFsInfoLabel")
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ImageFsInfoLabel indicates an expected call of ImageFsInfoLabel.
func (mr *MockImageFsInfoProviderMockRecorder) ImageFsInfoLabel() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageFsInfoLabel", reflect.TypeOf((*MockImageFsInfoProvider)(nil).ImageFsInfoLabel))
}

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate mockgen -source=types.go -destination=testing/cadvisor_mock.go -package=testing Interface
//go:generate mockery
package cadvisor
import (

View File

@ -27,7 +27,6 @@ import (
"time"
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
"go.uber.org/mock/gomock"
"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/stretchr/testify/assert"
@ -177,17 +176,13 @@ func TestSoftRequirementsValidationSuccess(t *testing.T) {
func TestGetCapacity(t *testing.T) {
ephemeralStorageFromCapacity := int64(2000)
ephemeralStorageFromCadvisor := int64(8000)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockCtrlError := gomock.NewController(t)
defer mockCtrlError.Finish()
mockCadvisor := cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor := cadvisortest.NewMockInterface(t)
rootfs := cadvisorapiv2.FsInfo{
Capacity: 8000,
}
mockCadvisor.EXPECT().RootFsInfo().Return(rootfs, nil)
mockCadvisorError := cadvisortest.NewMockInterface(mockCtrlError)
mockCadvisorError := cadvisortest.NewMockInterface(t)
mockCadvisorError.EXPECT().RootFsInfo().Return(cadvisorapiv2.FsInfo{}, errors.New("Unable to get rootfs data from cAdvisor interface"))
cases := []struct {
name string

View File

@ -0,0 +1,18 @@
---
dir: testing
filename: "mock_{{.InterfaceName | snakecase}}.go"
boilerplate-file: ../../../hack/boilerplate/boilerplate.generatego.txt
outpkg: testing
with-expecter: true
packages:
io/fs:
interfaces:
DirEntry:
config:
filename: mockdirentry.go
k8s.io/kubernetes/pkg/kubelet/container:
interfaces:
Runtime:
config:
filename: runtime_mock.go
RuntimeCache:

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate mockgen -source=runtime.go -destination=testing/runtime_mock.go -package=testing Runtime
//go:generate mockery
package container
import (

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate mockgen -source=runtime_cache.go -destination=testing/mock_runtime_cache.go -package=testing RuntimeCache
//go:generate mockery
package container
import (

View File

@ -14,112 +14,148 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: runtime_cache.go
//
// Generated by this command:
//
// mockgen -source=runtime_cache.go -destination=testing/mock_runtime_cache.go -package=testing RuntimeCache
//
// Code generated by mockery v2.40.3. DO NOT EDIT.
// Package testing is a generated GoMock package.
package testing
import (
context "context"
reflect "reflect"
time "time"
gomock "go.uber.org/mock/gomock"
container "k8s.io/kubernetes/pkg/kubelet/container"
mock "github.com/stretchr/testify/mock"
time "time"
)
// MockRuntimeCache is a mock of RuntimeCache interface.
// MockRuntimeCache is an autogenerated mock type for the RuntimeCache type
type MockRuntimeCache struct {
ctrl *gomock.Controller
recorder *MockRuntimeCacheMockRecorder
mock.Mock
}
// MockRuntimeCacheMockRecorder is the mock recorder for MockRuntimeCache.
type MockRuntimeCacheMockRecorder struct {
mock *MockRuntimeCache
type MockRuntimeCache_Expecter struct {
mock *mock.Mock
}
// NewMockRuntimeCache creates a new mock instance.
func NewMockRuntimeCache(ctrl *gomock.Controller) *MockRuntimeCache {
mock := &MockRuntimeCache{ctrl: ctrl}
mock.recorder = &MockRuntimeCacheMockRecorder{mock}
func (_m *MockRuntimeCache) EXPECT() *MockRuntimeCache_Expecter {
return &MockRuntimeCache_Expecter{mock: &_m.Mock}
}
// ForceUpdateIfOlder provides a mock function with given fields: _a0, _a1
func (_m *MockRuntimeCache) ForceUpdateIfOlder(_a0 context.Context, _a1 time.Time) error {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ForceUpdateIfOlder")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, time.Time) error); ok {
r0 = rf(_a0, _a1)
} else {
r0 = ret.Error(0)
}
return r0
}
// MockRuntimeCache_ForceUpdateIfOlder_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ForceUpdateIfOlder'
type MockRuntimeCache_ForceUpdateIfOlder_Call struct {
*mock.Call
}
// ForceUpdateIfOlder is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 time.Time
func (_e *MockRuntimeCache_Expecter) ForceUpdateIfOlder(_a0 interface{}, _a1 interface{}) *MockRuntimeCache_ForceUpdateIfOlder_Call {
return &MockRuntimeCache_ForceUpdateIfOlder_Call{Call: _e.mock.On("ForceUpdateIfOlder", _a0, _a1)}
}
func (_c *MockRuntimeCache_ForceUpdateIfOlder_Call) Run(run func(_a0 context.Context, _a1 time.Time)) *MockRuntimeCache_ForceUpdateIfOlder_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(time.Time))
})
return _c
}
func (_c *MockRuntimeCache_ForceUpdateIfOlder_Call) Return(_a0 error) *MockRuntimeCache_ForceUpdateIfOlder_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockRuntimeCache_ForceUpdateIfOlder_Call) RunAndReturn(run func(context.Context, time.Time) error) *MockRuntimeCache_ForceUpdateIfOlder_Call {
_c.Call.Return(run)
return _c
}
// GetPods provides a mock function with given fields: _a0
func (_m *MockRuntimeCache) GetPods(_a0 context.Context) ([]*container.Pod, error) {
ret := _m.Called(_a0)
if len(ret) == 0 {
panic("no return value specified for GetPods")
}
var r0 []*container.Pod
var r1 error
if rf, ok := ret.Get(0).(func(context.Context) ([]*container.Pod, error)); ok {
return rf(_a0)
}
if rf, ok := ret.Get(0).(func(context.Context) []*container.Pod); ok {
r0 = rf(_a0)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*container.Pod)
}
}
if rf, ok := ret.Get(1).(func(context.Context) error); ok {
r1 = rf(_a0)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockRuntimeCache_GetPods_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPods'
type MockRuntimeCache_GetPods_Call struct {
*mock.Call
}
// GetPods is a helper method to define mock.On call
// - _a0 context.Context
func (_e *MockRuntimeCache_Expecter) GetPods(_a0 interface{}) *MockRuntimeCache_GetPods_Call {
return &MockRuntimeCache_GetPods_Call{Call: _e.mock.On("GetPods", _a0)}
}
func (_c *MockRuntimeCache_GetPods_Call) Run(run func(_a0 context.Context)) *MockRuntimeCache_GetPods_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context))
})
return _c
}
func (_c *MockRuntimeCache_GetPods_Call) Return(_a0 []*container.Pod, _a1 error) *MockRuntimeCache_GetPods_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockRuntimeCache_GetPods_Call) RunAndReturn(run func(context.Context) ([]*container.Pod, error)) *MockRuntimeCache_GetPods_Call {
_c.Call.Return(run)
return _c
}
// NewMockRuntimeCache creates a new instance of MockRuntimeCache. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockRuntimeCache(t interface {
mock.TestingT
Cleanup(func())
}) *MockRuntimeCache {
mock := &MockRuntimeCache{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockRuntimeCache) EXPECT() *MockRuntimeCacheMockRecorder {
return m.recorder
}
// ForceUpdateIfOlder mocks base method.
func (m *MockRuntimeCache) ForceUpdateIfOlder(arg0 context.Context, arg1 time.Time) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ForceUpdateIfOlder", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// ForceUpdateIfOlder indicates an expected call of ForceUpdateIfOlder.
func (mr *MockRuntimeCacheMockRecorder) ForceUpdateIfOlder(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ForceUpdateIfOlder", reflect.TypeOf((*MockRuntimeCache)(nil).ForceUpdateIfOlder), arg0, arg1)
}
// GetPods mocks base method.
func (m *MockRuntimeCache) GetPods(arg0 context.Context) ([]*container.Pod, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPods", arg0)
ret0, _ := ret[0].([]*container.Pod)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetPods indicates an expected call of GetPods.
func (mr *MockRuntimeCacheMockRecorder) GetPods(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPods", reflect.TypeOf((*MockRuntimeCache)(nil).GetPods), arg0)
}
// MockpodsGetter is a mock of podsGetter interface.
type MockpodsGetter struct {
ctrl *gomock.Controller
recorder *MockpodsGetterMockRecorder
}
// MockpodsGetterMockRecorder is the mock recorder for MockpodsGetter.
type MockpodsGetterMockRecorder struct {
mock *MockpodsGetter
}
// NewMockpodsGetter creates a new mock instance.
func NewMockpodsGetter(ctrl *gomock.Controller) *MockpodsGetter {
mock := &MockpodsGetter{ctrl: ctrl}
mock.recorder = &MockpodsGetterMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockpodsGetter) EXPECT() *MockpodsGetterMockRecorder {
return m.recorder
}
// GetPods mocks base method.
func (m *MockpodsGetter) GetPods(arg0 context.Context, arg1 bool) ([]*container.Pod, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPods", arg0, arg1)
ret0, _ := ret[0].([]*container.Pod)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetPods indicates an expected call of GetPods.
func (mr *MockpodsGetterMockRecorder) GetPods(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPods", reflect.TypeOf((*MockpodsGetter)(nil).GetPods), arg0, arg1)
}

View File

@ -1,5 +1,5 @@
/*
Copyright 2022 The Kubernetes Authors.
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -14,94 +14,231 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by MockGen.
// Source: os (interfaces: DirEntry)
// Code generated by mockery v2.40.3. DO NOT EDIT.
package testing
import (
fs "io/fs"
reflect "reflect"
gomock "go.uber.org/mock/gomock"
mock "github.com/stretchr/testify/mock"
)
// MockDirEntry is a mock of DirEntry interface.
// MockDirEntry is an autogenerated mock type for the DirEntry type
type MockDirEntry struct {
ctrl *gomock.Controller
recorder *MockDirEntryMockRecorder
mock.Mock
}
// MockDirEntryMockRecorder is the mock recorder for MockDirEntry.
type MockDirEntryMockRecorder struct {
mock *MockDirEntry
type MockDirEntry_Expecter struct {
mock *mock.Mock
}
// NewMockDirEntry creates a new mock instance.
func NewMockDirEntry(ctrl *gomock.Controller) *MockDirEntry {
mock := &MockDirEntry{ctrl: ctrl}
mock.recorder = &MockDirEntryMockRecorder{mock}
func (_m *MockDirEntry) EXPECT() *MockDirEntry_Expecter {
return &MockDirEntry_Expecter{mock: &_m.Mock}
}
// Info provides a mock function with given fields:
func (_m *MockDirEntry) Info() (fs.FileInfo, error) {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Info")
}
var r0 fs.FileInfo
var r1 error
if rf, ok := ret.Get(0).(func() (fs.FileInfo, error)); ok {
return rf()
}
if rf, ok := ret.Get(0).(func() fs.FileInfo); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(fs.FileInfo)
}
}
if rf, ok := ret.Get(1).(func() error); ok {
r1 = rf()
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockDirEntry_Info_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Info'
type MockDirEntry_Info_Call struct {
*mock.Call
}
// Info is a helper method to define mock.On call
func (_e *MockDirEntry_Expecter) Info() *MockDirEntry_Info_Call {
return &MockDirEntry_Info_Call{Call: _e.mock.On("Info")}
}
func (_c *MockDirEntry_Info_Call) Run(run func()) *MockDirEntry_Info_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockDirEntry_Info_Call) Return(_a0 fs.FileInfo, _a1 error) *MockDirEntry_Info_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockDirEntry_Info_Call) RunAndReturn(run func() (fs.FileInfo, error)) *MockDirEntry_Info_Call {
_c.Call.Return(run)
return _c
}
// IsDir provides a mock function with given fields:
func (_m *MockDirEntry) IsDir() bool {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for IsDir")
}
var r0 bool
if rf, ok := ret.Get(0).(func() bool); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(bool)
}
return r0
}
// MockDirEntry_IsDir_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsDir'
type MockDirEntry_IsDir_Call struct {
*mock.Call
}
// IsDir is a helper method to define mock.On call
func (_e *MockDirEntry_Expecter) IsDir() *MockDirEntry_IsDir_Call {
return &MockDirEntry_IsDir_Call{Call: _e.mock.On("IsDir")}
}
func (_c *MockDirEntry_IsDir_Call) Run(run func()) *MockDirEntry_IsDir_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockDirEntry_IsDir_Call) Return(_a0 bool) *MockDirEntry_IsDir_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockDirEntry_IsDir_Call) RunAndReturn(run func() bool) *MockDirEntry_IsDir_Call {
_c.Call.Return(run)
return _c
}
// Name provides a mock function with given fields:
func (_m *MockDirEntry) Name() string {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Name")
}
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// MockDirEntry_Name_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Name'
type MockDirEntry_Name_Call struct {
*mock.Call
}
// Name is a helper method to define mock.On call
func (_e *MockDirEntry_Expecter) Name() *MockDirEntry_Name_Call {
return &MockDirEntry_Name_Call{Call: _e.mock.On("Name")}
}
func (_c *MockDirEntry_Name_Call) Run(run func()) *MockDirEntry_Name_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockDirEntry_Name_Call) Return(_a0 string) *MockDirEntry_Name_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockDirEntry_Name_Call) RunAndReturn(run func() string) *MockDirEntry_Name_Call {
_c.Call.Return(run)
return _c
}
// Type provides a mock function with given fields:
func (_m *MockDirEntry) Type() fs.FileMode {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Type")
}
var r0 fs.FileMode
if rf, ok := ret.Get(0).(func() fs.FileMode); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(fs.FileMode)
}
return r0
}
// MockDirEntry_Type_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Type'
type MockDirEntry_Type_Call struct {
*mock.Call
}
// Type is a helper method to define mock.On call
func (_e *MockDirEntry_Expecter) Type() *MockDirEntry_Type_Call {
return &MockDirEntry_Type_Call{Call: _e.mock.On("Type")}
}
func (_c *MockDirEntry_Type_Call) Run(run func()) *MockDirEntry_Type_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockDirEntry_Type_Call) Return(_a0 fs.FileMode) *MockDirEntry_Type_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockDirEntry_Type_Call) RunAndReturn(run func() fs.FileMode) *MockDirEntry_Type_Call {
_c.Call.Return(run)
return _c
}
// NewMockDirEntry creates a new instance of MockDirEntry. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockDirEntry(t interface {
mock.TestingT
Cleanup(func())
}) *MockDirEntry {
mock := &MockDirEntry{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockDirEntry) EXPECT() *MockDirEntryMockRecorder {
return m.recorder
}
// Info mocks base method.
func (m *MockDirEntry) Info() (fs.FileInfo, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Info")
ret0, _ := ret[0].(fs.FileInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Info indicates an expected call of Info.
func (mr *MockDirEntryMockRecorder) Info() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Info", reflect.TypeOf((*MockDirEntry)(nil).Info))
}
// IsDir mocks base method.
func (m *MockDirEntry) IsDir() bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsDir")
ret0, _ := ret[0].(bool)
return ret0
}
// IsDir indicates an expected call of IsDir.
func (mr *MockDirEntryMockRecorder) IsDir() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsDir", reflect.TypeOf((*MockDirEntry)(nil).IsDir))
}
// Name mocks base method.
func (m *MockDirEntry) Name() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Name")
ret0, _ := ret[0].(string)
return ret0
}
// Name indicates an expected call of Name.
func (mr *MockDirEntryMockRecorder) Name() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockDirEntry)(nil).Name))
}
// Type mocks base method.
func (m *MockDirEntry) Type() fs.FileMode {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Type")
ret0, _ := ret[0].(fs.FileMode)
return ret0
}
// Type indicates an expected call of Type.
func (mr *MockDirEntryMockRecorder) Type() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Type", reflect.TypeOf((*MockDirEntry)(nil).Type))
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
---
dir: .
filename: "mock_{{.InterfaceName | snakecase}}_test.go"
boilerplate-file: ../../../hack/boilerplate/boilerplate.generatego.txt
inpackage: true
with-expecter: true
packages:
k8s.io/kubernetes/pkg/kubelet/eviction:
interfaces:
CgroupNotifier:
NotifierFactory:
ThresholdNotifier:

View File

@ -24,7 +24,6 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
gomock "go.uber.org/mock/gomock"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
@ -2976,10 +2975,7 @@ func TestUpdateMemcgThreshold(t *testing.T) {
}
summaryProvider := &fakeSummaryProvider{result: makeMemoryStats("2Gi", map[*v1.Pod]statsapi.PodStats{})}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
thresholdNotifier := NewMockThresholdNotifier(mockCtrl)
thresholdNotifier := NewMockThresholdNotifier(t)
thresholdNotifier.EXPECT().UpdateThreshold(summaryProvider.result).Return(nil).Times(2)
manager := &managerImpl{
@ -3019,7 +3015,7 @@ func TestUpdateMemcgThreshold(t *testing.T) {
}
// new memory threshold notifier that returns an error
thresholdNotifier = NewMockThresholdNotifier(mockCtrl)
thresholdNotifier = NewMockThresholdNotifier(t)
thresholdNotifier.EXPECT().UpdateThreshold(summaryProvider.result).Return(fmt.Errorf("error updating threshold")).Times(1)
thresholdNotifier.EXPECT().Description().Return("mock thresholdNotifier").Times(1)
manager.thresholdNotifiers = []ThresholdNotifier{thresholdNotifier}

View File

@ -23,7 +23,6 @@ import (
"testing"
"time"
gomock "go.uber.org/mock/gomock"
"k8s.io/apimachinery/pkg/api/resource"
statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
evictionapi "k8s.io/kubernetes/pkg/kubelet/eviction/api"
@ -130,18 +129,15 @@ func TestUpdateThreshold(t *testing.T) {
},
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
notifierFactory := NewMockNotifierFactory(mockCtrl)
notifier := NewMockCgroupNotifier(mockCtrl)
notifierFactory := NewMockNotifierFactory(t)
notifier := NewMockCgroupNotifier(t)
m := newTestMemoryThresholdNotifier(tc.evictionThreshold, notifierFactory, nil)
notifierFactory.EXPECT().NewCgroupNotifier(testCgroupPath, memoryUsageAttribute, tc.expectedThreshold.Value()).Return(notifier, tc.updateThresholdErr).Times(1)
var events chan<- struct{} = m.events
notifier.EXPECT().Start(events).Return().AnyTimes()
notifier.EXPECT().Start(events).Return().Maybe()
err := m.UpdateThreshold(nodeSummary(tc.available, tc.workingSet, tc.usage, isAllocatableEvictionThreshold(tc.evictionThreshold)))
if err != nil && !tc.expectErr {
t.Errorf("Unexpected error updating threshold: %v", err)
@ -161,10 +157,8 @@ func TestStart(t *testing.T) {
Quantity: &noResources,
},
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
notifierFactory := NewMockNotifierFactory(mockCtrl)
notifier := NewMockCgroupNotifier(mockCtrl)
notifierFactory := NewMockNotifierFactory(t)
notifier := NewMockCgroupNotifier(t)
var wg sync.WaitGroup
wg.Add(4)
@ -174,7 +168,7 @@ func TestStart(t *testing.T) {
notifierFactory.EXPECT().NewCgroupNotifier(testCgroupPath, memoryUsageAttribute, int64(0)).Return(notifier, nil).Times(1)
var events chan<- struct{} = m.events
notifier.EXPECT().Start(events).DoAndReturn(func(events chan<- struct{}) {
notifier.EXPECT().Start(events).Run(func(events chan<- struct{}) {
for i := 0; i < 4; i++ {
events <- struct{}{}
}

View File

@ -0,0 +1,113 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package eviction
import mock "github.com/stretchr/testify/mock"
// MockCgroupNotifier is an autogenerated mock type for the CgroupNotifier type
type MockCgroupNotifier struct {
mock.Mock
}
type MockCgroupNotifier_Expecter struct {
mock *mock.Mock
}
func (_m *MockCgroupNotifier) EXPECT() *MockCgroupNotifier_Expecter {
return &MockCgroupNotifier_Expecter{mock: &_m.Mock}
}
// Start provides a mock function with given fields: eventCh
func (_m *MockCgroupNotifier) Start(eventCh chan<- struct{}) {
_m.Called(eventCh)
}
// MockCgroupNotifier_Start_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Start'
type MockCgroupNotifier_Start_Call struct {
*mock.Call
}
// Start is a helper method to define mock.On call
// - eventCh chan<- struct{}
func (_e *MockCgroupNotifier_Expecter) Start(eventCh interface{}) *MockCgroupNotifier_Start_Call {
return &MockCgroupNotifier_Start_Call{Call: _e.mock.On("Start", eventCh)}
}
func (_c *MockCgroupNotifier_Start_Call) Run(run func(eventCh chan<- struct{})) *MockCgroupNotifier_Start_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(chan<- struct{}))
})
return _c
}
func (_c *MockCgroupNotifier_Start_Call) Return() *MockCgroupNotifier_Start_Call {
_c.Call.Return()
return _c
}
func (_c *MockCgroupNotifier_Start_Call) RunAndReturn(run func(chan<- struct{})) *MockCgroupNotifier_Start_Call {
_c.Call.Return(run)
return _c
}
// Stop provides a mock function with given fields:
func (_m *MockCgroupNotifier) Stop() {
_m.Called()
}
// MockCgroupNotifier_Stop_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Stop'
type MockCgroupNotifier_Stop_Call struct {
*mock.Call
}
// Stop is a helper method to define mock.On call
func (_e *MockCgroupNotifier_Expecter) Stop() *MockCgroupNotifier_Stop_Call {
return &MockCgroupNotifier_Stop_Call{Call: _e.mock.On("Stop")}
}
func (_c *MockCgroupNotifier_Stop_Call) Run(run func()) *MockCgroupNotifier_Stop_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockCgroupNotifier_Stop_Call) Return() *MockCgroupNotifier_Stop_Call {
_c.Call.Return()
return _c
}
func (_c *MockCgroupNotifier_Stop_Call) RunAndReturn(run func()) *MockCgroupNotifier_Stop_Call {
_c.Call.Return(run)
return _c
}
// NewMockCgroupNotifier creates a new instance of MockCgroupNotifier. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockCgroupNotifier(t interface {
mock.TestingT
Cleanup(func())
}) *MockCgroupNotifier {
mock := &MockCgroupNotifier{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -0,0 +1,108 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package eviction
import mock "github.com/stretchr/testify/mock"
// MockNotifierFactory is an autogenerated mock type for the NotifierFactory type
type MockNotifierFactory struct {
mock.Mock
}
type MockNotifierFactory_Expecter struct {
mock *mock.Mock
}
func (_m *MockNotifierFactory) EXPECT() *MockNotifierFactory_Expecter {
return &MockNotifierFactory_Expecter{mock: &_m.Mock}
}
// NewCgroupNotifier provides a mock function with given fields: path, attribute, threshold
func (_m *MockNotifierFactory) NewCgroupNotifier(path string, attribute string, threshold int64) (CgroupNotifier, error) {
ret := _m.Called(path, attribute, threshold)
if len(ret) == 0 {
panic("no return value specified for NewCgroupNotifier")
}
var r0 CgroupNotifier
var r1 error
if rf, ok := ret.Get(0).(func(string, string, int64) (CgroupNotifier, error)); ok {
return rf(path, attribute, threshold)
}
if rf, ok := ret.Get(0).(func(string, string, int64) CgroupNotifier); ok {
r0 = rf(path, attribute, threshold)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(CgroupNotifier)
}
}
if rf, ok := ret.Get(1).(func(string, string, int64) error); ok {
r1 = rf(path, attribute, threshold)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockNotifierFactory_NewCgroupNotifier_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewCgroupNotifier'
type MockNotifierFactory_NewCgroupNotifier_Call struct {
*mock.Call
}
// NewCgroupNotifier is a helper method to define mock.On call
// - path string
// - attribute string
// - threshold int64
func (_e *MockNotifierFactory_Expecter) NewCgroupNotifier(path interface{}, attribute interface{}, threshold interface{}) *MockNotifierFactory_NewCgroupNotifier_Call {
return &MockNotifierFactory_NewCgroupNotifier_Call{Call: _e.mock.On("NewCgroupNotifier", path, attribute, threshold)}
}
func (_c *MockNotifierFactory_NewCgroupNotifier_Call) Run(run func(path string, attribute string, threshold int64)) *MockNotifierFactory_NewCgroupNotifier_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(string), args[1].(string), args[2].(int64))
})
return _c
}
func (_c *MockNotifierFactory_NewCgroupNotifier_Call) Return(_a0 CgroupNotifier, _a1 error) *MockNotifierFactory_NewCgroupNotifier_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockNotifierFactory_NewCgroupNotifier_Call) RunAndReturn(run func(string, string, int64) (CgroupNotifier, error)) *MockNotifierFactory_NewCgroupNotifier_Call {
_c.Call.Return(run)
return _c
}
// NewMockNotifierFactory creates a new instance of MockNotifierFactory. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockNotifierFactory(t interface {
mock.TestingT
Cleanup(func())
}) *MockNotifierFactory {
mock := &MockNotifierFactory{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -14,373 +14,161 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: types.go
//
// Generated by this command:
//
// mockgen -source=types.go -destination=mock_threshold_notifier_test.go -package=eviction NotifierFactory,ThresholdNotifier
//
// Code generated by mockery v2.40.3. DO NOT EDIT.
// Package eviction is a generated GoMock package.
package eviction
import (
context "context"
reflect "reflect"
time "time"
gomock "go.uber.org/mock/gomock"
mock "github.com/stretchr/testify/mock"
v1alpha1 "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
)
// MockManager is a mock of Manager interface.
type MockManager struct {
ctrl *gomock.Controller
recorder *MockManagerMockRecorder
}
// MockManagerMockRecorder is the mock recorder for MockManager.
type MockManagerMockRecorder struct {
mock *MockManager
}
// NewMockManager creates a new mock instance.
func NewMockManager(ctrl *gomock.Controller) *MockManager {
mock := &MockManager{ctrl: ctrl}
mock.recorder = &MockManagerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockManager) EXPECT() *MockManagerMockRecorder {
return m.recorder
}
// IsUnderDiskPressure mocks base method.
func (m *MockManager) IsUnderDiskPressure() bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsUnderDiskPressure")
ret0, _ := ret[0].(bool)
return ret0
}
// IsUnderDiskPressure indicates an expected call of IsUnderDiskPressure.
func (mr *MockManagerMockRecorder) IsUnderDiskPressure() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUnderDiskPressure", reflect.TypeOf((*MockManager)(nil).IsUnderDiskPressure))
}
// IsUnderMemoryPressure mocks base method.
func (m *MockManager) IsUnderMemoryPressure() bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsUnderMemoryPressure")
ret0, _ := ret[0].(bool)
return ret0
}
// IsUnderMemoryPressure indicates an expected call of IsUnderMemoryPressure.
func (mr *MockManagerMockRecorder) IsUnderMemoryPressure() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUnderMemoryPressure", reflect.TypeOf((*MockManager)(nil).IsUnderMemoryPressure))
}
// IsUnderPIDPressure mocks base method.
func (m *MockManager) IsUnderPIDPressure() bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsUnderPIDPressure")
ret0, _ := ret[0].(bool)
return ret0
}
// IsUnderPIDPressure indicates an expected call of IsUnderPIDPressure.
func (mr *MockManagerMockRecorder) IsUnderPIDPressure() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUnderPIDPressure", reflect.TypeOf((*MockManager)(nil).IsUnderPIDPressure))
}
// Start mocks base method.
func (m *MockManager) Start(diskInfoProvider DiskInfoProvider, podFunc ActivePodsFunc, podCleanedUpFunc PodCleanedUpFunc, monitoringInterval time.Duration) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Start", diskInfoProvider, podFunc, podCleanedUpFunc, monitoringInterval)
}
// Start indicates an expected call of Start.
func (mr *MockManagerMockRecorder) Start(diskInfoProvider, podFunc, podCleanedUpFunc, monitoringInterval any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockManager)(nil).Start), diskInfoProvider, podFunc, podCleanedUpFunc, monitoringInterval)
}
// MockDiskInfoProvider is a mock of DiskInfoProvider interface.
type MockDiskInfoProvider struct {
ctrl *gomock.Controller
recorder *MockDiskInfoProviderMockRecorder
}
// MockDiskInfoProviderMockRecorder is the mock recorder for MockDiskInfoProvider.
type MockDiskInfoProviderMockRecorder struct {
mock *MockDiskInfoProvider
}
// NewMockDiskInfoProvider creates a new mock instance.
func NewMockDiskInfoProvider(ctrl *gomock.Controller) *MockDiskInfoProvider {
mock := &MockDiskInfoProvider{ctrl: ctrl}
mock.recorder = &MockDiskInfoProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockDiskInfoProvider) EXPECT() *MockDiskInfoProviderMockRecorder {
return m.recorder
}
// HasDedicatedImageFs mocks base method.
func (m *MockDiskInfoProvider) HasDedicatedImageFs(ctx context.Context) (bool, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "HasDedicatedImageFs", ctx)
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// HasDedicatedImageFs indicates an expected call of HasDedicatedImageFs.
func (mr *MockDiskInfoProviderMockRecorder) HasDedicatedImageFs(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasDedicatedImageFs", reflect.TypeOf((*MockDiskInfoProvider)(nil).HasDedicatedImageFs), ctx)
}
// MockImageGC is a mock of ImageGC interface.
type MockImageGC struct {
ctrl *gomock.Controller
recorder *MockImageGCMockRecorder
}
// MockImageGCMockRecorder is the mock recorder for MockImageGC.
type MockImageGCMockRecorder struct {
mock *MockImageGC
}
// NewMockImageGC creates a new mock instance.
func NewMockImageGC(ctrl *gomock.Controller) *MockImageGC {
mock := &MockImageGC{ctrl: ctrl}
mock.recorder = &MockImageGCMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockImageGC) EXPECT() *MockImageGCMockRecorder {
return m.recorder
}
// DeleteUnusedImages mocks base method.
func (m *MockImageGC) DeleteUnusedImages(ctx context.Context) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DeleteUnusedImages", ctx)
ret0, _ := ret[0].(error)
return ret0
}
// DeleteUnusedImages indicates an expected call of DeleteUnusedImages.
func (mr *MockImageGCMockRecorder) DeleteUnusedImages(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteUnusedImages", reflect.TypeOf((*MockImageGC)(nil).DeleteUnusedImages), ctx)
}
// MockContainerGC is a mock of ContainerGC interface.
type MockContainerGC struct {
ctrl *gomock.Controller
recorder *MockContainerGCMockRecorder
}
// MockContainerGCMockRecorder is the mock recorder for MockContainerGC.
type MockContainerGCMockRecorder struct {
mock *MockContainerGC
}
// NewMockContainerGC creates a new mock instance.
func NewMockContainerGC(ctrl *gomock.Controller) *MockContainerGC {
mock := &MockContainerGC{ctrl: ctrl}
mock.recorder = &MockContainerGCMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockContainerGC) EXPECT() *MockContainerGCMockRecorder {
return m.recorder
}
// DeleteAllUnusedContainers mocks base method.
func (m *MockContainerGC) DeleteAllUnusedContainers(ctx context.Context) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DeleteAllUnusedContainers", ctx)
ret0, _ := ret[0].(error)
return ret0
}
// DeleteAllUnusedContainers indicates an expected call of DeleteAllUnusedContainers.
func (mr *MockContainerGCMockRecorder) DeleteAllUnusedContainers(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteAllUnusedContainers", reflect.TypeOf((*MockContainerGC)(nil).DeleteAllUnusedContainers), ctx)
}
// IsContainerFsSeparateFromImageFs mocks base method.
func (m *MockContainerGC) IsContainerFsSeparateFromImageFs(ctx context.Context) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsContainerFsSeparateFromImageFs", ctx)
ret0, _ := ret[0].(bool)
return ret0
}
// IsContainerFsSeparateFromImageFs indicates an expected call of IsContainerFsSeparateFromImageFs.
func (mr *MockContainerGCMockRecorder) IsContainerFsSeparateFromImageFs(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsContainerFsSeparateFromImageFs", reflect.TypeOf((*MockContainerGC)(nil).IsContainerFsSeparateFromImageFs), ctx)
}
// MockCgroupNotifier is a mock of CgroupNotifier interface.
type MockCgroupNotifier struct {
ctrl *gomock.Controller
recorder *MockCgroupNotifierMockRecorder
}
// MockCgroupNotifierMockRecorder is the mock recorder for MockCgroupNotifier.
type MockCgroupNotifierMockRecorder struct {
mock *MockCgroupNotifier
}
// NewMockCgroupNotifier creates a new mock instance.
func NewMockCgroupNotifier(ctrl *gomock.Controller) *MockCgroupNotifier {
mock := &MockCgroupNotifier{ctrl: ctrl}
mock.recorder = &MockCgroupNotifierMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockCgroupNotifier) EXPECT() *MockCgroupNotifierMockRecorder {
return m.recorder
}
// Start mocks base method.
func (m *MockCgroupNotifier) Start(eventCh chan<- struct{}) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Start", eventCh)
}
// Start indicates an expected call of Start.
func (mr *MockCgroupNotifierMockRecorder) Start(eventCh any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockCgroupNotifier)(nil).Start), eventCh)
}
// Stop mocks base method.
func (m *MockCgroupNotifier) Stop() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Stop")
}
// Stop indicates an expected call of Stop.
func (mr *MockCgroupNotifierMockRecorder) Stop() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockCgroupNotifier)(nil).Stop))
}
// MockNotifierFactory is a mock of NotifierFactory interface.
type MockNotifierFactory struct {
ctrl *gomock.Controller
recorder *MockNotifierFactoryMockRecorder
}
// MockNotifierFactoryMockRecorder is the mock recorder for MockNotifierFactory.
type MockNotifierFactoryMockRecorder struct {
mock *MockNotifierFactory
}
// NewMockNotifierFactory creates a new mock instance.
func NewMockNotifierFactory(ctrl *gomock.Controller) *MockNotifierFactory {
mock := &MockNotifierFactory{ctrl: ctrl}
mock.recorder = &MockNotifierFactoryMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockNotifierFactory) EXPECT() *MockNotifierFactoryMockRecorder {
return m.recorder
}
// NewCgroupNotifier mocks base method.
func (m *MockNotifierFactory) NewCgroupNotifier(path, attribute string, threshold int64) (CgroupNotifier, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NewCgroupNotifier", path, attribute, threshold)
ret0, _ := ret[0].(CgroupNotifier)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// NewCgroupNotifier indicates an expected call of NewCgroupNotifier.
func (mr *MockNotifierFactoryMockRecorder) NewCgroupNotifier(path, attribute, threshold any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewCgroupNotifier", reflect.TypeOf((*MockNotifierFactory)(nil).NewCgroupNotifier), path, attribute, threshold)
}
// MockThresholdNotifier is a mock of ThresholdNotifier interface.
// MockThresholdNotifier is an autogenerated mock type for the ThresholdNotifier type
type MockThresholdNotifier struct {
ctrl *gomock.Controller
recorder *MockThresholdNotifierMockRecorder
mock.Mock
}
// MockThresholdNotifierMockRecorder is the mock recorder for MockThresholdNotifier.
type MockThresholdNotifierMockRecorder struct {
mock *MockThresholdNotifier
type MockThresholdNotifier_Expecter struct {
mock *mock.Mock
}
// NewMockThresholdNotifier creates a new mock instance.
func NewMockThresholdNotifier(ctrl *gomock.Controller) *MockThresholdNotifier {
mock := &MockThresholdNotifier{ctrl: ctrl}
mock.recorder = &MockThresholdNotifierMockRecorder{mock}
func (_m *MockThresholdNotifier) EXPECT() *MockThresholdNotifier_Expecter {
return &MockThresholdNotifier_Expecter{mock: &_m.Mock}
}
// Description provides a mock function with given fields:
func (_m *MockThresholdNotifier) Description() string {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Description")
}
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// MockThresholdNotifier_Description_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Description'
type MockThresholdNotifier_Description_Call struct {
*mock.Call
}
// Description is a helper method to define mock.On call
func (_e *MockThresholdNotifier_Expecter) Description() *MockThresholdNotifier_Description_Call {
return &MockThresholdNotifier_Description_Call{Call: _e.mock.On("Description")}
}
func (_c *MockThresholdNotifier_Description_Call) Run(run func()) *MockThresholdNotifier_Description_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockThresholdNotifier_Description_Call) Return(_a0 string) *MockThresholdNotifier_Description_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockThresholdNotifier_Description_Call) RunAndReturn(run func() string) *MockThresholdNotifier_Description_Call {
_c.Call.Return(run)
return _c
}
// Start provides a mock function with given fields:
func (_m *MockThresholdNotifier) Start() {
_m.Called()
}
// MockThresholdNotifier_Start_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Start'
type MockThresholdNotifier_Start_Call struct {
*mock.Call
}
// Start is a helper method to define mock.On call
func (_e *MockThresholdNotifier_Expecter) Start() *MockThresholdNotifier_Start_Call {
return &MockThresholdNotifier_Start_Call{Call: _e.mock.On("Start")}
}
func (_c *MockThresholdNotifier_Start_Call) Run(run func()) *MockThresholdNotifier_Start_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockThresholdNotifier_Start_Call) Return() *MockThresholdNotifier_Start_Call {
_c.Call.Return()
return _c
}
func (_c *MockThresholdNotifier_Start_Call) RunAndReturn(run func()) *MockThresholdNotifier_Start_Call {
_c.Call.Return(run)
return _c
}
// UpdateThreshold provides a mock function with given fields: summary
func (_m *MockThresholdNotifier) UpdateThreshold(summary *v1alpha1.Summary) error {
ret := _m.Called(summary)
if len(ret) == 0 {
panic("no return value specified for UpdateThreshold")
}
var r0 error
if rf, ok := ret.Get(0).(func(*v1alpha1.Summary) error); ok {
r0 = rf(summary)
} else {
r0 = ret.Error(0)
}
return r0
}
// MockThresholdNotifier_UpdateThreshold_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateThreshold'
type MockThresholdNotifier_UpdateThreshold_Call struct {
*mock.Call
}
// UpdateThreshold is a helper method to define mock.On call
// - summary *v1alpha1.Summary
func (_e *MockThresholdNotifier_Expecter) UpdateThreshold(summary interface{}) *MockThresholdNotifier_UpdateThreshold_Call {
return &MockThresholdNotifier_UpdateThreshold_Call{Call: _e.mock.On("UpdateThreshold", summary)}
}
func (_c *MockThresholdNotifier_UpdateThreshold_Call) Run(run func(summary *v1alpha1.Summary)) *MockThresholdNotifier_UpdateThreshold_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(*v1alpha1.Summary))
})
return _c
}
func (_c *MockThresholdNotifier_UpdateThreshold_Call) Return(_a0 error) *MockThresholdNotifier_UpdateThreshold_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockThresholdNotifier_UpdateThreshold_Call) RunAndReturn(run func(*v1alpha1.Summary) error) *MockThresholdNotifier_UpdateThreshold_Call {
_c.Call.Return(run)
return _c
}
// NewMockThresholdNotifier creates a new instance of MockThresholdNotifier. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockThresholdNotifier(t interface {
mock.TestingT
Cleanup(func())
}) *MockThresholdNotifier {
mock := &MockThresholdNotifier{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockThresholdNotifier) EXPECT() *MockThresholdNotifierMockRecorder {
return m.recorder
}
// Description mocks base method.
func (m *MockThresholdNotifier) Description() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Description")
ret0, _ := ret[0].(string)
return ret0
}
// Description indicates an expected call of Description.
func (mr *MockThresholdNotifierMockRecorder) Description() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Description", reflect.TypeOf((*MockThresholdNotifier)(nil).Description))
}
// Start mocks base method.
func (m *MockThresholdNotifier) Start() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Start")
}
// Start indicates an expected call of Start.
func (mr *MockThresholdNotifierMockRecorder) Start() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockThresholdNotifier)(nil).Start))
}
// UpdateThreshold mocks base method.
func (m *MockThresholdNotifier) UpdateThreshold(summary *v1alpha1.Summary) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UpdateThreshold", summary)
ret0, _ := ret[0].(error)
return ret0
}
// UpdateThreshold indicates an expected call of UpdateThreshold.
func (mr *MockThresholdNotifierMockRecorder) UpdateThreshold(summary any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateThreshold", reflect.TypeOf((*MockThresholdNotifier)(nil).UpdateThreshold), summary)
}

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate mockgen -source=types.go -destination=mock_threshold_notifier_test.go -package=eviction NotifierFactory,ThresholdNotifier
//go:generate mockery
package eviction
import (

View File

@ -24,8 +24,8 @@ import (
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
noopoteltrace "go.opentelemetry.io/otel/trace/noop"
utilfeature "k8s.io/apiserver/pkg/util/feature"
@ -125,9 +125,7 @@ func makeContainer(id int) *container.Container {
func TestDetectImagesInitialDetect(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -175,9 +173,7 @@ func TestDetectImagesInitialDetectWithRuntimeHandlerInImageCriAPIFeatureGate(t *
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.RuntimeClassInImageCriAPI, true)
testRuntimeHandler := "test-runtimeHandler"
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -231,9 +227,7 @@ func TestDetectImagesInitialDetectWithRuntimeHandlerInImageCriAPIFeatureGate(t *
func TestDetectImagesWithNewImage(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
// Just one image initially.
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
@ -285,9 +279,7 @@ func TestDetectImagesWithNewImage(t *testing.T) {
func TestDeleteUnusedImagesExemptSandboxImage(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -306,8 +298,7 @@ func TestDeleteUnusedImagesExemptSandboxImage(t *testing.T) {
func TestDeletePinnedImage(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -330,8 +321,7 @@ func TestDeletePinnedImage(t *testing.T) {
func TestDoNotDeletePinnedImage(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -352,8 +342,7 @@ func TestDoNotDeletePinnedImage(t *testing.T) {
func TestDeleteUnPinnedImage(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -374,8 +363,7 @@ func TestDeleteUnPinnedImage(t *testing.T) {
func TestAllPinnedImages(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -397,9 +385,7 @@ func TestAllPinnedImages(t *testing.T) {
func TestDetectImagesContainerStopped(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -438,9 +424,7 @@ func TestDetectImagesContainerStopped(t *testing.T) {
func TestDetectImagesWithRemovedImages(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -469,9 +453,7 @@ func TestDetectImagesWithRemovedImages(t *testing.T) {
func TestFreeSpaceImagesInUseContainersAreIgnored(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -492,9 +474,7 @@ func TestFreeSpaceImagesInUseContainersAreIgnored(t *testing.T) {
func TestDeleteUnusedImagesRemoveAllUnusedImages(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -518,9 +498,7 @@ func TestDeleteUnusedImagesRemoveAllUnusedImages(t *testing.T) {
func TestDeleteUnusedImagesLimitByImageLiveTime(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{
MinAge: time.Second * 3, // set minAge to 3 seconds,
@ -553,9 +531,7 @@ func TestDeleteUnusedImagesLimitByImageLiveTime(t *testing.T) {
func TestFreeSpaceRemoveByLeastRecentlyUsed(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -607,9 +583,7 @@ func TestFreeSpaceRemoveByLeastRecentlyUsed(t *testing.T) {
func TestFreeSpaceTiesBrokenByDetectedTime(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(ImageGCPolicy{}, mockStatsProvider)
fakeRuntime.ImageList = []container.Image{
@ -647,9 +621,7 @@ func TestGarbageCollectBelowLowThreshold(t *testing.T) {
HighThresholdPercent: 90,
LowThresholdPercent: 80,
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, _ := newRealImageGCManager(policy, mockStatsProvider)
// Expect 40% usage.
@ -657,7 +629,7 @@ func TestGarbageCollectBelowLowThreshold(t *testing.T) {
AvailableBytes: uint64Ptr(600),
CapacityBytes: uint64Ptr(1000),
}
mockStatsProvider.EXPECT().ImageFsStats(gomock.Any()).Return(imageStats, imageStats, nil)
mockStatsProvider.EXPECT().ImageFsStats(mock.Anything).Return(imageStats, imageStats, nil)
assert.NoError(t, manager.GarbageCollect(ctx, time.Now()))
}
@ -668,12 +640,10 @@ func TestGarbageCollectCadvisorFailure(t *testing.T) {
HighThresholdPercent: 90,
LowThresholdPercent: 80,
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, _ := newRealImageGCManager(policy, mockStatsProvider)
mockStatsProvider.EXPECT().ImageFsStats(gomock.Any()).Return(&statsapi.FsStats{}, &statsapi.FsStats{}, fmt.Errorf("error"))
mockStatsProvider.EXPECT().ImageFsStats(mock.Anything).Return(&statsapi.FsStats{}, &statsapi.FsStats{}, fmt.Errorf("error"))
assert.NotNil(t, manager.GarbageCollect(ctx, time.Now()))
}
@ -684,9 +654,7 @@ func TestGarbageCollectBelowSuccess(t *testing.T) {
LowThresholdPercent: 80,
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(policy, mockStatsProvider)
// Expect 95% usage and most of it gets freed.
@ -694,7 +662,7 @@ func TestGarbageCollectBelowSuccess(t *testing.T) {
AvailableBytes: uint64Ptr(50),
CapacityBytes: uint64Ptr(1000),
}
mockStatsProvider.EXPECT().ImageFsStats(gomock.Any()).Return(imageFs, imageFs, nil)
mockStatsProvider.EXPECT().ImageFsStats(mock.Anything).Return(imageFs, imageFs, nil)
fakeRuntime.ImageList = []container.Image{
makeImage(0, 450),
}
@ -708,9 +676,7 @@ func TestGarbageCollectNotEnoughFreed(t *testing.T) {
HighThresholdPercent: 90,
LowThresholdPercent: 80,
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager, fakeRuntime := newRealImageGCManager(policy, mockStatsProvider)
// Expect 95% usage and little of it gets freed.
@ -718,7 +684,7 @@ func TestGarbageCollectNotEnoughFreed(t *testing.T) {
AvailableBytes: uint64Ptr(50),
CapacityBytes: uint64Ptr(1000),
}
mockStatsProvider.EXPECT().ImageFsStats(gomock.Any()).Return(imageFs, imageFs, nil)
mockStatsProvider.EXPECT().ImageFsStats(mock.Anything).Return(imageFs, imageFs, nil)
fakeRuntime.ImageList = []container.Image{
makeImage(0, 50),
}
@ -734,9 +700,7 @@ func TestGarbageCollectImageNotOldEnough(t *testing.T) {
MinAge: time.Minute * 1,
}
fakeRuntime := &containertest.FakeRuntime{}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager := &realImageGCManager{
runtime: fakeRuntime,
policy: policy,
@ -790,9 +754,7 @@ func TestGarbageCollectImageTooOld(t *testing.T) {
MaxAge: time.Minute * 1,
}
fakeRuntime := &containertest.FakeRuntime{}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager := &realImageGCManager{
runtime: fakeRuntime,
policy: policy,
@ -847,9 +809,7 @@ func TestGarbageCollectImageMaxAgeDisabled(t *testing.T) {
MaxAge: 0,
}
fakeRuntime := &containertest.FakeRuntime{}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
manager := &realImageGCManager{
runtime: fakeRuntime,
policy: policy,

View File

@ -40,7 +40,6 @@ import (
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
core "k8s.io/client-go/testing"
"k8s.io/mount-utils"
@ -3054,15 +3053,13 @@ func TestNewMainKubeletStandAlone(t *testing.T) {
}
var prober volume.DynamicPluginProber
tp := noopoteltrace.NewTracerProvider()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
cadvisor := cadvisortest.NewMockInterface(mockCtrl)
cadvisor.EXPECT().MachineInfo().Return(&cadvisorapi.MachineInfo{}, nil).AnyTimes()
cadvisor := cadvisortest.NewMockInterface(t)
cadvisor.EXPECT().MachineInfo().Return(&cadvisorapi.MachineInfo{}, nil).Maybe()
cadvisor.EXPECT().ImagesFsInfo().Return(cadvisorapiv2.FsInfo{
Usage: 400,
Capacity: 1000,
Available: 600,
}, nil).AnyTimes()
}, nil).Maybe()
tlsOptions := &server.TLSOptions{
Config: &tls.Config{
MinVersion: 0,

View File

@ -24,7 +24,6 @@ import (
"time"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -440,13 +439,10 @@ func TestPodLogDirectoryGC(t *testing.T) {
podStateProvider.removed["789"] = struct{}{}
podStateProvider.removed["654"] = struct{}{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()
fakeOS.ReadDirFn = func(string) ([]os.DirEntry, error) {
var dirEntries []os.DirEntry
for _, file := range files {
mockDE := containertest.NewMockDirEntry(ctrl)
mockDE := containertest.NewMockDirEntry(t)
mockDE.EXPECT().Name().Return(file)
dirEntries = append(dirEntries, mockDE)
}

View File

@ -23,7 +23,6 @@ import (
"testing"
"time"
"go.uber.org/mock/gomock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/component-base/metrics/testutil"
statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
@ -48,8 +47,6 @@ func TestCollectResourceMetrics(t *testing.T) {
"pod_memory_working_set_bytes",
"pod_swap_usage_bytes",
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
tests := []struct {
name string
@ -408,8 +405,8 @@ func TestCollectResourceMetrics(t *testing.T) {
tc := test
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
provider := summaryprovidertest.NewMockSummaryProvider(mockCtrl)
provider.EXPECT().GetCPUAndMemoryStats(ctx).Return(tc.summary, tc.summaryErr).AnyTimes()
provider := summaryprovidertest.NewMockSummaryProvider(t)
provider.EXPECT().GetCPUAndMemoryStats(ctx).Return(tc.summary, tc.summaryErr).Maybe()
collector := NewResourceMetricsCollector(provider)
if err := testutil.CustomCollectAndCompare(collector, strings.NewReader(tc.expectedMetrics), interestedMetrics...); err != nil {

View File

@ -21,7 +21,6 @@ import (
"strings"
"testing"
"go.uber.org/mock/gomock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/component-base/metrics/testutil"
statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
@ -142,12 +141,10 @@ func TestVolumeStatsCollector(t *testing.T) {
}
)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
mockStatsProvider.EXPECT().ListPodStats(ctx).Return(podStats, nil).AnyTimes()
mockStatsProvider.EXPECT().ListPodStatsAndUpdateCPUNanoCoreUsage(ctx).Return(podStats, nil).AnyTimes()
mockStatsProvider.EXPECT().ListPodStats(ctx).Return(podStats, nil).Maybe()
mockStatsProvider.EXPECT().ListPodStatsAndUpdateCPUNanoCoreUsage(ctx).Return(podStats, nil).Maybe()
if err := testutil.CustomCollectAndCompare(&volumeStatsCollector{statsProvider: mockStatsProvider}, strings.NewReader(want), metrics...); err != nil {
t.Errorf("unexpected collecting result:\n%s", err)
}
@ -230,12 +227,10 @@ func TestVolumeStatsCollectorWithNullVolumeStatus(t *testing.T) {
}
)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
mockStatsProvider.EXPECT().ListPodStats(ctx).Return(podStats, nil).AnyTimes()
mockStatsProvider.EXPECT().ListPodStatsAndUpdateCPUNanoCoreUsage(ctx).Return(podStats, nil).AnyTimes()
mockStatsProvider.EXPECT().ListPodStats(ctx).Return(podStats, nil).Maybe()
mockStatsProvider.EXPECT().ListPodStatsAndUpdateCPUNanoCoreUsage(ctx).Return(podStats, nil).Maybe()
if err := testutil.CustomCollectAndCompare(&volumeStatsCollector{statsProvider: mockStatsProvider}, strings.NewReader(want), metrics...); err != nil {
t.Errorf("unexpected collecting result:\n%s", err)
}

View File

@ -28,7 +28,6 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
"k8s.io/apimachinery/pkg/types"
"k8s.io/component-base/metrics/testutil"
@ -352,15 +351,13 @@ func createTestPodsStatusesAndEvents(num int) ([]*kubecontainer.Pod, []*kubecont
func TestRelistWithCache(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
runtimeMock := containertest.NewMockRuntime(mockCtrl)
runtimeMock := containertest.NewMockRuntime(t)
pleg := newTestGenericPLEGWithRuntimeMock(runtimeMock)
ch := pleg.Watch()
pods, statuses, events := createTestPodsStatusesAndEvents(2)
runtimeMock.EXPECT().GetPods(ctx, true).Return(pods, nil).AnyTimes()
runtimeMock.EXPECT().GetPods(ctx, true).Return(pods, nil).Maybe()
runtimeMock.EXPECT().GetPodStatus(ctx, pods[0].ID, "", "").Return(statuses[0], nil).Times(1)
// Inject an error when querying runtime for the pod status for pods[1].
statusErr := fmt.Errorf("unable to get status")
@ -409,9 +406,7 @@ func TestRelistWithCache(t *testing.T) {
func TestRemoveCacheEntry(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
runtimeMock := containertest.NewMockRuntime(mockCtrl)
runtimeMock := containertest.NewMockRuntime(t)
pleg := newTestGenericPLEGWithRuntimeMock(runtimeMock)
pods, statuses, _ := createTestPodsStatusesAndEvents(1)
@ -457,9 +452,7 @@ func TestHealthy(t *testing.T) {
func TestRelistWithReinspection(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
runtimeMock := containertest.NewMockRuntime(mockCtrl)
runtimeMock := containertest.NewMockRuntime(t)
pleg := newTestGenericPLEGWithRuntimeMock(runtimeMock)
ch := pleg.Watch()
@ -613,11 +606,8 @@ func TestRelistIPChange(t *testing.T) {
},
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
for _, tc := range testCases {
runtimeMock := containertest.NewMockRuntime(mockCtrl)
runtimeMock := containertest.NewMockRuntime(t)
pleg := newTestGenericPLEGWithRuntimeMock(runtimeMock)
ch := pleg.Watch()

View File

@ -0,0 +1,10 @@
---
dir: testing
filename: "mock_{{.InterfaceName | snakecase}}.go"
boilerplate-file: ../../../hack/boilerplate/boilerplate.generatego.txt
outpkg: testing
with-expecter: true
packages:
k8s.io/kubernetes/pkg/kubelet/pod:
interfaces:
Manager:

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate mockgen -source=pod_manager.go -destination=testing/mock_manager.go -package=testing Manager
//go:generate mockery
package pod
import (

View File

@ -14,243 +14,752 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: pod_manager.go
//
// Generated by this command:
//
// mockgen -source=pod_manager.go -destination=testing/mock_manager.go -package=testing Manager
//
// Code generated by mockery v2.40.3. DO NOT EDIT.
// Package testing is a generated GoMock package.
package testing
import (
reflect "reflect"
mock "github.com/stretchr/testify/mock"
kubelettypes "k8s.io/kubernetes/pkg/kubelet/types"
gomock "go.uber.org/mock/gomock"
v1 "k8s.io/api/core/v1"
types "k8s.io/apimachinery/pkg/types"
types0 "k8s.io/kubernetes/pkg/kubelet/types"
v1 "k8s.io/api/core/v1"
)
// MockManager is a mock of Manager interface.
// MockManager is an autogenerated mock type for the Manager type
type MockManager struct {
ctrl *gomock.Controller
recorder *MockManagerMockRecorder
mock.Mock
}
// MockManagerMockRecorder is the mock recorder for MockManager.
type MockManagerMockRecorder struct {
mock *MockManager
type MockManager_Expecter struct {
mock *mock.Mock
}
// NewMockManager creates a new mock instance.
func NewMockManager(ctrl *gomock.Controller) *MockManager {
mock := &MockManager{ctrl: ctrl}
mock.recorder = &MockManagerMockRecorder{mock}
func (_m *MockManager) EXPECT() *MockManager_Expecter {
return &MockManager_Expecter{mock: &_m.Mock}
}
// AddPod provides a mock function with given fields: _a0
func (_m *MockManager) AddPod(_a0 *v1.Pod) {
_m.Called(_a0)
}
// MockManager_AddPod_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddPod'
type MockManager_AddPod_Call struct {
*mock.Call
}
// AddPod is a helper method to define mock.On call
// - _a0 *v1.Pod
func (_e *MockManager_Expecter) AddPod(_a0 interface{}) *MockManager_AddPod_Call {
return &MockManager_AddPod_Call{Call: _e.mock.On("AddPod", _a0)}
}
func (_c *MockManager_AddPod_Call) Run(run func(_a0 *v1.Pod)) *MockManager_AddPod_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(*v1.Pod))
})
return _c
}
func (_c *MockManager_AddPod_Call) Return() *MockManager_AddPod_Call {
_c.Call.Return()
return _c
}
func (_c *MockManager_AddPod_Call) RunAndReturn(run func(*v1.Pod)) *MockManager_AddPod_Call {
_c.Call.Return(run)
return _c
}
// GetMirrorPodByPod provides a mock function with given fields: _a0
func (_m *MockManager) GetMirrorPodByPod(_a0 *v1.Pod) (*v1.Pod, bool) {
ret := _m.Called(_a0)
if len(ret) == 0 {
panic("no return value specified for GetMirrorPodByPod")
}
var r0 *v1.Pod
var r1 bool
if rf, ok := ret.Get(0).(func(*v1.Pod) (*v1.Pod, bool)); ok {
return rf(_a0)
}
if rf, ok := ret.Get(0).(func(*v1.Pod) *v1.Pod); ok {
r0 = rf(_a0)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Pod)
}
}
if rf, ok := ret.Get(1).(func(*v1.Pod) bool); ok {
r1 = rf(_a0)
} else {
r1 = ret.Get(1).(bool)
}
return r0, r1
}
// MockManager_GetMirrorPodByPod_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMirrorPodByPod'
type MockManager_GetMirrorPodByPod_Call struct {
*mock.Call
}
// GetMirrorPodByPod is a helper method to define mock.On call
// - _a0 *v1.Pod
func (_e *MockManager_Expecter) GetMirrorPodByPod(_a0 interface{}) *MockManager_GetMirrorPodByPod_Call {
return &MockManager_GetMirrorPodByPod_Call{Call: _e.mock.On("GetMirrorPodByPod", _a0)}
}
func (_c *MockManager_GetMirrorPodByPod_Call) Run(run func(_a0 *v1.Pod)) *MockManager_GetMirrorPodByPod_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(*v1.Pod))
})
return _c
}
func (_c *MockManager_GetMirrorPodByPod_Call) Return(_a0 *v1.Pod, _a1 bool) *MockManager_GetMirrorPodByPod_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockManager_GetMirrorPodByPod_Call) RunAndReturn(run func(*v1.Pod) (*v1.Pod, bool)) *MockManager_GetMirrorPodByPod_Call {
_c.Call.Return(run)
return _c
}
// GetPodAndMirrorPod provides a mock function with given fields: _a0
func (_m *MockManager) GetPodAndMirrorPod(_a0 *v1.Pod) (*v1.Pod, *v1.Pod, bool) {
ret := _m.Called(_a0)
if len(ret) == 0 {
panic("no return value specified for GetPodAndMirrorPod")
}
var r0 *v1.Pod
var r1 *v1.Pod
var r2 bool
if rf, ok := ret.Get(0).(func(*v1.Pod) (*v1.Pod, *v1.Pod, bool)); ok {
return rf(_a0)
}
if rf, ok := ret.Get(0).(func(*v1.Pod) *v1.Pod); ok {
r0 = rf(_a0)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Pod)
}
}
if rf, ok := ret.Get(1).(func(*v1.Pod) *v1.Pod); ok {
r1 = rf(_a0)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*v1.Pod)
}
}
if rf, ok := ret.Get(2).(func(*v1.Pod) bool); ok {
r2 = rf(_a0)
} else {
r2 = ret.Get(2).(bool)
}
return r0, r1, r2
}
// MockManager_GetPodAndMirrorPod_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodAndMirrorPod'
type MockManager_GetPodAndMirrorPod_Call struct {
*mock.Call
}
// GetPodAndMirrorPod is a helper method to define mock.On call
// - _a0 *v1.Pod
func (_e *MockManager_Expecter) GetPodAndMirrorPod(_a0 interface{}) *MockManager_GetPodAndMirrorPod_Call {
return &MockManager_GetPodAndMirrorPod_Call{Call: _e.mock.On("GetPodAndMirrorPod", _a0)}
}
func (_c *MockManager_GetPodAndMirrorPod_Call) Run(run func(_a0 *v1.Pod)) *MockManager_GetPodAndMirrorPod_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(*v1.Pod))
})
return _c
}
func (_c *MockManager_GetPodAndMirrorPod_Call) Return(_a0 *v1.Pod, mirrorPod *v1.Pod, wasMirror bool) *MockManager_GetPodAndMirrorPod_Call {
_c.Call.Return(_a0, mirrorPod, wasMirror)
return _c
}
func (_c *MockManager_GetPodAndMirrorPod_Call) RunAndReturn(run func(*v1.Pod) (*v1.Pod, *v1.Pod, bool)) *MockManager_GetPodAndMirrorPod_Call {
_c.Call.Return(run)
return _c
}
// GetPodByFullName provides a mock function with given fields: podFullName
func (_m *MockManager) GetPodByFullName(podFullName string) (*v1.Pod, bool) {
ret := _m.Called(podFullName)
if len(ret) == 0 {
panic("no return value specified for GetPodByFullName")
}
var r0 *v1.Pod
var r1 bool
if rf, ok := ret.Get(0).(func(string) (*v1.Pod, bool)); ok {
return rf(podFullName)
}
if rf, ok := ret.Get(0).(func(string) *v1.Pod); ok {
r0 = rf(podFullName)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Pod)
}
}
if rf, ok := ret.Get(1).(func(string) bool); ok {
r1 = rf(podFullName)
} else {
r1 = ret.Get(1).(bool)
}
return r0, r1
}
// MockManager_GetPodByFullName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodByFullName'
type MockManager_GetPodByFullName_Call struct {
*mock.Call
}
// GetPodByFullName is a helper method to define mock.On call
// - podFullName string
func (_e *MockManager_Expecter) GetPodByFullName(podFullName interface{}) *MockManager_GetPodByFullName_Call {
return &MockManager_GetPodByFullName_Call{Call: _e.mock.On("GetPodByFullName", podFullName)}
}
func (_c *MockManager_GetPodByFullName_Call) Run(run func(podFullName string)) *MockManager_GetPodByFullName_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(string))
})
return _c
}
func (_c *MockManager_GetPodByFullName_Call) Return(_a0 *v1.Pod, _a1 bool) *MockManager_GetPodByFullName_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockManager_GetPodByFullName_Call) RunAndReturn(run func(string) (*v1.Pod, bool)) *MockManager_GetPodByFullName_Call {
_c.Call.Return(run)
return _c
}
// GetPodByMirrorPod provides a mock function with given fields: _a0
func (_m *MockManager) GetPodByMirrorPod(_a0 *v1.Pod) (*v1.Pod, bool) {
ret := _m.Called(_a0)
if len(ret) == 0 {
panic("no return value specified for GetPodByMirrorPod")
}
var r0 *v1.Pod
var r1 bool
if rf, ok := ret.Get(0).(func(*v1.Pod) (*v1.Pod, bool)); ok {
return rf(_a0)
}
if rf, ok := ret.Get(0).(func(*v1.Pod) *v1.Pod); ok {
r0 = rf(_a0)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Pod)
}
}
if rf, ok := ret.Get(1).(func(*v1.Pod) bool); ok {
r1 = rf(_a0)
} else {
r1 = ret.Get(1).(bool)
}
return r0, r1
}
// MockManager_GetPodByMirrorPod_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodByMirrorPod'
type MockManager_GetPodByMirrorPod_Call struct {
*mock.Call
}
// GetPodByMirrorPod is a helper method to define mock.On call
// - _a0 *v1.Pod
func (_e *MockManager_Expecter) GetPodByMirrorPod(_a0 interface{}) *MockManager_GetPodByMirrorPod_Call {
return &MockManager_GetPodByMirrorPod_Call{Call: _e.mock.On("GetPodByMirrorPod", _a0)}
}
func (_c *MockManager_GetPodByMirrorPod_Call) Run(run func(_a0 *v1.Pod)) *MockManager_GetPodByMirrorPod_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(*v1.Pod))
})
return _c
}
func (_c *MockManager_GetPodByMirrorPod_Call) Return(_a0 *v1.Pod, _a1 bool) *MockManager_GetPodByMirrorPod_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockManager_GetPodByMirrorPod_Call) RunAndReturn(run func(*v1.Pod) (*v1.Pod, bool)) *MockManager_GetPodByMirrorPod_Call {
_c.Call.Return(run)
return _c
}
// GetPodByName provides a mock function with given fields: namespace, name
func (_m *MockManager) GetPodByName(namespace string, name string) (*v1.Pod, bool) {
ret := _m.Called(namespace, name)
if len(ret) == 0 {
panic("no return value specified for GetPodByName")
}
var r0 *v1.Pod
var r1 bool
if rf, ok := ret.Get(0).(func(string, string) (*v1.Pod, bool)); ok {
return rf(namespace, name)
}
if rf, ok := ret.Get(0).(func(string, string) *v1.Pod); ok {
r0 = rf(namespace, name)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Pod)
}
}
if rf, ok := ret.Get(1).(func(string, string) bool); ok {
r1 = rf(namespace, name)
} else {
r1 = ret.Get(1).(bool)
}
return r0, r1
}
// MockManager_GetPodByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodByName'
type MockManager_GetPodByName_Call struct {
*mock.Call
}
// GetPodByName is a helper method to define mock.On call
// - namespace string
// - name string
func (_e *MockManager_Expecter) GetPodByName(namespace interface{}, name interface{}) *MockManager_GetPodByName_Call {
return &MockManager_GetPodByName_Call{Call: _e.mock.On("GetPodByName", namespace, name)}
}
func (_c *MockManager_GetPodByName_Call) Run(run func(namespace string, name string)) *MockManager_GetPodByName_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(string), args[1].(string))
})
return _c
}
func (_c *MockManager_GetPodByName_Call) Return(_a0 *v1.Pod, _a1 bool) *MockManager_GetPodByName_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockManager_GetPodByName_Call) RunAndReturn(run func(string, string) (*v1.Pod, bool)) *MockManager_GetPodByName_Call {
_c.Call.Return(run)
return _c
}
// GetPodByUID provides a mock function with given fields: _a0
func (_m *MockManager) GetPodByUID(_a0 types.UID) (*v1.Pod, bool) {
ret := _m.Called(_a0)
if len(ret) == 0 {
panic("no return value specified for GetPodByUID")
}
var r0 *v1.Pod
var r1 bool
if rf, ok := ret.Get(0).(func(types.UID) (*v1.Pod, bool)); ok {
return rf(_a0)
}
if rf, ok := ret.Get(0).(func(types.UID) *v1.Pod); ok {
r0 = rf(_a0)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Pod)
}
}
if rf, ok := ret.Get(1).(func(types.UID) bool); ok {
r1 = rf(_a0)
} else {
r1 = ret.Get(1).(bool)
}
return r0, r1
}
// MockManager_GetPodByUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodByUID'
type MockManager_GetPodByUID_Call struct {
*mock.Call
}
// GetPodByUID is a helper method to define mock.On call
// - _a0 types.UID
func (_e *MockManager_Expecter) GetPodByUID(_a0 interface{}) *MockManager_GetPodByUID_Call {
return &MockManager_GetPodByUID_Call{Call: _e.mock.On("GetPodByUID", _a0)}
}
func (_c *MockManager_GetPodByUID_Call) Run(run func(_a0 types.UID)) *MockManager_GetPodByUID_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(types.UID))
})
return _c
}
func (_c *MockManager_GetPodByUID_Call) Return(_a0 *v1.Pod, _a1 bool) *MockManager_GetPodByUID_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockManager_GetPodByUID_Call) RunAndReturn(run func(types.UID) (*v1.Pod, bool)) *MockManager_GetPodByUID_Call {
_c.Call.Return(run)
return _c
}
// GetPods provides a mock function with given fields:
func (_m *MockManager) GetPods() []*v1.Pod {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for GetPods")
}
var r0 []*v1.Pod
if rf, ok := ret.Get(0).(func() []*v1.Pod); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*v1.Pod)
}
}
return r0
}
// MockManager_GetPods_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPods'
type MockManager_GetPods_Call struct {
*mock.Call
}
// GetPods is a helper method to define mock.On call
func (_e *MockManager_Expecter) GetPods() *MockManager_GetPods_Call {
return &MockManager_GetPods_Call{Call: _e.mock.On("GetPods")}
}
func (_c *MockManager_GetPods_Call) Run(run func()) *MockManager_GetPods_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockManager_GetPods_Call) Return(_a0 []*v1.Pod) *MockManager_GetPods_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockManager_GetPods_Call) RunAndReturn(run func() []*v1.Pod) *MockManager_GetPods_Call {
_c.Call.Return(run)
return _c
}
// GetPodsAndMirrorPods provides a mock function with given fields:
func (_m *MockManager) GetPodsAndMirrorPods() ([]*v1.Pod, []*v1.Pod, []string) {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for GetPodsAndMirrorPods")
}
var r0 []*v1.Pod
var r1 []*v1.Pod
var r2 []string
if rf, ok := ret.Get(0).(func() ([]*v1.Pod, []*v1.Pod, []string)); ok {
return rf()
}
if rf, ok := ret.Get(0).(func() []*v1.Pod); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*v1.Pod)
}
}
if rf, ok := ret.Get(1).(func() []*v1.Pod); ok {
r1 = rf()
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).([]*v1.Pod)
}
}
if rf, ok := ret.Get(2).(func() []string); ok {
r2 = rf()
} else {
if ret.Get(2) != nil {
r2 = ret.Get(2).([]string)
}
}
return r0, r1, r2
}
// MockManager_GetPodsAndMirrorPods_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodsAndMirrorPods'
type MockManager_GetPodsAndMirrorPods_Call struct {
*mock.Call
}
// GetPodsAndMirrorPods is a helper method to define mock.On call
func (_e *MockManager_Expecter) GetPodsAndMirrorPods() *MockManager_GetPodsAndMirrorPods_Call {
return &MockManager_GetPodsAndMirrorPods_Call{Call: _e.mock.On("GetPodsAndMirrorPods")}
}
func (_c *MockManager_GetPodsAndMirrorPods_Call) Run(run func()) *MockManager_GetPodsAndMirrorPods_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockManager_GetPodsAndMirrorPods_Call) Return(allPods []*v1.Pod, allMirrorPods []*v1.Pod, orphanedMirrorPodFullnames []string) *MockManager_GetPodsAndMirrorPods_Call {
_c.Call.Return(allPods, allMirrorPods, orphanedMirrorPodFullnames)
return _c
}
func (_c *MockManager_GetPodsAndMirrorPods_Call) RunAndReturn(run func() ([]*v1.Pod, []*v1.Pod, []string)) *MockManager_GetPodsAndMirrorPods_Call {
_c.Call.Return(run)
return _c
}
// GetUIDTranslations provides a mock function with given fields:
func (_m *MockManager) GetUIDTranslations() (map[kubelettypes.ResolvedPodUID]kubelettypes.MirrorPodUID, map[kubelettypes.MirrorPodUID]kubelettypes.ResolvedPodUID) {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for GetUIDTranslations")
}
var r0 map[kubelettypes.ResolvedPodUID]kubelettypes.MirrorPodUID
var r1 map[kubelettypes.MirrorPodUID]kubelettypes.ResolvedPodUID
if rf, ok := ret.Get(0).(func() (map[kubelettypes.ResolvedPodUID]kubelettypes.MirrorPodUID, map[kubelettypes.MirrorPodUID]kubelettypes.ResolvedPodUID)); ok {
return rf()
}
if rf, ok := ret.Get(0).(func() map[kubelettypes.ResolvedPodUID]kubelettypes.MirrorPodUID); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(map[kubelettypes.ResolvedPodUID]kubelettypes.MirrorPodUID)
}
}
if rf, ok := ret.Get(1).(func() map[kubelettypes.MirrorPodUID]kubelettypes.ResolvedPodUID); ok {
r1 = rf()
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(map[kubelettypes.MirrorPodUID]kubelettypes.ResolvedPodUID)
}
}
return r0, r1
}
// MockManager_GetUIDTranslations_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUIDTranslations'
type MockManager_GetUIDTranslations_Call struct {
*mock.Call
}
// GetUIDTranslations is a helper method to define mock.On call
func (_e *MockManager_Expecter) GetUIDTranslations() *MockManager_GetUIDTranslations_Call {
return &MockManager_GetUIDTranslations_Call{Call: _e.mock.On("GetUIDTranslations")}
}
func (_c *MockManager_GetUIDTranslations_Call) Run(run func()) *MockManager_GetUIDTranslations_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockManager_GetUIDTranslations_Call) Return(podToMirror map[kubelettypes.ResolvedPodUID]kubelettypes.MirrorPodUID, mirrorToPod map[kubelettypes.MirrorPodUID]kubelettypes.ResolvedPodUID) *MockManager_GetUIDTranslations_Call {
_c.Call.Return(podToMirror, mirrorToPod)
return _c
}
func (_c *MockManager_GetUIDTranslations_Call) RunAndReturn(run func() (map[kubelettypes.ResolvedPodUID]kubelettypes.MirrorPodUID, map[kubelettypes.MirrorPodUID]kubelettypes.ResolvedPodUID)) *MockManager_GetUIDTranslations_Call {
_c.Call.Return(run)
return _c
}
// RemovePod provides a mock function with given fields: _a0
func (_m *MockManager) RemovePod(_a0 *v1.Pod) {
_m.Called(_a0)
}
// MockManager_RemovePod_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemovePod'
type MockManager_RemovePod_Call struct {
*mock.Call
}
// RemovePod is a helper method to define mock.On call
// - _a0 *v1.Pod
func (_e *MockManager_Expecter) RemovePod(_a0 interface{}) *MockManager_RemovePod_Call {
return &MockManager_RemovePod_Call{Call: _e.mock.On("RemovePod", _a0)}
}
func (_c *MockManager_RemovePod_Call) Run(run func(_a0 *v1.Pod)) *MockManager_RemovePod_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(*v1.Pod))
})
return _c
}
func (_c *MockManager_RemovePod_Call) Return() *MockManager_RemovePod_Call {
_c.Call.Return()
return _c
}
func (_c *MockManager_RemovePod_Call) RunAndReturn(run func(*v1.Pod)) *MockManager_RemovePod_Call {
_c.Call.Return(run)
return _c
}
// SetPods provides a mock function with given fields: pods
func (_m *MockManager) SetPods(pods []*v1.Pod) {
_m.Called(pods)
}
// MockManager_SetPods_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetPods'
type MockManager_SetPods_Call struct {
*mock.Call
}
// SetPods is a helper method to define mock.On call
// - pods []*v1.Pod
func (_e *MockManager_Expecter) SetPods(pods interface{}) *MockManager_SetPods_Call {
return &MockManager_SetPods_Call{Call: _e.mock.On("SetPods", pods)}
}
func (_c *MockManager_SetPods_Call) Run(run func(pods []*v1.Pod)) *MockManager_SetPods_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].([]*v1.Pod))
})
return _c
}
func (_c *MockManager_SetPods_Call) Return() *MockManager_SetPods_Call {
_c.Call.Return()
return _c
}
func (_c *MockManager_SetPods_Call) RunAndReturn(run func([]*v1.Pod)) *MockManager_SetPods_Call {
_c.Call.Return(run)
return _c
}
// TranslatePodUID provides a mock function with given fields: uid
func (_m *MockManager) TranslatePodUID(uid types.UID) kubelettypes.ResolvedPodUID {
ret := _m.Called(uid)
if len(ret) == 0 {
panic("no return value specified for TranslatePodUID")
}
var r0 kubelettypes.ResolvedPodUID
if rf, ok := ret.Get(0).(func(types.UID) kubelettypes.ResolvedPodUID); ok {
r0 = rf(uid)
} else {
r0 = ret.Get(0).(kubelettypes.ResolvedPodUID)
}
return r0
}
// MockManager_TranslatePodUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TranslatePodUID'
type MockManager_TranslatePodUID_Call struct {
*mock.Call
}
// TranslatePodUID is a helper method to define mock.On call
// - uid types.UID
func (_e *MockManager_Expecter) TranslatePodUID(uid interface{}) *MockManager_TranslatePodUID_Call {
return &MockManager_TranslatePodUID_Call{Call: _e.mock.On("TranslatePodUID", uid)}
}
func (_c *MockManager_TranslatePodUID_Call) Run(run func(uid types.UID)) *MockManager_TranslatePodUID_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(types.UID))
})
return _c
}
func (_c *MockManager_TranslatePodUID_Call) Return(_a0 kubelettypes.ResolvedPodUID) *MockManager_TranslatePodUID_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockManager_TranslatePodUID_Call) RunAndReturn(run func(types.UID) kubelettypes.ResolvedPodUID) *MockManager_TranslatePodUID_Call {
_c.Call.Return(run)
return _c
}
// UpdatePod provides a mock function with given fields: _a0
func (_m *MockManager) UpdatePod(_a0 *v1.Pod) {
_m.Called(_a0)
}
// MockManager_UpdatePod_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdatePod'
type MockManager_UpdatePod_Call struct {
*mock.Call
}
// UpdatePod is a helper method to define mock.On call
// - _a0 *v1.Pod
func (_e *MockManager_Expecter) UpdatePod(_a0 interface{}) *MockManager_UpdatePod_Call {
return &MockManager_UpdatePod_Call{Call: _e.mock.On("UpdatePod", _a0)}
}
func (_c *MockManager_UpdatePod_Call) Run(run func(_a0 *v1.Pod)) *MockManager_UpdatePod_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(*v1.Pod))
})
return _c
}
func (_c *MockManager_UpdatePod_Call) Return() *MockManager_UpdatePod_Call {
_c.Call.Return()
return _c
}
func (_c *MockManager_UpdatePod_Call) RunAndReturn(run func(*v1.Pod)) *MockManager_UpdatePod_Call {
_c.Call.Return(run)
return _c
}
// NewMockManager creates a new instance of MockManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockManager(t interface {
mock.TestingT
Cleanup(func())
}) *MockManager {
mock := &MockManager{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockManager) EXPECT() *MockManagerMockRecorder {
return m.recorder
}
// AddPod mocks base method.
func (m *MockManager) AddPod(pod *v1.Pod) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "AddPod", pod)
}
// AddPod indicates an expected call of AddPod.
func (mr *MockManagerMockRecorder) AddPod(pod any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddPod", reflect.TypeOf((*MockManager)(nil).AddPod), pod)
}
// GetMirrorPodByPod mocks base method.
func (m *MockManager) GetMirrorPodByPod(arg0 *v1.Pod) (*v1.Pod, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetMirrorPodByPod", arg0)
ret0, _ := ret[0].(*v1.Pod)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetMirrorPodByPod indicates an expected call of GetMirrorPodByPod.
func (mr *MockManagerMockRecorder) GetMirrorPodByPod(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMirrorPodByPod", reflect.TypeOf((*MockManager)(nil).GetMirrorPodByPod), arg0)
}
// GetPodAndMirrorPod mocks base method.
func (m *MockManager) GetPodAndMirrorPod(arg0 *v1.Pod) (*v1.Pod, *v1.Pod, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPodAndMirrorPod", arg0)
ret0, _ := ret[0].(*v1.Pod)
ret1, _ := ret[1].(*v1.Pod)
ret2, _ := ret[2].(bool)
return ret0, ret1, ret2
}
// GetPodAndMirrorPod indicates an expected call of GetPodAndMirrorPod.
func (mr *MockManagerMockRecorder) GetPodAndMirrorPod(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodAndMirrorPod", reflect.TypeOf((*MockManager)(nil).GetPodAndMirrorPod), arg0)
}
// GetPodByFullName mocks base method.
func (m *MockManager) GetPodByFullName(podFullName string) (*v1.Pod, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPodByFullName", podFullName)
ret0, _ := ret[0].(*v1.Pod)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetPodByFullName indicates an expected call of GetPodByFullName.
func (mr *MockManagerMockRecorder) GetPodByFullName(podFullName any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodByFullName", reflect.TypeOf((*MockManager)(nil).GetPodByFullName), podFullName)
}
// GetPodByMirrorPod mocks base method.
func (m *MockManager) GetPodByMirrorPod(arg0 *v1.Pod) (*v1.Pod, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPodByMirrorPod", arg0)
ret0, _ := ret[0].(*v1.Pod)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetPodByMirrorPod indicates an expected call of GetPodByMirrorPod.
func (mr *MockManagerMockRecorder) GetPodByMirrorPod(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodByMirrorPod", reflect.TypeOf((*MockManager)(nil).GetPodByMirrorPod), arg0)
}
// GetPodByName mocks base method.
func (m *MockManager) GetPodByName(namespace, name string) (*v1.Pod, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPodByName", namespace, name)
ret0, _ := ret[0].(*v1.Pod)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetPodByName indicates an expected call of GetPodByName.
func (mr *MockManagerMockRecorder) GetPodByName(namespace, name any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodByName", reflect.TypeOf((*MockManager)(nil).GetPodByName), namespace, name)
}
// GetPodByUID mocks base method.
func (m *MockManager) GetPodByUID(arg0 types.UID) (*v1.Pod, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPodByUID", arg0)
ret0, _ := ret[0].(*v1.Pod)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetPodByUID indicates an expected call of GetPodByUID.
func (mr *MockManagerMockRecorder) GetPodByUID(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodByUID", reflect.TypeOf((*MockManager)(nil).GetPodByUID), arg0)
}
// GetPods mocks base method.
func (m *MockManager) GetPods() []*v1.Pod {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPods")
ret0, _ := ret[0].([]*v1.Pod)
return ret0
}
// GetPods indicates an expected call of GetPods.
func (mr *MockManagerMockRecorder) GetPods() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPods", reflect.TypeOf((*MockManager)(nil).GetPods))
}
// GetPodsAndMirrorPods mocks base method.
func (m *MockManager) GetPodsAndMirrorPods() ([]*v1.Pod, []*v1.Pod, []string) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPodsAndMirrorPods")
ret0, _ := ret[0].([]*v1.Pod)
ret1, _ := ret[1].([]*v1.Pod)
ret2, _ := ret[2].([]string)
return ret0, ret1, ret2
}
// GetPodsAndMirrorPods indicates an expected call of GetPodsAndMirrorPods.
func (mr *MockManagerMockRecorder) GetPodsAndMirrorPods() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodsAndMirrorPods", reflect.TypeOf((*MockManager)(nil).GetPodsAndMirrorPods))
}
// GetUIDTranslations mocks base method.
func (m *MockManager) GetUIDTranslations() (map[types0.ResolvedPodUID]types0.MirrorPodUID, map[types0.MirrorPodUID]types0.ResolvedPodUID) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetUIDTranslations")
ret0, _ := ret[0].(map[types0.ResolvedPodUID]types0.MirrorPodUID)
ret1, _ := ret[1].(map[types0.MirrorPodUID]types0.ResolvedPodUID)
return ret0, ret1
}
// GetUIDTranslations indicates an expected call of GetUIDTranslations.
func (mr *MockManagerMockRecorder) GetUIDTranslations() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUIDTranslations", reflect.TypeOf((*MockManager)(nil).GetUIDTranslations))
}
// RemovePod mocks base method.
func (m *MockManager) RemovePod(pod *v1.Pod) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RemovePod", pod)
}
// RemovePod indicates an expected call of RemovePod.
func (mr *MockManagerMockRecorder) RemovePod(pod any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemovePod", reflect.TypeOf((*MockManager)(nil).RemovePod), pod)
}
// SetPods mocks base method.
func (m *MockManager) SetPods(pods []*v1.Pod) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetPods", pods)
}
// SetPods indicates an expected call of SetPods.
func (mr *MockManagerMockRecorder) SetPods(pods any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPods", reflect.TypeOf((*MockManager)(nil).SetPods), pods)
}
// TranslatePodUID mocks base method.
func (m *MockManager) TranslatePodUID(uid types.UID) types0.ResolvedPodUID {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "TranslatePodUID", uid)
ret0, _ := ret[0].(types0.ResolvedPodUID)
return ret0
}
// TranslatePodUID indicates an expected call of TranslatePodUID.
func (mr *MockManagerMockRecorder) TranslatePodUID(uid any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TranslatePodUID", reflect.TypeOf((*MockManager)(nil).TranslatePodUID), uid)
}
// UpdatePod mocks base method.
func (m *MockManager) UpdatePod(pod *v1.Pod) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "UpdatePod", pod)
}
// UpdatePod indicates an expected call of UpdatePod.
func (mr *MockManagerMockRecorder) UpdatePod(pod any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdatePod", reflect.TypeOf((*MockManager)(nil).UpdatePod), pod)
}

View File

@ -25,7 +25,6 @@ import (
cadvisorapi "github.com/google/cadvisor/info/v1"
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
"go.uber.org/mock/gomock"
"k8s.io/mount-utils"
v1 "k8s.io/api/core/v1"
@ -57,20 +56,18 @@ import (
func TestRunOnce(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
cadvisor := cadvisortest.NewMockInterface(mockCtrl)
cadvisor.EXPECT().MachineInfo().Return(&cadvisorapi.MachineInfo{}, nil).AnyTimes()
cadvisor := cadvisortest.NewMockInterface(t)
cadvisor.EXPECT().MachineInfo().Return(&cadvisorapi.MachineInfo{}, nil).Maybe()
cadvisor.EXPECT().ImagesFsInfo().Return(cadvisorapiv2.FsInfo{
Usage: 400,
Capacity: 1000,
Available: 600,
}, nil).AnyTimes()
}, nil).Maybe()
cadvisor.EXPECT().RootFsInfo().Return(cadvisorapiv2.FsInfo{
Usage: 9,
Capacity: 10,
}, nil).AnyTimes()
}, nil).Maybe()
fakeSecretManager := secret.NewFakeManager()
fakeConfigMapManager := configmap.NewFakeManager()
clusterTrustBundleManager := &clustertrustbundle.NoopManager{}

View File

@ -0,0 +1,13 @@
---
dir: testing
filename: "mock_{{.InterfaceName | snakecase}}.go"
boilerplate-file: ../../../../hack/boilerplate/boilerplate.generatego.txt
outpkg: testing
with-expecter: true
packages:
k8s.io/kubernetes/pkg/kubelet/server/stats:
interfaces:
Provider:
config:
filename: mock_stats_provider.go
SummaryProvider:

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate mockgen -source=handler.go -destination=testing/mock_stats_provider.go -package=testing Provider
//go:generate mockery
package stats
import (

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate mockgen -source=summary.go -destination=testing/mock_summary_provider.go -package=testing SummaryProvider
//go:generate mockery
package stats
import (

View File

@ -26,7 +26,6 @@ import (
fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -72,14 +71,12 @@ func TestSummaryProviderGetStatsNoSplitFileSystem(t *testing.T) {
"/pods": {cs: getContainerStats(), ns: getNetworkStats()},
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
mockStatsProvider.EXPECT().GetNode().Return(node, nil)
mockStatsProvider.EXPECT().GetNodeConfig().Return(nodeConfig)
mockStatsProvider.EXPECT().GetPodCgroupRoot().Return(cgroupRoot)
mockStatsProvider.EXPECT().ListPodStats(ctx).Return(podStats, nil).AnyTimes()
mockStatsProvider.EXPECT().ListPodStats(ctx).Return(podStats, nil).Maybe()
mockStatsProvider.EXPECT().ListPodStatsAndUpdateCPUNanoCoreUsage(ctx).Return(podStats, nil)
mockStatsProvider.EXPECT().ImageFsStats(ctx).Return(imageFsStats, imageFsStats, nil)
mockStatsProvider.EXPECT().RootFsStats().Return(rootFsStats, nil)
@ -169,14 +166,12 @@ func TestSummaryProviderGetStatsSplitImageFs(t *testing.T) {
"/pods": {cs: getContainerStats(), ns: getNetworkStats()},
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
mockStatsProvider.EXPECT().GetNode().Return(node, nil)
mockStatsProvider.EXPECT().GetNodeConfig().Return(nodeConfig)
mockStatsProvider.EXPECT().GetPodCgroupRoot().Return(cgroupRoot)
mockStatsProvider.EXPECT().ListPodStats(ctx).Return(podStats, nil).AnyTimes()
mockStatsProvider.EXPECT().ListPodStats(ctx).Return(podStats, nil).Maybe()
mockStatsProvider.EXPECT().ListPodStatsAndUpdateCPUNanoCoreUsage(ctx).Return(podStats, nil)
mockStatsProvider.EXPECT().RootFsStats().Return(rootFsStats, nil)
mockStatsProvider.EXPECT().RlimitStats().Return(rlimitStats, nil)
@ -265,9 +260,7 @@ func TestSummaryProviderGetCPUAndMemoryStats(t *testing.T) {
"/pods": {cs: getVolumeCPUAndMemoryStats()},
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider := statstest.NewMockProvider(t)
mockStatsProvider.EXPECT().GetNode().Return(node, nil)
mockStatsProvider.EXPECT().GetNodeConfig().Return(nodeConfig)

View File

@ -26,7 +26,6 @@ import (
fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/assert"
gomock "go.uber.org/mock/gomock"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -55,19 +54,16 @@ func TestSummaryProvider(t *testing.T) {
assert := assert.New(t)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStatsProvider := statstest.NewMockProvider(mockCtrl)
mockStatsProvider.EXPECT().GetNode().Return(node, nil).AnyTimes()
mockStatsProvider.EXPECT().GetNodeConfig().Return(nodeConfig).AnyTimes()
mockStatsProvider.EXPECT().GetPodCgroupRoot().Return(cgroupRoot).AnyTimes()
mockStatsProvider.EXPECT().ListPodStats(ctx).Return(podStats, nil).AnyTimes()
mockStatsProvider.EXPECT().ListPodStatsAndUpdateCPUNanoCoreUsage(ctx).Return(podStats, nil).AnyTimes()
mockStatsProvider.EXPECT().ImageFsStats(ctx).Return(imageFsStats, imageFsStats, nil).AnyTimes()
mockStatsProvider.EXPECT().RootFsStats().Return(rootFsStats, nil).AnyTimes()
mockStatsProvider.EXPECT().RlimitStats().Return(nil, nil).AnyTimes()
mockStatsProvider.EXPECT().GetCgroupStats("/", true).Return(cgroupStatsMap["/"].cs, cgroupStatsMap["/"].ns, nil).AnyTimes()
mockStatsProvider := statstest.NewMockProvider(t)
mockStatsProvider.EXPECT().GetNode().Return(node, nil).Maybe()
mockStatsProvider.EXPECT().GetNodeConfig().Return(nodeConfig).Maybe()
mockStatsProvider.EXPECT().GetPodCgroupRoot().Return(cgroupRoot).Maybe()
mockStatsProvider.EXPECT().ListPodStats(ctx).Return(podStats, nil).Maybe()
mockStatsProvider.EXPECT().ListPodStatsAndUpdateCPUNanoCoreUsage(ctx).Return(podStats, nil).Maybe()
mockStatsProvider.EXPECT().ImageFsStats(ctx).Return(imageFsStats, imageFsStats, nil).Maybe()
mockStatsProvider.EXPECT().RootFsStats().Return(rootFsStats, nil).Maybe()
mockStatsProvider.EXPECT().RlimitStats().Return(nil, nil).Maybe()
mockStatsProvider.EXPECT().GetCgroupStats("/", true).Return(cgroupStatsMap["/"].cs, cgroupStatsMap["/"].ns, nil).Maybe()
kubeletCreationTime := metav1.Now()
systemBootTime := metav1.Now()

File diff suppressed because it is too large Load Diff

View File

@ -14,74 +14,158 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: summary.go
//
// Generated by this command:
//
// mockgen -source=summary.go -destination=testing/mock_summary_provider.go -package=testing SummaryProvider
//
// Code generated by mockery v2.40.3. DO NOT EDIT.
// Package testing is a generated GoMock package.
package testing
import (
context "context"
reflect "reflect"
gomock "go.uber.org/mock/gomock"
mock "github.com/stretchr/testify/mock"
v1alpha1 "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
)
// MockSummaryProvider is a mock of SummaryProvider interface.
// MockSummaryProvider is an autogenerated mock type for the SummaryProvider type
type MockSummaryProvider struct {
ctrl *gomock.Controller
recorder *MockSummaryProviderMockRecorder
mock.Mock
}
// MockSummaryProviderMockRecorder is the mock recorder for MockSummaryProvider.
type MockSummaryProviderMockRecorder struct {
mock *MockSummaryProvider
type MockSummaryProvider_Expecter struct {
mock *mock.Mock
}
// NewMockSummaryProvider creates a new mock instance.
func NewMockSummaryProvider(ctrl *gomock.Controller) *MockSummaryProvider {
mock := &MockSummaryProvider{ctrl: ctrl}
mock.recorder = &MockSummaryProviderMockRecorder{mock}
func (_m *MockSummaryProvider) EXPECT() *MockSummaryProvider_Expecter {
return &MockSummaryProvider_Expecter{mock: &_m.Mock}
}
// Get provides a mock function with given fields: ctx, updateStats
func (_m *MockSummaryProvider) Get(ctx context.Context, updateStats bool) (*v1alpha1.Summary, error) {
ret := _m.Called(ctx, updateStats)
if len(ret) == 0 {
panic("no return value specified for Get")
}
var r0 *v1alpha1.Summary
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, bool) (*v1alpha1.Summary, error)); ok {
return rf(ctx, updateStats)
}
if rf, ok := ret.Get(0).(func(context.Context, bool) *v1alpha1.Summary); ok {
r0 = rf(ctx, updateStats)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1alpha1.Summary)
}
}
if rf, ok := ret.Get(1).(func(context.Context, bool) error); ok {
r1 = rf(ctx, updateStats)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockSummaryProvider_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get'
type MockSummaryProvider_Get_Call struct {
*mock.Call
}
// Get is a helper method to define mock.On call
// - ctx context.Context
// - updateStats bool
func (_e *MockSummaryProvider_Expecter) Get(ctx interface{}, updateStats interface{}) *MockSummaryProvider_Get_Call {
return &MockSummaryProvider_Get_Call{Call: _e.mock.On("Get", ctx, updateStats)}
}
func (_c *MockSummaryProvider_Get_Call) Run(run func(ctx context.Context, updateStats bool)) *MockSummaryProvider_Get_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(bool))
})
return _c
}
func (_c *MockSummaryProvider_Get_Call) Return(_a0 *v1alpha1.Summary, _a1 error) *MockSummaryProvider_Get_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockSummaryProvider_Get_Call) RunAndReturn(run func(context.Context, bool) (*v1alpha1.Summary, error)) *MockSummaryProvider_Get_Call {
_c.Call.Return(run)
return _c
}
// GetCPUAndMemoryStats provides a mock function with given fields: ctx
func (_m *MockSummaryProvider) GetCPUAndMemoryStats(ctx context.Context) (*v1alpha1.Summary, error) {
ret := _m.Called(ctx)
if len(ret) == 0 {
panic("no return value specified for GetCPUAndMemoryStats")
}
var r0 *v1alpha1.Summary
var r1 error
if rf, ok := ret.Get(0).(func(context.Context) (*v1alpha1.Summary, error)); ok {
return rf(ctx)
}
if rf, ok := ret.Get(0).(func(context.Context) *v1alpha1.Summary); ok {
r0 = rf(ctx)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1alpha1.Summary)
}
}
if rf, ok := ret.Get(1).(func(context.Context) error); ok {
r1 = rf(ctx)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockSummaryProvider_GetCPUAndMemoryStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCPUAndMemoryStats'
type MockSummaryProvider_GetCPUAndMemoryStats_Call struct {
*mock.Call
}
// GetCPUAndMemoryStats is a helper method to define mock.On call
// - ctx context.Context
func (_e *MockSummaryProvider_Expecter) GetCPUAndMemoryStats(ctx interface{}) *MockSummaryProvider_GetCPUAndMemoryStats_Call {
return &MockSummaryProvider_GetCPUAndMemoryStats_Call{Call: _e.mock.On("GetCPUAndMemoryStats", ctx)}
}
func (_c *MockSummaryProvider_GetCPUAndMemoryStats_Call) Run(run func(ctx context.Context)) *MockSummaryProvider_GetCPUAndMemoryStats_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context))
})
return _c
}
func (_c *MockSummaryProvider_GetCPUAndMemoryStats_Call) Return(_a0 *v1alpha1.Summary, _a1 error) *MockSummaryProvider_GetCPUAndMemoryStats_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockSummaryProvider_GetCPUAndMemoryStats_Call) RunAndReturn(run func(context.Context) (*v1alpha1.Summary, error)) *MockSummaryProvider_GetCPUAndMemoryStats_Call {
_c.Call.Return(run)
return _c
}
// NewMockSummaryProvider creates a new instance of MockSummaryProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockSummaryProvider(t interface {
mock.TestingT
Cleanup(func())
}) *MockSummaryProvider {
mock := &MockSummaryProvider{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockSummaryProvider) EXPECT() *MockSummaryProviderMockRecorder {
return m.recorder
}
// Get mocks base method.
func (m *MockSummaryProvider) Get(ctx context.Context, updateStats bool) (*v1alpha1.Summary, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Get", ctx, updateStats)
ret0, _ := ret[0].(*v1alpha1.Summary)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Get indicates an expected call of Get.
func (mr *MockSummaryProviderMockRecorder) Get(ctx, updateStats any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockSummaryProvider)(nil).Get), ctx, updateStats)
}
// GetCPUAndMemoryStats mocks base method.
func (m *MockSummaryProvider) GetCPUAndMemoryStats(ctx context.Context) (*v1alpha1.Summary, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetCPUAndMemoryStats", ctx)
ret0, _ := ret[0].(*v1alpha1.Summary)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetCPUAndMemoryStats indicates an expected call of GetCPUAndMemoryStats.
func (mr *MockSummaryProviderMockRecorder) GetCPUAndMemoryStats(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCPUAndMemoryStats", reflect.TypeOf((*MockSummaryProvider)(nil).GetCPUAndMemoryStats), ctx)
}

View File

@ -23,7 +23,6 @@ import (
"time"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
csipbv1 "github.com/container-storage-interface/spec/lib/go/csi"
k8sv1 "k8s.io/api/core/v1"
@ -105,11 +104,8 @@ var (
)
func TestPVCRef(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
// Setup mock stats provider
mockStats := statstest.NewMockProvider(mockCtrl)
mockStats := statstest.NewMockProvider(t)
volumes := map[string]volume.Volume{vol0: &fakeVolume{}, vol1: &fakeVolume{}, vol3: &fakeVolume{}}
mockStats.EXPECT().ListVolumesForPod(fakePod.UID).Return(volumes, true)
blockVolumes := map[string]volume.BlockVolume{vol2: &fakeBlockVolume{}}
@ -165,9 +161,7 @@ func TestPVCRef(t *testing.T) {
}
func TestNormalVolumeEvent(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockStats := statstest.NewMockProvider(mockCtrl)
mockStats := statstest.NewMockProvider(t)
volumes := map[string]volume.Volume{vol0: &fakeVolume{}, vol1: &fakeVolume{}}
mockStats.EXPECT().ListVolumesForPod(fakePod.UID).Return(volumes, true)
@ -190,11 +184,9 @@ func TestNormalVolumeEvent(t *testing.T) {
func TestAbnormalVolumeEvent(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIVolumeHealth, true)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
// Setup mock stats provider
mockStats := statstest.NewMockProvider(mockCtrl)
mockStats := statstest.NewMockProvider(t)
volumes := map[string]volume.Volume{vol0: &fakeVolume{}}
mockStats.EXPECT().ListVolumesForPod(fakePod.UID).Return(volumes, true)
blockVolumes := map[string]volume.BlockVolume{vol1: &fakeBlockVolume{}}

View File

@ -23,7 +23,6 @@ import (
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -245,15 +244,12 @@ func TestCadvisorListPodStats(t *testing.T) {
Recursive: true,
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockCadvisor := cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor := cadvisortest.NewMockInterface(t)
mockCadvisor.EXPECT().ContainerInfoV2("/", options).Return(infos, nil)
mockCadvisor.EXPECT().RootFsInfo().Return(rootfs, nil)
mockCadvisor.EXPECT().ImagesFsInfo().Return(imagefs, nil)
mockRuntime := containertest.NewMockRuntime(mockCtrl)
mockRuntime := containertest.NewMockRuntime(t)
ephemeralVolumes := []statsapi.VolumeStats{getPodVolumeStats(seedEphemeralVolume1, "ephemeralVolume1"),
getPodVolumeStats(seedEphemeralVolume2, "ephemeralVolume2")}
@ -267,7 +263,7 @@ func TestCadvisorListPodStats(t *testing.T) {
p1Time := metav1.Now()
p2Time := metav1.Now()
p3Time := metav1.Now()
mockStatus := statustest.NewMockPodStatusProvider(mockCtrl)
mockStatus := statustest.NewMockPodStatusProvider(t)
mockStatus.EXPECT().GetPodStatus(types.UID("UID"+pName0)).Return(v1.PodStatus{StartTime: &p0Time}, true)
mockStatus.EXPECT().GetPodStatus(types.UID("UID"+pName1)).Return(v1.PodStatus{StartTime: &p1Time}, true)
mockStatus.EXPECT().GetPodStatus(types.UID("UID"+pName2)).Return(v1.PodStatus{StartTime: &p2Time}, true)
@ -434,10 +430,7 @@ func TestCadvisorListPodCPUAndMemoryStats(t *testing.T) {
Recursive: true,
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockCadvisor := cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor := cadvisortest.NewMockInterface(t)
mockCadvisor.EXPECT().ContainerInfoV2("/", options).Return(infos, nil)
ephemeralVolumes := []statsapi.VolumeStats{getPodVolumeStats(seedEphemeralVolume1, "ephemeralVolume1"),
@ -525,12 +518,10 @@ func TestCadvisorListPodCPUAndMemoryStats(t *testing.T) {
func TestCadvisorImagesFsStatsKubeletSeparateDiskOff(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
var (
assert = assert.New(t)
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
mockRuntime = containertest.NewMockRuntime(mockCtrl)
mockCadvisor = cadvisortest.NewMockInterface(t)
mockRuntime = containertest.NewMockRuntime(t)
seed = 1000
imageFsInfo = getTestFsInfo(seed)
@ -557,12 +548,10 @@ func TestCadvisorImagesFsStatsKubeletSeparateDiskOff(t *testing.T) {
func TestCadvisorImagesFsStats(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
var (
assert = assert.New(t)
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
mockRuntime = containertest.NewMockRuntime(mockCtrl)
mockCadvisor = cadvisortest.NewMockInterface(t)
mockRuntime = containertest.NewMockRuntime(t)
seed = 1000
imageFsInfo = getTestFsInfo(seed)
@ -605,12 +594,10 @@ func TestCadvisorImagesFsStats(t *testing.T) {
func TestCadvisorSplitImagesFsStats(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
var (
assert = assert.New(t)
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
mockRuntime = containertest.NewMockRuntime(mockCtrl)
mockCadvisor = cadvisortest.NewMockInterface(t)
mockRuntime = containertest.NewMockRuntime(t)
seed = 1000
imageFsInfo = getTestFsInfo(seed)
@ -736,20 +723,17 @@ func TestCadvisorListPodStatsWhenContainerLogFound(t *testing.T) {
Recursive: true,
}
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockCadvisor := cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor := cadvisortest.NewMockInterface(t)
mockCadvisor.EXPECT().ContainerInfoV2("/", options).Return(infos, nil)
mockCadvisor.EXPECT().RootFsInfo().Return(rootfs, nil)
mockCadvisor.EXPECT().ImagesFsInfo().Return(imagefs, nil)
mockRuntime := containertest.NewMockRuntime(mockCtrl)
mockRuntime.EXPECT().ImageStats(ctx).Return(&kubecontainer.ImageStats{TotalStorageBytes: 123}, nil).AnyTimes()
mockRuntime := containertest.NewMockRuntime(t)
mockRuntime.EXPECT().ImageStats(ctx).Return(&kubecontainer.ImageStats{TotalStorageBytes: 123}, nil).Maybe()
volumeStats := serverstats.PodVolumeStats{}
p0Time := metav1.Now()
mockStatus := statustest.NewMockPodStatusProvider(mockCtrl)
mockStatus := statustest.NewMockPodStatusProvider(t)
mockStatus.EXPECT().GetPodStatus(types.UID("UID"+pName0)).Return(v1.PodStatus{StartTime: &p0Time}, true)
resourceAnalyzer := &fakeResourceAnalyzer{podVolumeStats: volumeStats}

View File

@ -29,7 +29,6 @@ import (
cadvisorfs "github.com/google/cadvisor/fs"
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
"github.com/stretchr/testify/assert"
gomock "go.uber.org/mock/gomock"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@ -148,11 +147,8 @@ func TestCRIListPodStats(t *testing.T) {
podLogStats1 = makeFakeLogStats(6000)
)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
var (
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor = cadvisortest.NewMockInterface(t)
mockRuntimeCache = new(kubecontainertest.MockRuntimeCache)
mockPodManager = new(kubepodtest.MockManager)
resourceAnalyzer = new(fakeResourceAnalyzer)
@ -216,13 +212,10 @@ func TestCRIListPodStats(t *testing.T) {
filepath.Join(kuberuntime.BuildPodLogsDirectory(testPodLogDirectory, "sandbox1-ns", "sandbox1-name", types.UID("sandbox1-uid")), podLogName1): podLogStats1,
}
ctrl := gomock.NewController(t)
defer ctrl.Finish()
fakeOS := &kubecontainertest.FakeOS{}
fakeOS.ReadDirFn = func(path string) ([]os.DirEntry, error) {
var dirEntries []os.DirEntry
mockDE := kubecontainertest.NewMockDirEntry(ctrl)
mockDE := kubecontainertest.NewMockDirEntry(t)
switch path {
case kuberuntime.BuildPodLogsDirectory(testPodLogDirectory, "sandbox0-ns", "sandbox0-name", types.UID("sandbox0-uid")):
mockDE.EXPECT().Name().Return(podLogName0)
@ -373,10 +366,8 @@ func TestListPodStatsStrictlyFromCRI(t *testing.T) {
podLogStats0 = makeFakeLogStats(5000)
podLogStats1 = makeFakeLogStats(6000)
)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
var (
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor = cadvisortest.NewMockInterface(t)
mockRuntimeCache = new(kubecontainertest.MockRuntimeCache)
mockPodManager = new(kubepodtest.MockManager)
resourceAnalyzer = new(fakeResourceAnalyzer)
@ -443,12 +434,10 @@ func TestListPodStatsStrictlyFromCRI(t *testing.T) {
filepath.Join(kuberuntime.BuildPodLogsDirectory(testPodLogDirectory, "sandbox0-ns", "sandbox0-name", types.UID("sandbox0-uid")), podLogName0): podLogStats0,
filepath.Join(kuberuntime.BuildPodLogsDirectory(testPodLogDirectory, "sandbox1-ns", "sandbox1-name", types.UID("sandbox1-uid")), podLogName1): podLogStats1,
}
ctrl := gomock.NewController(t)
defer ctrl.Finish()
fakeOS := &kubecontainertest.FakeOS{}
fakeOS.ReadDirFn = func(path string) ([]os.DirEntry, error) {
var dirEntries []os.DirEntry
mockDE := kubecontainertest.NewMockDirEntry(ctrl)
mockDE := kubecontainertest.NewMockDirEntry(t)
switch path {
case kuberuntime.BuildPodLogsDirectory(testPodLogDirectory, "sandbox0-ns", "sandbox0-name", types.UID("sandbox0-uid")):
mockDE.EXPECT().Name().Return(podLogName0)
@ -584,11 +573,8 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
containerStats9 = makeFakeContainerStats(container9, imageFsMountpoint)
)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
var (
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor = cadvisortest.NewMockInterface(t)
mockRuntimeCache = new(kubecontainertest.MockRuntimeCache)
mockPodManager = new(kubepodtest.MockManager)
resourceAnalyzer = new(fakeResourceAnalyzer)
@ -752,11 +738,8 @@ func TestCRIImagesFsStats(t *testing.T) {
imageFsUsage = makeFakeImageFsUsage(imageFsMountpoint)
)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
var (
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor = cadvisortest.NewMockInterface(t)
mockRuntimeCache = new(kubecontainertest.MockRuntimeCache)
mockPodManager = new(kubepodtest.MockManager)
resourceAnalyzer = new(fakeResourceAnalyzer)

View File

@ -27,7 +27,6 @@ import (
fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@ -76,11 +75,8 @@ func TestGetCgroupStats(t *testing.T) {
updateStats = false
)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
var (
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor = cadvisortest.NewMockInterface(t)
mockPodManager = new(kubepodtest.MockManager)
mockRuntimeCache = new(kubecontainertest.MockRuntimeCache)
@ -113,11 +109,8 @@ func TestGetCgroupCPUAndMemoryStats(t *testing.T) {
updateStats = false
)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
var (
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor = cadvisortest.NewMockInterface(t)
mockPodManager = new(kubepodtest.MockManager)
mockRuntimeCache = new(kubecontainertest.MockRuntimeCache)
@ -147,11 +140,8 @@ func TestRootFsStats(t *testing.T) {
containerInfoSeed = 2000
)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
var (
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor = cadvisortest.NewMockInterface(t)
mockPodManager = new(kubepodtest.MockManager)
mockRuntimeCache = new(kubecontainertest.MockRuntimeCache)
@ -179,8 +169,6 @@ func TestRootFsStats(t *testing.T) {
func TestHasDedicatedImageFs(t *testing.T) {
ctx := context.Background()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
imageStatsExpected := &statsapi.FsStats{AvailableBytes: uint64Ptr(1)}
for desc, test := range map[string]struct {
@ -213,7 +201,7 @@ func TestHasDedicatedImageFs(t *testing.T) {
} {
t.Logf("TestCase %q", desc)
var (
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
mockCadvisor = cadvisortest.NewMockInterface(t)
mockPodManager = new(kubepodtest.MockManager)
mockRuntimeCache = new(kubecontainertest.MockRuntimeCache)
)

View File

@ -0,0 +1,10 @@
---
dir: testing
filename: "mock_{{.InterfaceName | snakecase}}.go"
boilerplate-file: ../../../hack/boilerplate/boilerplate.generatego.txt
outpkg: testing
with-expecter: true
packages:
k8s.io/kubernetes/pkg/kubelet/status:
interfaces:
PodStatusProvider:

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate mockgen -source=status_manager.go -destination=testing/mock_pod_status_provider.go -package=testing PodStatusProvider
//go:generate mockery
package status
import (

View File

@ -14,395 +14,97 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: status_manager.go
//
// Generated by this command:
//
// mockgen -source=status_manager.go -destination=testing/mock_pod_status_provider.go -package=testing PodStatusProvider
//
// Code generated by mockery v2.40.3. DO NOT EDIT.
// Package testing is a generated GoMock package.
package testing
import (
reflect "reflect"
mock "github.com/stretchr/testify/mock"
gomock "go.uber.org/mock/gomock"
v1 "k8s.io/api/core/v1"
types "k8s.io/apimachinery/pkg/types"
container "k8s.io/kubernetes/pkg/kubelet/container"
types0 "k8s.io/kubernetes/pkg/kubelet/types"
v1 "k8s.io/api/core/v1"
)
// MockPodManager is a mock of PodManager interface.
type MockPodManager struct {
ctrl *gomock.Controller
recorder *MockPodManagerMockRecorder
}
// MockPodManagerMockRecorder is the mock recorder for MockPodManager.
type MockPodManagerMockRecorder struct {
mock *MockPodManager
}
// NewMockPodManager creates a new mock instance.
func NewMockPodManager(ctrl *gomock.Controller) *MockPodManager {
mock := &MockPodManager{ctrl: ctrl}
mock.recorder = &MockPodManagerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockPodManager) EXPECT() *MockPodManagerMockRecorder {
return m.recorder
}
// GetMirrorPodByPod mocks base method.
func (m *MockPodManager) GetMirrorPodByPod(arg0 *v1.Pod) (*v1.Pod, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetMirrorPodByPod", arg0)
ret0, _ := ret[0].(*v1.Pod)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetMirrorPodByPod indicates an expected call of GetMirrorPodByPod.
func (mr *MockPodManagerMockRecorder) GetMirrorPodByPod(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMirrorPodByPod", reflect.TypeOf((*MockPodManager)(nil).GetMirrorPodByPod), arg0)
}
// GetPodByUID mocks base method.
func (m *MockPodManager) GetPodByUID(arg0 types.UID) (*v1.Pod, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPodByUID", arg0)
ret0, _ := ret[0].(*v1.Pod)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetPodByUID indicates an expected call of GetPodByUID.
func (mr *MockPodManagerMockRecorder) GetPodByUID(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodByUID", reflect.TypeOf((*MockPodManager)(nil).GetPodByUID), arg0)
}
// GetUIDTranslations mocks base method.
func (m *MockPodManager) GetUIDTranslations() (map[types0.ResolvedPodUID]types0.MirrorPodUID, map[types0.MirrorPodUID]types0.ResolvedPodUID) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetUIDTranslations")
ret0, _ := ret[0].(map[types0.ResolvedPodUID]types0.MirrorPodUID)
ret1, _ := ret[1].(map[types0.MirrorPodUID]types0.ResolvedPodUID)
return ret0, ret1
}
// GetUIDTranslations indicates an expected call of GetUIDTranslations.
func (mr *MockPodManagerMockRecorder) GetUIDTranslations() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUIDTranslations", reflect.TypeOf((*MockPodManager)(nil).GetUIDTranslations))
}
// TranslatePodUID mocks base method.
func (m *MockPodManager) TranslatePodUID(uid types.UID) types0.ResolvedPodUID {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "TranslatePodUID", uid)
ret0, _ := ret[0].(types0.ResolvedPodUID)
return ret0
}
// TranslatePodUID indicates an expected call of TranslatePodUID.
func (mr *MockPodManagerMockRecorder) TranslatePodUID(uid any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TranslatePodUID", reflect.TypeOf((*MockPodManager)(nil).TranslatePodUID), uid)
}
// MockPodStatusProvider is a mock of PodStatusProvider interface.
// MockPodStatusProvider is an autogenerated mock type for the PodStatusProvider type
type MockPodStatusProvider struct {
ctrl *gomock.Controller
recorder *MockPodStatusProviderMockRecorder
mock.Mock
}
// MockPodStatusProviderMockRecorder is the mock recorder for MockPodStatusProvider.
type MockPodStatusProviderMockRecorder struct {
mock *MockPodStatusProvider
type MockPodStatusProvider_Expecter struct {
mock *mock.Mock
}
// NewMockPodStatusProvider creates a new mock instance.
func NewMockPodStatusProvider(ctrl *gomock.Controller) *MockPodStatusProvider {
mock := &MockPodStatusProvider{ctrl: ctrl}
mock.recorder = &MockPodStatusProviderMockRecorder{mock}
func (_m *MockPodStatusProvider) EXPECT() *MockPodStatusProvider_Expecter {
return &MockPodStatusProvider_Expecter{mock: &_m.Mock}
}
// GetPodStatus provides a mock function with given fields: uid
func (_m *MockPodStatusProvider) GetPodStatus(uid types.UID) (v1.PodStatus, bool) {
ret := _m.Called(uid)
if len(ret) == 0 {
panic("no return value specified for GetPodStatus")
}
var r0 v1.PodStatus
var r1 bool
if rf, ok := ret.Get(0).(func(types.UID) (v1.PodStatus, bool)); ok {
return rf(uid)
}
if rf, ok := ret.Get(0).(func(types.UID) v1.PodStatus); ok {
r0 = rf(uid)
} else {
r0 = ret.Get(0).(v1.PodStatus)
}
if rf, ok := ret.Get(1).(func(types.UID) bool); ok {
r1 = rf(uid)
} else {
r1 = ret.Get(1).(bool)
}
return r0, r1
}
// MockPodStatusProvider_GetPodStatus_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodStatus'
type MockPodStatusProvider_GetPodStatus_Call struct {
*mock.Call
}
// GetPodStatus is a helper method to define mock.On call
// - uid types.UID
func (_e *MockPodStatusProvider_Expecter) GetPodStatus(uid interface{}) *MockPodStatusProvider_GetPodStatus_Call {
return &MockPodStatusProvider_GetPodStatus_Call{Call: _e.mock.On("GetPodStatus", uid)}
}
func (_c *MockPodStatusProvider_GetPodStatus_Call) Run(run func(uid types.UID)) *MockPodStatusProvider_GetPodStatus_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(types.UID))
})
return _c
}
func (_c *MockPodStatusProvider_GetPodStatus_Call) Return(_a0 v1.PodStatus, _a1 bool) *MockPodStatusProvider_GetPodStatus_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockPodStatusProvider_GetPodStatus_Call) RunAndReturn(run func(types.UID) (v1.PodStatus, bool)) *MockPodStatusProvider_GetPodStatus_Call {
_c.Call.Return(run)
return _c
}
// NewMockPodStatusProvider creates a new instance of MockPodStatusProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockPodStatusProvider(t interface {
mock.TestingT
Cleanup(func())
}) *MockPodStatusProvider {
mock := &MockPodStatusProvider{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockPodStatusProvider) EXPECT() *MockPodStatusProviderMockRecorder {
return m.recorder
}
// GetPodStatus mocks base method.
func (m *MockPodStatusProvider) GetPodStatus(uid types.UID) (v1.PodStatus, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPodStatus", uid)
ret0, _ := ret[0].(v1.PodStatus)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetPodStatus indicates an expected call of GetPodStatus.
func (mr *MockPodStatusProviderMockRecorder) GetPodStatus(uid any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodStatus", reflect.TypeOf((*MockPodStatusProvider)(nil).GetPodStatus), uid)
}
// MockPodDeletionSafetyProvider is a mock of PodDeletionSafetyProvider interface.
type MockPodDeletionSafetyProvider struct {
ctrl *gomock.Controller
recorder *MockPodDeletionSafetyProviderMockRecorder
}
// MockPodDeletionSafetyProviderMockRecorder is the mock recorder for MockPodDeletionSafetyProvider.
type MockPodDeletionSafetyProviderMockRecorder struct {
mock *MockPodDeletionSafetyProvider
}
// NewMockPodDeletionSafetyProvider creates a new mock instance.
func NewMockPodDeletionSafetyProvider(ctrl *gomock.Controller) *MockPodDeletionSafetyProvider {
mock := &MockPodDeletionSafetyProvider{ctrl: ctrl}
mock.recorder = &MockPodDeletionSafetyProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockPodDeletionSafetyProvider) EXPECT() *MockPodDeletionSafetyProviderMockRecorder {
return m.recorder
}
// PodCouldHaveRunningContainers mocks base method.
func (m *MockPodDeletionSafetyProvider) PodCouldHaveRunningContainers(pod *v1.Pod) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "PodCouldHaveRunningContainers", pod)
ret0, _ := ret[0].(bool)
return ret0
}
// PodCouldHaveRunningContainers indicates an expected call of PodCouldHaveRunningContainers.
func (mr *MockPodDeletionSafetyProviderMockRecorder) PodCouldHaveRunningContainers(pod any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PodCouldHaveRunningContainers", reflect.TypeOf((*MockPodDeletionSafetyProvider)(nil).PodCouldHaveRunningContainers), pod)
}
// MockPodStartupLatencyStateHelper is a mock of PodStartupLatencyStateHelper interface.
type MockPodStartupLatencyStateHelper struct {
ctrl *gomock.Controller
recorder *MockPodStartupLatencyStateHelperMockRecorder
}
// MockPodStartupLatencyStateHelperMockRecorder is the mock recorder for MockPodStartupLatencyStateHelper.
type MockPodStartupLatencyStateHelperMockRecorder struct {
mock *MockPodStartupLatencyStateHelper
}
// NewMockPodStartupLatencyStateHelper creates a new mock instance.
func NewMockPodStartupLatencyStateHelper(ctrl *gomock.Controller) *MockPodStartupLatencyStateHelper {
mock := &MockPodStartupLatencyStateHelper{ctrl: ctrl}
mock.recorder = &MockPodStartupLatencyStateHelperMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockPodStartupLatencyStateHelper) EXPECT() *MockPodStartupLatencyStateHelperMockRecorder {
return m.recorder
}
// DeletePodStartupState mocks base method.
func (m *MockPodStartupLatencyStateHelper) DeletePodStartupState(podUID types.UID) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "DeletePodStartupState", podUID)
}
// DeletePodStartupState indicates an expected call of DeletePodStartupState.
func (mr *MockPodStartupLatencyStateHelperMockRecorder) DeletePodStartupState(podUID any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeletePodStartupState", reflect.TypeOf((*MockPodStartupLatencyStateHelper)(nil).DeletePodStartupState), podUID)
}
// RecordStatusUpdated mocks base method.
func (m *MockPodStartupLatencyStateHelper) RecordStatusUpdated(pod *v1.Pod) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RecordStatusUpdated", pod)
}
// RecordStatusUpdated indicates an expected call of RecordStatusUpdated.
func (mr *MockPodStartupLatencyStateHelperMockRecorder) RecordStatusUpdated(pod any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordStatusUpdated", reflect.TypeOf((*MockPodStartupLatencyStateHelper)(nil).RecordStatusUpdated), pod)
}
// MockManager is a mock of Manager interface.
type MockManager struct {
ctrl *gomock.Controller
recorder *MockManagerMockRecorder
}
// MockManagerMockRecorder is the mock recorder for MockManager.
type MockManagerMockRecorder struct {
mock *MockManager
}
// NewMockManager creates a new mock instance.
func NewMockManager(ctrl *gomock.Controller) *MockManager {
mock := &MockManager{ctrl: ctrl}
mock.recorder = &MockManagerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockManager) EXPECT() *MockManagerMockRecorder {
return m.recorder
}
// GetContainerResourceAllocation mocks base method.
func (m *MockManager) GetContainerResourceAllocation(podUID, containerName string) (v1.ResourceList, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetContainerResourceAllocation", podUID, containerName)
ret0, _ := ret[0].(v1.ResourceList)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetContainerResourceAllocation indicates an expected call of GetContainerResourceAllocation.
func (mr *MockManagerMockRecorder) GetContainerResourceAllocation(podUID, containerName any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetContainerResourceAllocation", reflect.TypeOf((*MockManager)(nil).GetContainerResourceAllocation), podUID, containerName)
}
// GetPodResizeStatus mocks base method.
func (m *MockManager) GetPodResizeStatus(podUID string) (v1.PodResizeStatus, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPodResizeStatus", podUID)
ret0, _ := ret[0].(v1.PodResizeStatus)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetPodResizeStatus indicates an expected call of GetPodResizeStatus.
func (mr *MockManagerMockRecorder) GetPodResizeStatus(podUID any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodResizeStatus", reflect.TypeOf((*MockManager)(nil).GetPodResizeStatus), podUID)
}
// GetPodStatus mocks base method.
func (m *MockManager) GetPodStatus(uid types.UID) (v1.PodStatus, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPodStatus", uid)
ret0, _ := ret[0].(v1.PodStatus)
ret1, _ := ret[1].(bool)
return ret0, ret1
}
// GetPodStatus indicates an expected call of GetPodStatus.
func (mr *MockManagerMockRecorder) GetPodStatus(uid any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodStatus", reflect.TypeOf((*MockManager)(nil).GetPodStatus), uid)
}
// RemoveOrphanedStatuses mocks base method.
func (m *MockManager) RemoveOrphanedStatuses(podUIDs map[types.UID]bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RemoveOrphanedStatuses", podUIDs)
}
// RemoveOrphanedStatuses indicates an expected call of RemoveOrphanedStatuses.
func (mr *MockManagerMockRecorder) RemoveOrphanedStatuses(podUIDs any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveOrphanedStatuses", reflect.TypeOf((*MockManager)(nil).RemoveOrphanedStatuses), podUIDs)
}
// SetContainerReadiness mocks base method.
func (m *MockManager) SetContainerReadiness(podUID types.UID, containerID container.ContainerID, ready bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetContainerReadiness", podUID, containerID, ready)
}
// SetContainerReadiness indicates an expected call of SetContainerReadiness.
func (mr *MockManagerMockRecorder) SetContainerReadiness(podUID, containerID, ready any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetContainerReadiness", reflect.TypeOf((*MockManager)(nil).SetContainerReadiness), podUID, containerID, ready)
}
// SetContainerStartup mocks base method.
func (m *MockManager) SetContainerStartup(podUID types.UID, containerID container.ContainerID, started bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetContainerStartup", podUID, containerID, started)
}
// SetContainerStartup indicates an expected call of SetContainerStartup.
func (mr *MockManagerMockRecorder) SetContainerStartup(podUID, containerID, started any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetContainerStartup", reflect.TypeOf((*MockManager)(nil).SetContainerStartup), podUID, containerID, started)
}
// SetPodAllocation mocks base method.
func (m *MockManager) SetPodAllocation(pod *v1.Pod) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetPodAllocation", pod)
ret0, _ := ret[0].(error)
return ret0
}
// SetPodAllocation indicates an expected call of SetPodAllocation.
func (mr *MockManagerMockRecorder) SetPodAllocation(pod any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPodAllocation", reflect.TypeOf((*MockManager)(nil).SetPodAllocation), pod)
}
// SetPodResizeStatus mocks base method.
func (m *MockManager) SetPodResizeStatus(podUID types.UID, resize v1.PodResizeStatus) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetPodResizeStatus", podUID, resize)
ret0, _ := ret[0].(error)
return ret0
}
// SetPodResizeStatus indicates an expected call of SetPodResizeStatus.
func (mr *MockManagerMockRecorder) SetPodResizeStatus(podUID, resize any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPodResizeStatus", reflect.TypeOf((*MockManager)(nil).SetPodResizeStatus), podUID, resize)
}
// SetPodStatus mocks base method.
func (m *MockManager) SetPodStatus(pod *v1.Pod, status v1.PodStatus) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetPodStatus", pod, status)
}
// SetPodStatus indicates an expected call of SetPodStatus.
func (mr *MockManagerMockRecorder) SetPodStatus(pod, status any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPodStatus", reflect.TypeOf((*MockManager)(nil).SetPodStatus), pod, status)
}
// Start mocks base method.
func (m *MockManager) Start() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Start")
}
// Start indicates an expected call of Start.
func (mr *MockManagerMockRecorder) Start() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockManager)(nil).Start))
}
// TerminatePod mocks base method.
func (m *MockManager) TerminatePod(pod *v1.Pod) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "TerminatePod", pod)
}
// TerminatePod indicates an expected call of TerminatePod.
func (mr *MockManagerMockRecorder) TerminatePod(pod any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TerminatePod", reflect.TypeOf((*MockManager)(nil).TerminatePod), pod)
}

View File

@ -0,0 +1,12 @@
---
dir: .
filename: mock_{{.InterfaceName | snakecase}}.go
outpkg: driver
boilerplate-file: ../../../../../../hack/boilerplate/boilerplate.generatego.txt
with-expecter: True
packages:
github.com/container-storage-interface/spec/lib/go/csi:
interfaces:
ControllerServer:
IdentityServer:
NodeServer:

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate mockgen -package=driver -destination=driver.mock.go -build_flags=-mod=readonly github.com/container-storage-interface/spec/lib/go/csi IdentityServer,ControllerServer,NodeServer
//go:generate mockery
package driver

View File

@ -1,478 +0,0 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/container-storage-interface/spec/lib/go/csi (interfaces: IdentityServer,ControllerServer,NodeServer)
//
// Generated by this command:
//
// mockgen -package=driver -destination=driver.mock.go -build_flags=-mod=readonly github.com/container-storage-interface/spec/lib/go/csi IdentityServer,ControllerServer,NodeServer
//
// Package driver is a generated GoMock package.
package driver
import (
context "context"
reflect "reflect"
csi "github.com/container-storage-interface/spec/lib/go/csi"
gomock "go.uber.org/mock/gomock"
)
// MockIdentityServer is a mock of IdentityServer interface.
type MockIdentityServer struct {
ctrl *gomock.Controller
recorder *MockIdentityServerMockRecorder
}
// MockIdentityServerMockRecorder is the mock recorder for MockIdentityServer.
type MockIdentityServerMockRecorder struct {
mock *MockIdentityServer
}
// NewMockIdentityServer creates a new mock instance.
func NewMockIdentityServer(ctrl *gomock.Controller) *MockIdentityServer {
mock := &MockIdentityServer{ctrl: ctrl}
mock.recorder = &MockIdentityServerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockIdentityServer) EXPECT() *MockIdentityServerMockRecorder {
return m.recorder
}
// GetPluginCapabilities mocks base method.
func (m *MockIdentityServer) GetPluginCapabilities(arg0 context.Context, arg1 *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPluginCapabilities", arg0, arg1)
ret0, _ := ret[0].(*csi.GetPluginCapabilitiesResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetPluginCapabilities indicates an expected call of GetPluginCapabilities.
func (mr *MockIdentityServerMockRecorder) GetPluginCapabilities(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPluginCapabilities", reflect.TypeOf((*MockIdentityServer)(nil).GetPluginCapabilities), arg0, arg1)
}
// GetPluginInfo mocks base method.
func (m *MockIdentityServer) GetPluginInfo(arg0 context.Context, arg1 *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPluginInfo", arg0, arg1)
ret0, _ := ret[0].(*csi.GetPluginInfoResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetPluginInfo indicates an expected call of GetPluginInfo.
func (mr *MockIdentityServerMockRecorder) GetPluginInfo(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPluginInfo", reflect.TypeOf((*MockIdentityServer)(nil).GetPluginInfo), arg0, arg1)
}
// Probe mocks base method.
func (m *MockIdentityServer) Probe(arg0 context.Context, arg1 *csi.ProbeRequest) (*csi.ProbeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Probe", arg0, arg1)
ret0, _ := ret[0].(*csi.ProbeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Probe indicates an expected call of Probe.
func (mr *MockIdentityServerMockRecorder) Probe(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Probe", reflect.TypeOf((*MockIdentityServer)(nil).Probe), arg0, arg1)
}
// MockControllerServer is a mock of ControllerServer interface.
type MockControllerServer struct {
ctrl *gomock.Controller
recorder *MockControllerServerMockRecorder
}
// MockControllerServerMockRecorder is the mock recorder for MockControllerServer.
type MockControllerServerMockRecorder struct {
mock *MockControllerServer
}
// NewMockControllerServer creates a new mock instance.
func NewMockControllerServer(ctrl *gomock.Controller) *MockControllerServer {
mock := &MockControllerServer{ctrl: ctrl}
mock.recorder = &MockControllerServerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockControllerServer) EXPECT() *MockControllerServerMockRecorder {
return m.recorder
}
// ControllerExpandVolume mocks base method.
func (m *MockControllerServer) ControllerExpandVolume(arg0 context.Context, arg1 *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ControllerExpandVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.ControllerExpandVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ControllerExpandVolume indicates an expected call of ControllerExpandVolume.
func (mr *MockControllerServerMockRecorder) ControllerExpandVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControllerExpandVolume", reflect.TypeOf((*MockControllerServer)(nil).ControllerExpandVolume), arg0, arg1)
}
// ControllerGetCapabilities mocks base method.
func (m *MockControllerServer) ControllerGetCapabilities(arg0 context.Context, arg1 *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ControllerGetCapabilities", arg0, arg1)
ret0, _ := ret[0].(*csi.ControllerGetCapabilitiesResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ControllerGetCapabilities indicates an expected call of ControllerGetCapabilities.
func (mr *MockControllerServerMockRecorder) ControllerGetCapabilities(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControllerGetCapabilities", reflect.TypeOf((*MockControllerServer)(nil).ControllerGetCapabilities), arg0, arg1)
}
// ControllerGetVolume mocks base method.
func (m *MockControllerServer) ControllerGetVolume(arg0 context.Context, arg1 *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ControllerGetVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.ControllerGetVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ControllerGetVolume indicates an expected call of ControllerGetVolume.
func (mr *MockControllerServerMockRecorder) ControllerGetVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControllerGetVolume", reflect.TypeOf((*MockControllerServer)(nil).ControllerGetVolume), arg0, arg1)
}
// ControllerModifyVolume mocks base method.
func (m *MockControllerServer) ControllerModifyVolume(arg0 context.Context, arg1 *csi.ControllerModifyVolumeRequest) (*csi.ControllerModifyVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ControllerModifyVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.ControllerModifyVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ControllerModifyVolume indicates an expected call of ControllerModifyVolume.
func (mr *MockControllerServerMockRecorder) ControllerModifyVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControllerModifyVolume", reflect.TypeOf((*MockControllerServer)(nil).ControllerModifyVolume), arg0, arg1)
}
// ControllerPublishVolume mocks base method.
func (m *MockControllerServer) ControllerPublishVolume(arg0 context.Context, arg1 *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ControllerPublishVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.ControllerPublishVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ControllerPublishVolume indicates an expected call of ControllerPublishVolume.
func (mr *MockControllerServerMockRecorder) ControllerPublishVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControllerPublishVolume", reflect.TypeOf((*MockControllerServer)(nil).ControllerPublishVolume), arg0, arg1)
}
// ControllerUnpublishVolume mocks base method.
func (m *MockControllerServer) ControllerUnpublishVolume(arg0 context.Context, arg1 *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ControllerUnpublishVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.ControllerUnpublishVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ControllerUnpublishVolume indicates an expected call of ControllerUnpublishVolume.
func (mr *MockControllerServerMockRecorder) ControllerUnpublishVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControllerUnpublishVolume", reflect.TypeOf((*MockControllerServer)(nil).ControllerUnpublishVolume), arg0, arg1)
}
// CreateSnapshot mocks base method.
func (m *MockControllerServer) CreateSnapshot(arg0 context.Context, arg1 *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "CreateSnapshot", arg0, arg1)
ret0, _ := ret[0].(*csi.CreateSnapshotResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// CreateSnapshot indicates an expected call of CreateSnapshot.
func (mr *MockControllerServerMockRecorder) CreateSnapshot(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateSnapshot", reflect.TypeOf((*MockControllerServer)(nil).CreateSnapshot), arg0, arg1)
}
// CreateVolume mocks base method.
func (m *MockControllerServer) CreateVolume(arg0 context.Context, arg1 *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "CreateVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.CreateVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// CreateVolume indicates an expected call of CreateVolume.
func (mr *MockControllerServerMockRecorder) CreateVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateVolume", reflect.TypeOf((*MockControllerServer)(nil).CreateVolume), arg0, arg1)
}
// DeleteSnapshot mocks base method.
func (m *MockControllerServer) DeleteSnapshot(arg0 context.Context, arg1 *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DeleteSnapshot", arg0, arg1)
ret0, _ := ret[0].(*csi.DeleteSnapshotResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// DeleteSnapshot indicates an expected call of DeleteSnapshot.
func (mr *MockControllerServerMockRecorder) DeleteSnapshot(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteSnapshot", reflect.TypeOf((*MockControllerServer)(nil).DeleteSnapshot), arg0, arg1)
}
// DeleteVolume mocks base method.
func (m *MockControllerServer) DeleteVolume(arg0 context.Context, arg1 *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DeleteVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.DeleteVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// DeleteVolume indicates an expected call of DeleteVolume.
func (mr *MockControllerServerMockRecorder) DeleteVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteVolume", reflect.TypeOf((*MockControllerServer)(nil).DeleteVolume), arg0, arg1)
}
// GetCapacity mocks base method.
func (m *MockControllerServer) GetCapacity(arg0 context.Context, arg1 *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetCapacity", arg0, arg1)
ret0, _ := ret[0].(*csi.GetCapacityResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetCapacity indicates an expected call of GetCapacity.
func (mr *MockControllerServerMockRecorder) GetCapacity(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCapacity", reflect.TypeOf((*MockControllerServer)(nil).GetCapacity), arg0, arg1)
}
// ListSnapshots mocks base method.
func (m *MockControllerServer) ListSnapshots(arg0 context.Context, arg1 *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ListSnapshots", arg0, arg1)
ret0, _ := ret[0].(*csi.ListSnapshotsResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ListSnapshots indicates an expected call of ListSnapshots.
func (mr *MockControllerServerMockRecorder) ListSnapshots(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListSnapshots", reflect.TypeOf((*MockControllerServer)(nil).ListSnapshots), arg0, arg1)
}
// ListVolumes mocks base method.
func (m *MockControllerServer) ListVolumes(arg0 context.Context, arg1 *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ListVolumes", arg0, arg1)
ret0, _ := ret[0].(*csi.ListVolumesResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ListVolumes indicates an expected call of ListVolumes.
func (mr *MockControllerServerMockRecorder) ListVolumes(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListVolumes", reflect.TypeOf((*MockControllerServer)(nil).ListVolumes), arg0, arg1)
}
// ValidateVolumeCapabilities mocks base method.
func (m *MockControllerServer) ValidateVolumeCapabilities(arg0 context.Context, arg1 *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateVolumeCapabilities", arg0, arg1)
ret0, _ := ret[0].(*csi.ValidateVolumeCapabilitiesResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ValidateVolumeCapabilities indicates an expected call of ValidateVolumeCapabilities.
func (mr *MockControllerServerMockRecorder) ValidateVolumeCapabilities(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateVolumeCapabilities", reflect.TypeOf((*MockControllerServer)(nil).ValidateVolumeCapabilities), arg0, arg1)
}
// MockNodeServer is a mock of NodeServer interface.
type MockNodeServer struct {
ctrl *gomock.Controller
recorder *MockNodeServerMockRecorder
}
// MockNodeServerMockRecorder is the mock recorder for MockNodeServer.
type MockNodeServerMockRecorder struct {
mock *MockNodeServer
}
// NewMockNodeServer creates a new mock instance.
func NewMockNodeServer(ctrl *gomock.Controller) *MockNodeServer {
mock := &MockNodeServer{ctrl: ctrl}
mock.recorder = &MockNodeServerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockNodeServer) EXPECT() *MockNodeServerMockRecorder {
return m.recorder
}
// NodeExpandVolume mocks base method.
func (m *MockNodeServer) NodeExpandVolume(arg0 context.Context, arg1 *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NodeExpandVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.NodeExpandVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// NodeExpandVolume indicates an expected call of NodeExpandVolume.
func (mr *MockNodeServerMockRecorder) NodeExpandVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeExpandVolume", reflect.TypeOf((*MockNodeServer)(nil).NodeExpandVolume), arg0, arg1)
}
// NodeGetCapabilities mocks base method.
func (m *MockNodeServer) NodeGetCapabilities(arg0 context.Context, arg1 *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NodeGetCapabilities", arg0, arg1)
ret0, _ := ret[0].(*csi.NodeGetCapabilitiesResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// NodeGetCapabilities indicates an expected call of NodeGetCapabilities.
func (mr *MockNodeServerMockRecorder) NodeGetCapabilities(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeGetCapabilities", reflect.TypeOf((*MockNodeServer)(nil).NodeGetCapabilities), arg0, arg1)
}
// NodeGetInfo mocks base method.
func (m *MockNodeServer) NodeGetInfo(arg0 context.Context, arg1 *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NodeGetInfo", arg0, arg1)
ret0, _ := ret[0].(*csi.NodeGetInfoResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// NodeGetInfo indicates an expected call of NodeGetInfo.
func (mr *MockNodeServerMockRecorder) NodeGetInfo(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeGetInfo", reflect.TypeOf((*MockNodeServer)(nil).NodeGetInfo), arg0, arg1)
}
// NodeGetVolumeStats mocks base method.
func (m *MockNodeServer) NodeGetVolumeStats(arg0 context.Context, arg1 *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NodeGetVolumeStats", arg0, arg1)
ret0, _ := ret[0].(*csi.NodeGetVolumeStatsResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// NodeGetVolumeStats indicates an expected call of NodeGetVolumeStats.
func (mr *MockNodeServerMockRecorder) NodeGetVolumeStats(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeGetVolumeStats", reflect.TypeOf((*MockNodeServer)(nil).NodeGetVolumeStats), arg0, arg1)
}
// NodePublishVolume mocks base method.
func (m *MockNodeServer) NodePublishVolume(arg0 context.Context, arg1 *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NodePublishVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.NodePublishVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// NodePublishVolume indicates an expected call of NodePublishVolume.
func (mr *MockNodeServerMockRecorder) NodePublishVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodePublishVolume", reflect.TypeOf((*MockNodeServer)(nil).NodePublishVolume), arg0, arg1)
}
// NodeStageVolume mocks base method.
func (m *MockNodeServer) NodeStageVolume(arg0 context.Context, arg1 *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NodeStageVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.NodeStageVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// NodeStageVolume indicates an expected call of NodeStageVolume.
func (mr *MockNodeServerMockRecorder) NodeStageVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeStageVolume", reflect.TypeOf((*MockNodeServer)(nil).NodeStageVolume), arg0, arg1)
}
// NodeUnpublishVolume mocks base method.
func (m *MockNodeServer) NodeUnpublishVolume(arg0 context.Context, arg1 *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NodeUnpublishVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.NodeUnpublishVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// NodeUnpublishVolume indicates an expected call of NodeUnpublishVolume.
func (mr *MockNodeServerMockRecorder) NodeUnpublishVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeUnpublishVolume", reflect.TypeOf((*MockNodeServer)(nil).NodeUnpublishVolume), arg0, arg1)
}
// NodeUnstageVolume mocks base method.
func (m *MockNodeServer) NodeUnstageVolume(arg0 context.Context, arg1 *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NodeUnstageVolume", arg0, arg1)
ret0, _ := ret[0].(*csi.NodeUnstageVolumeResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// NodeUnstageVolume indicates an expected call of NodeUnstageVolume.
func (mr *MockNodeServerMockRecorder) NodeUnstageVolume(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeUnstageVolume", reflect.TypeOf((*MockNodeServer)(nil).NodeUnstageVolume), arg0, arg1)
}

View File

@ -0,0 +1,879 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package driver
import (
context "context"
csi "github.com/container-storage-interface/spec/lib/go/csi"
mock "github.com/stretchr/testify/mock"
)
// MockControllerServer is an autogenerated mock type for the ControllerServer type
type MockControllerServer struct {
mock.Mock
}
type MockControllerServer_Expecter struct {
mock *mock.Mock
}
func (_m *MockControllerServer) EXPECT() *MockControllerServer_Expecter {
return &MockControllerServer_Expecter{mock: &_m.Mock}
}
// ControllerExpandVolume provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) ControllerExpandVolume(_a0 context.Context, _a1 *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ControllerExpandVolume")
}
var r0 *csi.ControllerExpandVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerExpandVolumeRequest) *csi.ControllerExpandVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.ControllerExpandVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.ControllerExpandVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_ControllerExpandVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ControllerExpandVolume'
type MockControllerServer_ControllerExpandVolume_Call struct {
*mock.Call
}
// ControllerExpandVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.ControllerExpandVolumeRequest
func (_e *MockControllerServer_Expecter) ControllerExpandVolume(_a0 interface{}, _a1 interface{}) *MockControllerServer_ControllerExpandVolume_Call {
return &MockControllerServer_ControllerExpandVolume_Call{Call: _e.mock.On("ControllerExpandVolume", _a0, _a1)}
}
func (_c *MockControllerServer_ControllerExpandVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.ControllerExpandVolumeRequest)) *MockControllerServer_ControllerExpandVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.ControllerExpandVolumeRequest))
})
return _c
}
func (_c *MockControllerServer_ControllerExpandVolume_Call) Return(_a0 *csi.ControllerExpandVolumeResponse, _a1 error) *MockControllerServer_ControllerExpandVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_ControllerExpandVolume_Call) RunAndReturn(run func(context.Context, *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error)) *MockControllerServer_ControllerExpandVolume_Call {
_c.Call.Return(run)
return _c
}
// ControllerGetCapabilities provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) ControllerGetCapabilities(_a0 context.Context, _a1 *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ControllerGetCapabilities")
}
var r0 *csi.ControllerGetCapabilitiesResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerGetCapabilitiesRequest) *csi.ControllerGetCapabilitiesResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.ControllerGetCapabilitiesResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.ControllerGetCapabilitiesRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_ControllerGetCapabilities_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ControllerGetCapabilities'
type MockControllerServer_ControllerGetCapabilities_Call struct {
*mock.Call
}
// ControllerGetCapabilities is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.ControllerGetCapabilitiesRequest
func (_e *MockControllerServer_Expecter) ControllerGetCapabilities(_a0 interface{}, _a1 interface{}) *MockControllerServer_ControllerGetCapabilities_Call {
return &MockControllerServer_ControllerGetCapabilities_Call{Call: _e.mock.On("ControllerGetCapabilities", _a0, _a1)}
}
func (_c *MockControllerServer_ControllerGetCapabilities_Call) Run(run func(_a0 context.Context, _a1 *csi.ControllerGetCapabilitiesRequest)) *MockControllerServer_ControllerGetCapabilities_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.ControllerGetCapabilitiesRequest))
})
return _c
}
func (_c *MockControllerServer_ControllerGetCapabilities_Call) Return(_a0 *csi.ControllerGetCapabilitiesResponse, _a1 error) *MockControllerServer_ControllerGetCapabilities_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_ControllerGetCapabilities_Call) RunAndReturn(run func(context.Context, *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error)) *MockControllerServer_ControllerGetCapabilities_Call {
_c.Call.Return(run)
return _c
}
// ControllerGetVolume provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) ControllerGetVolume(_a0 context.Context, _a1 *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ControllerGetVolume")
}
var r0 *csi.ControllerGetVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerGetVolumeRequest) *csi.ControllerGetVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.ControllerGetVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.ControllerGetVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_ControllerGetVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ControllerGetVolume'
type MockControllerServer_ControllerGetVolume_Call struct {
*mock.Call
}
// ControllerGetVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.ControllerGetVolumeRequest
func (_e *MockControllerServer_Expecter) ControllerGetVolume(_a0 interface{}, _a1 interface{}) *MockControllerServer_ControllerGetVolume_Call {
return &MockControllerServer_ControllerGetVolume_Call{Call: _e.mock.On("ControllerGetVolume", _a0, _a1)}
}
func (_c *MockControllerServer_ControllerGetVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.ControllerGetVolumeRequest)) *MockControllerServer_ControllerGetVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.ControllerGetVolumeRequest))
})
return _c
}
func (_c *MockControllerServer_ControllerGetVolume_Call) Return(_a0 *csi.ControllerGetVolumeResponse, _a1 error) *MockControllerServer_ControllerGetVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_ControllerGetVolume_Call) RunAndReturn(run func(context.Context, *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error)) *MockControllerServer_ControllerGetVolume_Call {
_c.Call.Return(run)
return _c
}
// ControllerModifyVolume provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) ControllerModifyVolume(_a0 context.Context, _a1 *csi.ControllerModifyVolumeRequest) (*csi.ControllerModifyVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ControllerModifyVolume")
}
var r0 *csi.ControllerModifyVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerModifyVolumeRequest) (*csi.ControllerModifyVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerModifyVolumeRequest) *csi.ControllerModifyVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.ControllerModifyVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.ControllerModifyVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_ControllerModifyVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ControllerModifyVolume'
type MockControllerServer_ControllerModifyVolume_Call struct {
*mock.Call
}
// ControllerModifyVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.ControllerModifyVolumeRequest
func (_e *MockControllerServer_Expecter) ControllerModifyVolume(_a0 interface{}, _a1 interface{}) *MockControllerServer_ControllerModifyVolume_Call {
return &MockControllerServer_ControllerModifyVolume_Call{Call: _e.mock.On("ControllerModifyVolume", _a0, _a1)}
}
func (_c *MockControllerServer_ControllerModifyVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.ControllerModifyVolumeRequest)) *MockControllerServer_ControllerModifyVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.ControllerModifyVolumeRequest))
})
return _c
}
func (_c *MockControllerServer_ControllerModifyVolume_Call) Return(_a0 *csi.ControllerModifyVolumeResponse, _a1 error) *MockControllerServer_ControllerModifyVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_ControllerModifyVolume_Call) RunAndReturn(run func(context.Context, *csi.ControllerModifyVolumeRequest) (*csi.ControllerModifyVolumeResponse, error)) *MockControllerServer_ControllerModifyVolume_Call {
_c.Call.Return(run)
return _c
}
// ControllerPublishVolume provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) ControllerPublishVolume(_a0 context.Context, _a1 *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ControllerPublishVolume")
}
var r0 *csi.ControllerPublishVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerPublishVolumeRequest) *csi.ControllerPublishVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.ControllerPublishVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.ControllerPublishVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_ControllerPublishVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ControllerPublishVolume'
type MockControllerServer_ControllerPublishVolume_Call struct {
*mock.Call
}
// ControllerPublishVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.ControllerPublishVolumeRequest
func (_e *MockControllerServer_Expecter) ControllerPublishVolume(_a0 interface{}, _a1 interface{}) *MockControllerServer_ControllerPublishVolume_Call {
return &MockControllerServer_ControllerPublishVolume_Call{Call: _e.mock.On("ControllerPublishVolume", _a0, _a1)}
}
func (_c *MockControllerServer_ControllerPublishVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.ControllerPublishVolumeRequest)) *MockControllerServer_ControllerPublishVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.ControllerPublishVolumeRequest))
})
return _c
}
func (_c *MockControllerServer_ControllerPublishVolume_Call) Return(_a0 *csi.ControllerPublishVolumeResponse, _a1 error) *MockControllerServer_ControllerPublishVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_ControllerPublishVolume_Call) RunAndReturn(run func(context.Context, *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error)) *MockControllerServer_ControllerPublishVolume_Call {
_c.Call.Return(run)
return _c
}
// ControllerUnpublishVolume provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) ControllerUnpublishVolume(_a0 context.Context, _a1 *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ControllerUnpublishVolume")
}
var r0 *csi.ControllerUnpublishVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.ControllerUnpublishVolumeRequest) *csi.ControllerUnpublishVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.ControllerUnpublishVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.ControllerUnpublishVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_ControllerUnpublishVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ControllerUnpublishVolume'
type MockControllerServer_ControllerUnpublishVolume_Call struct {
*mock.Call
}
// ControllerUnpublishVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.ControllerUnpublishVolumeRequest
func (_e *MockControllerServer_Expecter) ControllerUnpublishVolume(_a0 interface{}, _a1 interface{}) *MockControllerServer_ControllerUnpublishVolume_Call {
return &MockControllerServer_ControllerUnpublishVolume_Call{Call: _e.mock.On("ControllerUnpublishVolume", _a0, _a1)}
}
func (_c *MockControllerServer_ControllerUnpublishVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.ControllerUnpublishVolumeRequest)) *MockControllerServer_ControllerUnpublishVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.ControllerUnpublishVolumeRequest))
})
return _c
}
func (_c *MockControllerServer_ControllerUnpublishVolume_Call) Return(_a0 *csi.ControllerUnpublishVolumeResponse, _a1 error) *MockControllerServer_ControllerUnpublishVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_ControllerUnpublishVolume_Call) RunAndReturn(run func(context.Context, *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error)) *MockControllerServer_ControllerUnpublishVolume_Call {
_c.Call.Return(run)
return _c
}
// CreateSnapshot provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) CreateSnapshot(_a0 context.Context, _a1 *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for CreateSnapshot")
}
var r0 *csi.CreateSnapshotResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.CreateSnapshotRequest) *csi.CreateSnapshotResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.CreateSnapshotResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.CreateSnapshotRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_CreateSnapshot_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateSnapshot'
type MockControllerServer_CreateSnapshot_Call struct {
*mock.Call
}
// CreateSnapshot is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.CreateSnapshotRequest
func (_e *MockControllerServer_Expecter) CreateSnapshot(_a0 interface{}, _a1 interface{}) *MockControllerServer_CreateSnapshot_Call {
return &MockControllerServer_CreateSnapshot_Call{Call: _e.mock.On("CreateSnapshot", _a0, _a1)}
}
func (_c *MockControllerServer_CreateSnapshot_Call) Run(run func(_a0 context.Context, _a1 *csi.CreateSnapshotRequest)) *MockControllerServer_CreateSnapshot_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.CreateSnapshotRequest))
})
return _c
}
func (_c *MockControllerServer_CreateSnapshot_Call) Return(_a0 *csi.CreateSnapshotResponse, _a1 error) *MockControllerServer_CreateSnapshot_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_CreateSnapshot_Call) RunAndReturn(run func(context.Context, *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error)) *MockControllerServer_CreateSnapshot_Call {
_c.Call.Return(run)
return _c
}
// CreateVolume provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) CreateVolume(_a0 context.Context, _a1 *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for CreateVolume")
}
var r0 *csi.CreateVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.CreateVolumeRequest) *csi.CreateVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.CreateVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.CreateVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_CreateVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateVolume'
type MockControllerServer_CreateVolume_Call struct {
*mock.Call
}
// CreateVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.CreateVolumeRequest
func (_e *MockControllerServer_Expecter) CreateVolume(_a0 interface{}, _a1 interface{}) *MockControllerServer_CreateVolume_Call {
return &MockControllerServer_CreateVolume_Call{Call: _e.mock.On("CreateVolume", _a0, _a1)}
}
func (_c *MockControllerServer_CreateVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.CreateVolumeRequest)) *MockControllerServer_CreateVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.CreateVolumeRequest))
})
return _c
}
func (_c *MockControllerServer_CreateVolume_Call) Return(_a0 *csi.CreateVolumeResponse, _a1 error) *MockControllerServer_CreateVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_CreateVolume_Call) RunAndReturn(run func(context.Context, *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error)) *MockControllerServer_CreateVolume_Call {
_c.Call.Return(run)
return _c
}
// DeleteSnapshot provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) DeleteSnapshot(_a0 context.Context, _a1 *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for DeleteSnapshot")
}
var r0 *csi.DeleteSnapshotResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.DeleteSnapshotRequest) *csi.DeleteSnapshotResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.DeleteSnapshotResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.DeleteSnapshotRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_DeleteSnapshot_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteSnapshot'
type MockControllerServer_DeleteSnapshot_Call struct {
*mock.Call
}
// DeleteSnapshot is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.DeleteSnapshotRequest
func (_e *MockControllerServer_Expecter) DeleteSnapshot(_a0 interface{}, _a1 interface{}) *MockControllerServer_DeleteSnapshot_Call {
return &MockControllerServer_DeleteSnapshot_Call{Call: _e.mock.On("DeleteSnapshot", _a0, _a1)}
}
func (_c *MockControllerServer_DeleteSnapshot_Call) Run(run func(_a0 context.Context, _a1 *csi.DeleteSnapshotRequest)) *MockControllerServer_DeleteSnapshot_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.DeleteSnapshotRequest))
})
return _c
}
func (_c *MockControllerServer_DeleteSnapshot_Call) Return(_a0 *csi.DeleteSnapshotResponse, _a1 error) *MockControllerServer_DeleteSnapshot_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_DeleteSnapshot_Call) RunAndReturn(run func(context.Context, *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error)) *MockControllerServer_DeleteSnapshot_Call {
_c.Call.Return(run)
return _c
}
// DeleteVolume provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) DeleteVolume(_a0 context.Context, _a1 *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for DeleteVolume")
}
var r0 *csi.DeleteVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.DeleteVolumeRequest) *csi.DeleteVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.DeleteVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.DeleteVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_DeleteVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteVolume'
type MockControllerServer_DeleteVolume_Call struct {
*mock.Call
}
// DeleteVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.DeleteVolumeRequest
func (_e *MockControllerServer_Expecter) DeleteVolume(_a0 interface{}, _a1 interface{}) *MockControllerServer_DeleteVolume_Call {
return &MockControllerServer_DeleteVolume_Call{Call: _e.mock.On("DeleteVolume", _a0, _a1)}
}
func (_c *MockControllerServer_DeleteVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.DeleteVolumeRequest)) *MockControllerServer_DeleteVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.DeleteVolumeRequest))
})
return _c
}
func (_c *MockControllerServer_DeleteVolume_Call) Return(_a0 *csi.DeleteVolumeResponse, _a1 error) *MockControllerServer_DeleteVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_DeleteVolume_Call) RunAndReturn(run func(context.Context, *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error)) *MockControllerServer_DeleteVolume_Call {
_c.Call.Return(run)
return _c
}
// GetCapacity provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) GetCapacity(_a0 context.Context, _a1 *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for GetCapacity")
}
var r0 *csi.GetCapacityResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.GetCapacityRequest) *csi.GetCapacityResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.GetCapacityResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.GetCapacityRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_GetCapacity_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCapacity'
type MockControllerServer_GetCapacity_Call struct {
*mock.Call
}
// GetCapacity is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.GetCapacityRequest
func (_e *MockControllerServer_Expecter) GetCapacity(_a0 interface{}, _a1 interface{}) *MockControllerServer_GetCapacity_Call {
return &MockControllerServer_GetCapacity_Call{Call: _e.mock.On("GetCapacity", _a0, _a1)}
}
func (_c *MockControllerServer_GetCapacity_Call) Run(run func(_a0 context.Context, _a1 *csi.GetCapacityRequest)) *MockControllerServer_GetCapacity_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.GetCapacityRequest))
})
return _c
}
func (_c *MockControllerServer_GetCapacity_Call) Return(_a0 *csi.GetCapacityResponse, _a1 error) *MockControllerServer_GetCapacity_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_GetCapacity_Call) RunAndReturn(run func(context.Context, *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error)) *MockControllerServer_GetCapacity_Call {
_c.Call.Return(run)
return _c
}
// ListSnapshots provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) ListSnapshots(_a0 context.Context, _a1 *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ListSnapshots")
}
var r0 *csi.ListSnapshotsResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.ListSnapshotsRequest) *csi.ListSnapshotsResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.ListSnapshotsResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.ListSnapshotsRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_ListSnapshots_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListSnapshots'
type MockControllerServer_ListSnapshots_Call struct {
*mock.Call
}
// ListSnapshots is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.ListSnapshotsRequest
func (_e *MockControllerServer_Expecter) ListSnapshots(_a0 interface{}, _a1 interface{}) *MockControllerServer_ListSnapshots_Call {
return &MockControllerServer_ListSnapshots_Call{Call: _e.mock.On("ListSnapshots", _a0, _a1)}
}
func (_c *MockControllerServer_ListSnapshots_Call) Run(run func(_a0 context.Context, _a1 *csi.ListSnapshotsRequest)) *MockControllerServer_ListSnapshots_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.ListSnapshotsRequest))
})
return _c
}
func (_c *MockControllerServer_ListSnapshots_Call) Return(_a0 *csi.ListSnapshotsResponse, _a1 error) *MockControllerServer_ListSnapshots_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_ListSnapshots_Call) RunAndReturn(run func(context.Context, *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error)) *MockControllerServer_ListSnapshots_Call {
_c.Call.Return(run)
return _c
}
// ListVolumes provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) ListVolumes(_a0 context.Context, _a1 *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ListVolumes")
}
var r0 *csi.ListVolumesResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.ListVolumesRequest) *csi.ListVolumesResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.ListVolumesResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.ListVolumesRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_ListVolumes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListVolumes'
type MockControllerServer_ListVolumes_Call struct {
*mock.Call
}
// ListVolumes is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.ListVolumesRequest
func (_e *MockControllerServer_Expecter) ListVolumes(_a0 interface{}, _a1 interface{}) *MockControllerServer_ListVolumes_Call {
return &MockControllerServer_ListVolumes_Call{Call: _e.mock.On("ListVolumes", _a0, _a1)}
}
func (_c *MockControllerServer_ListVolumes_Call) Run(run func(_a0 context.Context, _a1 *csi.ListVolumesRequest)) *MockControllerServer_ListVolumes_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.ListVolumesRequest))
})
return _c
}
func (_c *MockControllerServer_ListVolumes_Call) Return(_a0 *csi.ListVolumesResponse, _a1 error) *MockControllerServer_ListVolumes_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_ListVolumes_Call) RunAndReturn(run func(context.Context, *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error)) *MockControllerServer_ListVolumes_Call {
_c.Call.Return(run)
return _c
}
// ValidateVolumeCapabilities provides a mock function with given fields: _a0, _a1
func (_m *MockControllerServer) ValidateVolumeCapabilities(_a0 context.Context, _a1 *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ValidateVolumeCapabilities")
}
var r0 *csi.ValidateVolumeCapabilitiesResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.ValidateVolumeCapabilitiesRequest) *csi.ValidateVolumeCapabilitiesResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.ValidateVolumeCapabilitiesResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.ValidateVolumeCapabilitiesRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockControllerServer_ValidateVolumeCapabilities_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ValidateVolumeCapabilities'
type MockControllerServer_ValidateVolumeCapabilities_Call struct {
*mock.Call
}
// ValidateVolumeCapabilities is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.ValidateVolumeCapabilitiesRequest
func (_e *MockControllerServer_Expecter) ValidateVolumeCapabilities(_a0 interface{}, _a1 interface{}) *MockControllerServer_ValidateVolumeCapabilities_Call {
return &MockControllerServer_ValidateVolumeCapabilities_Call{Call: _e.mock.On("ValidateVolumeCapabilities", _a0, _a1)}
}
func (_c *MockControllerServer_ValidateVolumeCapabilities_Call) Run(run func(_a0 context.Context, _a1 *csi.ValidateVolumeCapabilitiesRequest)) *MockControllerServer_ValidateVolumeCapabilities_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.ValidateVolumeCapabilitiesRequest))
})
return _c
}
func (_c *MockControllerServer_ValidateVolumeCapabilities_Call) Return(_a0 *csi.ValidateVolumeCapabilitiesResponse, _a1 error) *MockControllerServer_ValidateVolumeCapabilities_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockControllerServer_ValidateVolumeCapabilities_Call) RunAndReturn(run func(context.Context, *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error)) *MockControllerServer_ValidateVolumeCapabilities_Call {
_c.Call.Return(run)
return _c
}
// NewMockControllerServer creates a new instance of MockControllerServer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockControllerServer(t interface {
mock.TestingT
Cleanup(func())
}) *MockControllerServer {
mock := &MockControllerServer{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -0,0 +1,230 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package driver
import (
context "context"
csi "github.com/container-storage-interface/spec/lib/go/csi"
mock "github.com/stretchr/testify/mock"
)
// MockIdentityServer is an autogenerated mock type for the IdentityServer type
type MockIdentityServer struct {
mock.Mock
}
type MockIdentityServer_Expecter struct {
mock *mock.Mock
}
func (_m *MockIdentityServer) EXPECT() *MockIdentityServer_Expecter {
return &MockIdentityServer_Expecter{mock: &_m.Mock}
}
// GetPluginCapabilities provides a mock function with given fields: _a0, _a1
func (_m *MockIdentityServer) GetPluginCapabilities(_a0 context.Context, _a1 *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for GetPluginCapabilities")
}
var r0 *csi.GetPluginCapabilitiesResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.GetPluginCapabilitiesRequest) *csi.GetPluginCapabilitiesResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.GetPluginCapabilitiesResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.GetPluginCapabilitiesRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockIdentityServer_GetPluginCapabilities_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPluginCapabilities'
type MockIdentityServer_GetPluginCapabilities_Call struct {
*mock.Call
}
// GetPluginCapabilities is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.GetPluginCapabilitiesRequest
func (_e *MockIdentityServer_Expecter) GetPluginCapabilities(_a0 interface{}, _a1 interface{}) *MockIdentityServer_GetPluginCapabilities_Call {
return &MockIdentityServer_GetPluginCapabilities_Call{Call: _e.mock.On("GetPluginCapabilities", _a0, _a1)}
}
func (_c *MockIdentityServer_GetPluginCapabilities_Call) Run(run func(_a0 context.Context, _a1 *csi.GetPluginCapabilitiesRequest)) *MockIdentityServer_GetPluginCapabilities_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.GetPluginCapabilitiesRequest))
})
return _c
}
func (_c *MockIdentityServer_GetPluginCapabilities_Call) Return(_a0 *csi.GetPluginCapabilitiesResponse, _a1 error) *MockIdentityServer_GetPluginCapabilities_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockIdentityServer_GetPluginCapabilities_Call) RunAndReturn(run func(context.Context, *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error)) *MockIdentityServer_GetPluginCapabilities_Call {
_c.Call.Return(run)
return _c
}
// GetPluginInfo provides a mock function with given fields: _a0, _a1
func (_m *MockIdentityServer) GetPluginInfo(_a0 context.Context, _a1 *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for GetPluginInfo")
}
var r0 *csi.GetPluginInfoResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.GetPluginInfoRequest) *csi.GetPluginInfoResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.GetPluginInfoResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.GetPluginInfoRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockIdentityServer_GetPluginInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPluginInfo'
type MockIdentityServer_GetPluginInfo_Call struct {
*mock.Call
}
// GetPluginInfo is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.GetPluginInfoRequest
func (_e *MockIdentityServer_Expecter) GetPluginInfo(_a0 interface{}, _a1 interface{}) *MockIdentityServer_GetPluginInfo_Call {
return &MockIdentityServer_GetPluginInfo_Call{Call: _e.mock.On("GetPluginInfo", _a0, _a1)}
}
func (_c *MockIdentityServer_GetPluginInfo_Call) Run(run func(_a0 context.Context, _a1 *csi.GetPluginInfoRequest)) *MockIdentityServer_GetPluginInfo_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.GetPluginInfoRequest))
})
return _c
}
func (_c *MockIdentityServer_GetPluginInfo_Call) Return(_a0 *csi.GetPluginInfoResponse, _a1 error) *MockIdentityServer_GetPluginInfo_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockIdentityServer_GetPluginInfo_Call) RunAndReturn(run func(context.Context, *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error)) *MockIdentityServer_GetPluginInfo_Call {
_c.Call.Return(run)
return _c
}
// Probe provides a mock function with given fields: _a0, _a1
func (_m *MockIdentityServer) Probe(_a0 context.Context, _a1 *csi.ProbeRequest) (*csi.ProbeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for Probe")
}
var r0 *csi.ProbeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.ProbeRequest) (*csi.ProbeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.ProbeRequest) *csi.ProbeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.ProbeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.ProbeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockIdentityServer_Probe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Probe'
type MockIdentityServer_Probe_Call struct {
*mock.Call
}
// Probe is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.ProbeRequest
func (_e *MockIdentityServer_Expecter) Probe(_a0 interface{}, _a1 interface{}) *MockIdentityServer_Probe_Call {
return &MockIdentityServer_Probe_Call{Call: _e.mock.On("Probe", _a0, _a1)}
}
func (_c *MockIdentityServer_Probe_Call) Run(run func(_a0 context.Context, _a1 *csi.ProbeRequest)) *MockIdentityServer_Probe_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.ProbeRequest))
})
return _c
}
func (_c *MockIdentityServer_Probe_Call) Return(_a0 *csi.ProbeResponse, _a1 error) *MockIdentityServer_Probe_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockIdentityServer_Probe_Call) RunAndReturn(run func(context.Context, *csi.ProbeRequest) (*csi.ProbeResponse, error)) *MockIdentityServer_Probe_Call {
_c.Call.Return(run)
return _c
}
// NewMockIdentityServer creates a new instance of MockIdentityServer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockIdentityServer(t interface {
mock.TestingT
Cleanup(func())
}) *MockIdentityServer {
mock := &MockIdentityServer{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -0,0 +1,525 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package driver
import (
context "context"
csi "github.com/container-storage-interface/spec/lib/go/csi"
mock "github.com/stretchr/testify/mock"
)
// MockNodeServer is an autogenerated mock type for the NodeServer type
type MockNodeServer struct {
mock.Mock
}
type MockNodeServer_Expecter struct {
mock *mock.Mock
}
func (_m *MockNodeServer) EXPECT() *MockNodeServer_Expecter {
return &MockNodeServer_Expecter{mock: &_m.Mock}
}
// NodeExpandVolume provides a mock function with given fields: _a0, _a1
func (_m *MockNodeServer) NodeExpandVolume(_a0 context.Context, _a1 *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for NodeExpandVolume")
}
var r0 *csi.NodeExpandVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeExpandVolumeRequest) *csi.NodeExpandVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.NodeExpandVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.NodeExpandVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockNodeServer_NodeExpandVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NodeExpandVolume'
type MockNodeServer_NodeExpandVolume_Call struct {
*mock.Call
}
// NodeExpandVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.NodeExpandVolumeRequest
func (_e *MockNodeServer_Expecter) NodeExpandVolume(_a0 interface{}, _a1 interface{}) *MockNodeServer_NodeExpandVolume_Call {
return &MockNodeServer_NodeExpandVolume_Call{Call: _e.mock.On("NodeExpandVolume", _a0, _a1)}
}
func (_c *MockNodeServer_NodeExpandVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.NodeExpandVolumeRequest)) *MockNodeServer_NodeExpandVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.NodeExpandVolumeRequest))
})
return _c
}
func (_c *MockNodeServer_NodeExpandVolume_Call) Return(_a0 *csi.NodeExpandVolumeResponse, _a1 error) *MockNodeServer_NodeExpandVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockNodeServer_NodeExpandVolume_Call) RunAndReturn(run func(context.Context, *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error)) *MockNodeServer_NodeExpandVolume_Call {
_c.Call.Return(run)
return _c
}
// NodeGetCapabilities provides a mock function with given fields: _a0, _a1
func (_m *MockNodeServer) NodeGetCapabilities(_a0 context.Context, _a1 *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for NodeGetCapabilities")
}
var r0 *csi.NodeGetCapabilitiesResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeGetCapabilitiesRequest) *csi.NodeGetCapabilitiesResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.NodeGetCapabilitiesResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.NodeGetCapabilitiesRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockNodeServer_NodeGetCapabilities_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NodeGetCapabilities'
type MockNodeServer_NodeGetCapabilities_Call struct {
*mock.Call
}
// NodeGetCapabilities is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.NodeGetCapabilitiesRequest
func (_e *MockNodeServer_Expecter) NodeGetCapabilities(_a0 interface{}, _a1 interface{}) *MockNodeServer_NodeGetCapabilities_Call {
return &MockNodeServer_NodeGetCapabilities_Call{Call: _e.mock.On("NodeGetCapabilities", _a0, _a1)}
}
func (_c *MockNodeServer_NodeGetCapabilities_Call) Run(run func(_a0 context.Context, _a1 *csi.NodeGetCapabilitiesRequest)) *MockNodeServer_NodeGetCapabilities_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.NodeGetCapabilitiesRequest))
})
return _c
}
func (_c *MockNodeServer_NodeGetCapabilities_Call) Return(_a0 *csi.NodeGetCapabilitiesResponse, _a1 error) *MockNodeServer_NodeGetCapabilities_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockNodeServer_NodeGetCapabilities_Call) RunAndReturn(run func(context.Context, *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error)) *MockNodeServer_NodeGetCapabilities_Call {
_c.Call.Return(run)
return _c
}
// NodeGetInfo provides a mock function with given fields: _a0, _a1
func (_m *MockNodeServer) NodeGetInfo(_a0 context.Context, _a1 *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for NodeGetInfo")
}
var r0 *csi.NodeGetInfoResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeGetInfoRequest) *csi.NodeGetInfoResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.NodeGetInfoResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.NodeGetInfoRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockNodeServer_NodeGetInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NodeGetInfo'
type MockNodeServer_NodeGetInfo_Call struct {
*mock.Call
}
// NodeGetInfo is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.NodeGetInfoRequest
func (_e *MockNodeServer_Expecter) NodeGetInfo(_a0 interface{}, _a1 interface{}) *MockNodeServer_NodeGetInfo_Call {
return &MockNodeServer_NodeGetInfo_Call{Call: _e.mock.On("NodeGetInfo", _a0, _a1)}
}
func (_c *MockNodeServer_NodeGetInfo_Call) Run(run func(_a0 context.Context, _a1 *csi.NodeGetInfoRequest)) *MockNodeServer_NodeGetInfo_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.NodeGetInfoRequest))
})
return _c
}
func (_c *MockNodeServer_NodeGetInfo_Call) Return(_a0 *csi.NodeGetInfoResponse, _a1 error) *MockNodeServer_NodeGetInfo_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockNodeServer_NodeGetInfo_Call) RunAndReturn(run func(context.Context, *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error)) *MockNodeServer_NodeGetInfo_Call {
_c.Call.Return(run)
return _c
}
// NodeGetVolumeStats provides a mock function with given fields: _a0, _a1
func (_m *MockNodeServer) NodeGetVolumeStats(_a0 context.Context, _a1 *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for NodeGetVolumeStats")
}
var r0 *csi.NodeGetVolumeStatsResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeGetVolumeStatsRequest) *csi.NodeGetVolumeStatsResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.NodeGetVolumeStatsResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.NodeGetVolumeStatsRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockNodeServer_NodeGetVolumeStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NodeGetVolumeStats'
type MockNodeServer_NodeGetVolumeStats_Call struct {
*mock.Call
}
// NodeGetVolumeStats is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.NodeGetVolumeStatsRequest
func (_e *MockNodeServer_Expecter) NodeGetVolumeStats(_a0 interface{}, _a1 interface{}) *MockNodeServer_NodeGetVolumeStats_Call {
return &MockNodeServer_NodeGetVolumeStats_Call{Call: _e.mock.On("NodeGetVolumeStats", _a0, _a1)}
}
func (_c *MockNodeServer_NodeGetVolumeStats_Call) Run(run func(_a0 context.Context, _a1 *csi.NodeGetVolumeStatsRequest)) *MockNodeServer_NodeGetVolumeStats_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.NodeGetVolumeStatsRequest))
})
return _c
}
func (_c *MockNodeServer_NodeGetVolumeStats_Call) Return(_a0 *csi.NodeGetVolumeStatsResponse, _a1 error) *MockNodeServer_NodeGetVolumeStats_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockNodeServer_NodeGetVolumeStats_Call) RunAndReturn(run func(context.Context, *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error)) *MockNodeServer_NodeGetVolumeStats_Call {
_c.Call.Return(run)
return _c
}
// NodePublishVolume provides a mock function with given fields: _a0, _a1
func (_m *MockNodeServer) NodePublishVolume(_a0 context.Context, _a1 *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for NodePublishVolume")
}
var r0 *csi.NodePublishVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodePublishVolumeRequest) *csi.NodePublishVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.NodePublishVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.NodePublishVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockNodeServer_NodePublishVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NodePublishVolume'
type MockNodeServer_NodePublishVolume_Call struct {
*mock.Call
}
// NodePublishVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.NodePublishVolumeRequest
func (_e *MockNodeServer_Expecter) NodePublishVolume(_a0 interface{}, _a1 interface{}) *MockNodeServer_NodePublishVolume_Call {
return &MockNodeServer_NodePublishVolume_Call{Call: _e.mock.On("NodePublishVolume", _a0, _a1)}
}
func (_c *MockNodeServer_NodePublishVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.NodePublishVolumeRequest)) *MockNodeServer_NodePublishVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.NodePublishVolumeRequest))
})
return _c
}
func (_c *MockNodeServer_NodePublishVolume_Call) Return(_a0 *csi.NodePublishVolumeResponse, _a1 error) *MockNodeServer_NodePublishVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockNodeServer_NodePublishVolume_Call) RunAndReturn(run func(context.Context, *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error)) *MockNodeServer_NodePublishVolume_Call {
_c.Call.Return(run)
return _c
}
// NodeStageVolume provides a mock function with given fields: _a0, _a1
func (_m *MockNodeServer) NodeStageVolume(_a0 context.Context, _a1 *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for NodeStageVolume")
}
var r0 *csi.NodeStageVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeStageVolumeRequest) *csi.NodeStageVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.NodeStageVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.NodeStageVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockNodeServer_NodeStageVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NodeStageVolume'
type MockNodeServer_NodeStageVolume_Call struct {
*mock.Call
}
// NodeStageVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.NodeStageVolumeRequest
func (_e *MockNodeServer_Expecter) NodeStageVolume(_a0 interface{}, _a1 interface{}) *MockNodeServer_NodeStageVolume_Call {
return &MockNodeServer_NodeStageVolume_Call{Call: _e.mock.On("NodeStageVolume", _a0, _a1)}
}
func (_c *MockNodeServer_NodeStageVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.NodeStageVolumeRequest)) *MockNodeServer_NodeStageVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.NodeStageVolumeRequest))
})
return _c
}
func (_c *MockNodeServer_NodeStageVolume_Call) Return(_a0 *csi.NodeStageVolumeResponse, _a1 error) *MockNodeServer_NodeStageVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockNodeServer_NodeStageVolume_Call) RunAndReturn(run func(context.Context, *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error)) *MockNodeServer_NodeStageVolume_Call {
_c.Call.Return(run)
return _c
}
// NodeUnpublishVolume provides a mock function with given fields: _a0, _a1
func (_m *MockNodeServer) NodeUnpublishVolume(_a0 context.Context, _a1 *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for NodeUnpublishVolume")
}
var r0 *csi.NodeUnpublishVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeUnpublishVolumeRequest) *csi.NodeUnpublishVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.NodeUnpublishVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.NodeUnpublishVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockNodeServer_NodeUnpublishVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NodeUnpublishVolume'
type MockNodeServer_NodeUnpublishVolume_Call struct {
*mock.Call
}
// NodeUnpublishVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.NodeUnpublishVolumeRequest
func (_e *MockNodeServer_Expecter) NodeUnpublishVolume(_a0 interface{}, _a1 interface{}) *MockNodeServer_NodeUnpublishVolume_Call {
return &MockNodeServer_NodeUnpublishVolume_Call{Call: _e.mock.On("NodeUnpublishVolume", _a0, _a1)}
}
func (_c *MockNodeServer_NodeUnpublishVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.NodeUnpublishVolumeRequest)) *MockNodeServer_NodeUnpublishVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.NodeUnpublishVolumeRequest))
})
return _c
}
func (_c *MockNodeServer_NodeUnpublishVolume_Call) Return(_a0 *csi.NodeUnpublishVolumeResponse, _a1 error) *MockNodeServer_NodeUnpublishVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockNodeServer_NodeUnpublishVolume_Call) RunAndReturn(run func(context.Context, *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error)) *MockNodeServer_NodeUnpublishVolume_Call {
_c.Call.Return(run)
return _c
}
// NodeUnstageVolume provides a mock function with given fields: _a0, _a1
func (_m *MockNodeServer) NodeUnstageVolume(_a0 context.Context, _a1 *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for NodeUnstageVolume")
}
var r0 *csi.NodeUnstageVolumeResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *csi.NodeUnstageVolumeRequest) *csi.NodeUnstageVolumeResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*csi.NodeUnstageVolumeResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *csi.NodeUnstageVolumeRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockNodeServer_NodeUnstageVolume_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NodeUnstageVolume'
type MockNodeServer_NodeUnstageVolume_Call struct {
*mock.Call
}
// NodeUnstageVolume is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *csi.NodeUnstageVolumeRequest
func (_e *MockNodeServer_Expecter) NodeUnstageVolume(_a0 interface{}, _a1 interface{}) *MockNodeServer_NodeUnstageVolume_Call {
return &MockNodeServer_NodeUnstageVolume_Call{Call: _e.mock.On("NodeUnstageVolume", _a0, _a1)}
}
func (_c *MockNodeServer_NodeUnstageVolume_Call) Run(run func(_a0 context.Context, _a1 *csi.NodeUnstageVolumeRequest)) *MockNodeServer_NodeUnstageVolume_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*csi.NodeUnstageVolumeRequest))
})
return _c
}
func (_c *MockNodeServer_NodeUnstageVolume_Call) Return(_a0 *csi.NodeUnstageVolumeResponse, _a1 error) *MockNodeServer_NodeUnstageVolume_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockNodeServer_NodeUnstageVolume_Call) RunAndReturn(run func(context.Context, *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error)) *MockNodeServer_NodeUnstageVolume_Call {
_c.Call.Return(run)
return _c
}
// NewMockNodeServer creates a new instance of MockNodeServer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockNodeServer(t interface {
mock.TestingT
Cleanup(func())
}) *MockNodeServer {
mock := &MockNodeServer{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -62,6 +62,7 @@ import (
"k8s.io/kubernetes/pkg/kubeapiserver/options"
"k8s.io/kubernetes/test/integration/framework"
utilsoidc "k8s.io/kubernetes/test/utils/oidc"
"k8s.io/kubernetes/test/utils/oidc/handlers"
utilsnet "k8s.io/utils/net"
)
@ -170,7 +171,7 @@ jwt:
apiServer = startTestAPIServerForOIDC(t, apiServerOIDCConfig{oidcURL: oidcServer.URL(), oidcClientID: defaultOIDCClientID,
oidcCAFilePath: caFilePath, oidcUsernamePrefix: defaultOIDCUsernamePrefix, oidcUsernameClaim: "user"}, &signingPrivateKey.PublicKey)
}
oidcServer.JwksHandler().EXPECT().KeySet().AnyTimes().DoAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, publicKey))
oidcServer.JwksHandler().EXPECT().KeySet().RunAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, publicKey)).Maybe()
adminClient := kubernetes.NewForConfigOrDie(apiServer.ClientConfig)
configureRBAC(t, adminClient, defaultRole, defaultRoleBinding)
@ -178,7 +179,7 @@ jwt:
return oidcServer, apiServer, signingPrivateKey, caCertContent, caFilePath
}, configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
idTokenLifetime := time.Second * 1200
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
// This asserts the minimum valid claims for an ID token required by the authenticator.
@ -191,7 +192,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
},
configureClient: configureClientFetchingOIDCCredentials,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -213,7 +214,7 @@ jwt:
name: "wrong client ID",
configureInfrastructure: configureTestInfrastructure[*rsa.PrivateKey, *rsa.PublicKey],
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, _ *rsa.PrivateKey) {
oidcServer.TokenHandler().EXPECT().Token().Times(2).Return(utilsoidc.Token{}, utilsoidc.ErrBadClientID)
oidcServer.TokenHandler().EXPECT().Token().Times(2).Return(handlers.Token{}, utilsoidc.ErrBadClientID)
},
configureClient: configureClientWithEmptyIDToken,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -249,7 +250,7 @@ jwt:
configureInfrastructure: configureTestInfrastructure[*rsa.PrivateKey, *rsa.PublicKey],
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
configureOIDCServerToReturnExpiredIDToken(t, 1, oidcServer, signingPrivateKey)
oidcServer.TokenHandler().EXPECT().Token().Times(1).Return(utilsoidc.Token{
oidcServer.TokenHandler().EXPECT().Token().Times(1).Return(handlers.Token{
IDToken: "",
AccessToken: defaultStubAccessToken,
RefreshToken: defaultStubRefreshToken,
@ -308,12 +309,12 @@ jwt:
anotherSigningPrivateKey, _ := keyFunc(t)
oidcServer.JwksHandler().EXPECT().KeySet().AnyTimes().DoAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, &anotherSigningPrivateKey.PublicKey))
oidcServer.JwksHandler().EXPECT().KeySet().RunAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, &anotherSigningPrivateKey.PublicKey)).Maybe()
return oidcServer, apiServer, signingPrivateKey, caCertContent, caFilePath
},
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -324,7 +325,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
},
configureClient: configureClientFetchingOIDCCredentials,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -369,12 +370,12 @@ jwt:
&signingPrivateKey.PublicKey)
}
oidcServer.JwksHandler().EXPECT().KeySet().AnyTimes().DoAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, &signingPrivateKey.PublicKey))
oidcServer.JwksHandler().EXPECT().KeySet().RunAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, &signingPrivateKey.PublicKey)).Maybe()
return oidcServer, apiServer, signingPrivateKey, caCertContent, caFilePath
},
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -385,7 +386,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
},
configureClient: configureClientFetchingOIDCCredentials,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -414,7 +415,7 @@ jwt:
configureInfrastructure: configureTestInfrastructure[*ecdsa.PrivateKey, *ecdsa.PublicKey],
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *ecdsa.PrivateKey) {
idTokenLifetime := time.Second * 1200
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -425,7 +426,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
},
configureClient: configureClientFetchingOIDCCredentials,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -511,7 +512,7 @@ func TestUpdatingRefreshTokenInCaseOfExpiredIDToken(t *testing.T) {
{
name: "cache returns stale client if refresh token is not updated in config",
configureUpdatingTokenBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -522,7 +523,7 @@ func TestUpdatingRefreshTokenInCaseOfExpiredIDToken(t *testing.T) {
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
configureOIDCServerToReturnExpiredRefreshTokenErrorOnTryingToUpdateIDToken(oidcServer)
},
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -614,7 +615,7 @@ jwt:
configureInfrastructure: configureTestInfrastructure[*rsa.PrivateKey, *rsa.PublicKey],
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
idTokenLifetime := time.Second * 1200
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -625,7 +626,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
},
configureClient: configureClientFetchingOIDCCredentials,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -661,7 +662,7 @@ jwt:
configureInfrastructure: configureTestInfrastructure[*rsa.PrivateKey, *rsa.PublicKey],
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
idTokenLifetime := time.Second * 1200
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -674,7 +675,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
},
configureClient: configureClientFetchingOIDCCredentials,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -711,7 +712,7 @@ jwt:
configureInfrastructure: configureTestInfrastructure[*rsa.PrivateKey, *rsa.PublicKey],
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
idTokenLifetime := time.Second * 1200
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -723,7 +724,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
},
configureClient: configureClientFetchingOIDCCredentials,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -761,7 +762,7 @@ jwt:
configureInfrastructure: configureTestInfrastructure[*rsa.PrivateKey, *rsa.PublicKey],
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
idTokenLifetime := time.Second * 1200
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -773,7 +774,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
},
configureClient: configureClientFetchingOIDCCredentials,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -813,7 +814,7 @@ jwt:
configureInfrastructure: configureTestInfrastructure[*rsa.PrivateKey, *rsa.PublicKey],
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
idTokenLifetime := time.Second * 1200
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -825,7 +826,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
},
configureClient: configureClientFetchingOIDCCredentials,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -865,7 +866,7 @@ jwt:
configureInfrastructure: configureTestInfrastructure[*rsa.PrivateKey, *rsa.PublicKey],
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
idTokenLifetime := time.Second * 1200
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -878,7 +879,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
},
configureClient: configureClientFetchingOIDCCredentials,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -914,7 +915,7 @@ jwt:
configureInfrastructure: configureTestInfrastructure[*rsa.PrivateKey, *rsa.PublicKey],
configureOIDCServerBehaviour: func(t *testing.T, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
idTokenLifetime := time.Second * 1200
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -926,7 +927,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
},
configureClient: configureClientFetchingOIDCCredentials,
assertErrFn: func(t *testing.T, errorToCheck error) {
@ -1420,7 +1421,7 @@ func configureBasicTestInfrastructure[K utilsoidc.JosePrivateKey, L utilsoidc.Jo
oidcServer, apiServer, signingPrivateKey, caCertContent, caFilePath := configureTestInfrastructure(t, fn, keyFunc)
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -1431,7 +1432,7 @@ func configureBasicTestInfrastructure[K utilsoidc.JosePrivateKey, L utilsoidc.Jo
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
return oidcServer, apiServer, caCertContent, caFilePath
}
@ -1500,12 +1501,12 @@ jwt:
message: "the hd claim must be set to example.com"
`, tt.issuerURL, discoveryURL, indentCertificateAuthority(string(caCertContent)))
oidcServer.JwksHandler().EXPECT().KeySet().AnyTimes().DoAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, publicKey))
oidcServer.JwksHandler().EXPECT().KeySet().RunAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, publicKey)).Maybe()
apiServer := startTestAPIServerForOIDC(t, apiServerOIDCConfig{authenticationConfigYAML: authenticationConfig}, publicKey)
idTokenLifetime := time.Second * 1200
oidcServer.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
map[string]interface{}{
@ -1517,7 +1518,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
tokenURL, err := oidcServer.TokenURL()
require.NoError(t, err)
@ -1579,13 +1580,13 @@ jwt:
expression: "claims.uid"
`, oidcServer1.URL(), indentCertificateAuthority(string(caCertContent1)), oidcServer2.URL(), indentCertificateAuthority(string(caCertContent2)))
oidcServer1.JwksHandler().EXPECT().KeySet().AnyTimes().DoAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, publicKey1))
oidcServer2.JwksHandler().EXPECT().KeySet().AnyTimes().DoAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, publicKey2))
oidcServer1.JwksHandler().EXPECT().KeySet().RunAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, publicKey1)).Maybe()
oidcServer2.JwksHandler().EXPECT().KeySet().RunAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, publicKey2)).Maybe()
apiServer := startTestAPIServerForOIDC(t, apiServerOIDCConfig{authenticationConfigYAML: authenticationConfig}, publicKey1)
idTokenLifetime := time.Second * 1200
oidcServer1.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer1.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey1,
map[string]interface{}{
@ -1597,9 +1598,9 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
oidcServer2.TokenHandler().EXPECT().Token().Times(1).DoAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
oidcServer2.TokenHandler().EXPECT().Token().RunAndReturn(utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey2,
map[string]interface{}{
@ -1613,7 +1614,7 @@ jwt:
},
defaultStubAccessToken,
defaultStubRefreshToken,
))
)).Times(1)
tokenURL1, err := oidcServer1.TokenURL()
require.NoError(t, err)
@ -1681,7 +1682,7 @@ func configureTestInfrastructure[K utilsoidc.JosePrivateKey, L utilsoidc.JosePub
apiServer = startTestAPIServerForOIDC(t, apiServerOIDCConfig{oidcURL: oidcServer.URL(), oidcClientID: defaultOIDCClientID, oidcCAFilePath: caFilePath, oidcUsernamePrefix: defaultOIDCUsernamePrefix}, publicKey)
}
oidcServer.JwksHandler().EXPECT().KeySet().AnyTimes().DoAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, publicKey))
oidcServer.JwksHandler().EXPECT().KeySet().RunAndReturn(utilsoidc.DefaultJwksHandlerBehavior(t, publicKey)).Maybe()
adminClient := kubernetes.NewForConfigOrDie(apiServer.ClientConfig)
configureRBAC(t, adminClient, defaultRole, defaultRoleBinding)
@ -1791,7 +1792,7 @@ func fetchOIDCCredentials(t *testing.T, oidcTokenURL string, caCertContent []byt
},
}}
token := new(utilsoidc.Token)
token := new(handlers.Token)
resp, err := client.Do(req)
require.NoError(t, err)
@ -1817,7 +1818,7 @@ func fetchExpiredToken(t *testing.T, oidcServer *utilsoidc.TestServer, caCertCon
func configureOIDCServerToReturnExpiredIDToken(t *testing.T, returningExpiredTokenTimes int, oidcServer *utilsoidc.TestServer, signingPrivateKey *rsa.PrivateKey) {
t.Helper()
oidcServer.TokenHandler().EXPECT().Token().Times(returningExpiredTokenTimes).DoAndReturn(func() (utilsoidc.Token, error) {
oidcServer.TokenHandler().EXPECT().Token().RunAndReturn(func() (handlers.Token, error) {
token, err := utilsoidc.TokenHandlerBehaviorReturningPredefinedJWT(
t,
signingPrivateKey,
@ -1831,11 +1832,11 @@ func configureOIDCServerToReturnExpiredIDToken(t *testing.T, returningExpiredTok
defaultStubRefreshToken,
)()
return token, err
})
}).Times(returningExpiredTokenTimes)
}
func configureOIDCServerToReturnExpiredRefreshTokenErrorOnTryingToUpdateIDToken(oidcServer *utilsoidc.TestServer) {
oidcServer.TokenHandler().EXPECT().Token().Times(2).Return(utilsoidc.Token{}, utilsoidc.ErrRefreshTokenExpired)
oidcServer.TokenHandler().EXPECT().Token().Times(2).Return(handlers.Token{}, utilsoidc.ErrRefreshTokenExpired)
}
func generateCert(t *testing.T) (cert, key []byte, certFilePath, keyFilePath string) {

View File

@ -1,108 +0,0 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: handlers.go
//
// Generated by this command:
//
// mockgen -source=handlers.go -destination=handlers.mock.go -package=oidc TokenHandler JWKsHandler
//
// Package oidc is a generated GoMock package.
package oidc
import (
reflect "reflect"
gomock "go.uber.org/mock/gomock"
jose "gopkg.in/square/go-jose.v2"
)
// MockTokenHandler is a mock of TokenHandler interface.
type MockTokenHandler struct {
ctrl *gomock.Controller
recorder *MockTokenHandlerMockRecorder
}
// MockTokenHandlerMockRecorder is the mock recorder for MockTokenHandler.
type MockTokenHandlerMockRecorder struct {
mock *MockTokenHandler
}
// NewMockTokenHandler creates a new mock instance.
func NewMockTokenHandler(ctrl *gomock.Controller) *MockTokenHandler {
mock := &MockTokenHandler{ctrl: ctrl}
mock.recorder = &MockTokenHandlerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockTokenHandler) EXPECT() *MockTokenHandlerMockRecorder {
return m.recorder
}
// Token mocks base method.
func (m *MockTokenHandler) Token() (Token, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Token")
ret0, _ := ret[0].(Token)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Token indicates an expected call of Token.
func (mr *MockTokenHandlerMockRecorder) Token() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Token", reflect.TypeOf((*MockTokenHandler)(nil).Token))
}
// MockJWKsHandler is a mock of JWKsHandler interface.
type MockJWKsHandler struct {
ctrl *gomock.Controller
recorder *MockJWKsHandlerMockRecorder
}
// MockJWKsHandlerMockRecorder is the mock recorder for MockJWKsHandler.
type MockJWKsHandlerMockRecorder struct {
mock *MockJWKsHandler
}
// NewMockJWKsHandler creates a new mock instance.
func NewMockJWKsHandler(ctrl *gomock.Controller) *MockJWKsHandler {
mock := &MockJWKsHandler{ctrl: ctrl}
mock.recorder = &MockJWKsHandlerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockJWKsHandler) EXPECT() *MockJWKsHandlerMockRecorder {
return m.recorder
}
// KeySet mocks base method.
func (m *MockJWKsHandler) KeySet() jose.JSONWebKeySet {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "KeySet")
ret0, _ := ret[0].(jose.JSONWebKeySet)
return ret0
}
// KeySet indicates an expected call of KeySet.
func (mr *MockJWKsHandlerMockRecorder) KeySet() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "KeySet", reflect.TypeOf((*MockJWKsHandler)(nil).KeySet))
}

View File

@ -0,0 +1,13 @@
---
dir: .
filename: mock_{{.InterfaceName | snakecase}}.go
boilerplate-file: ../../../../hack/boilerplate/boilerplate.generatego.txt
inpackage: true
with-expecter: true
packages:
k8s.io/kubernetes/test/utils/oidc/handlers:
interfaces:
JWKsHandler:
config:
filename: mock_jwks_handler.go
TokenHandler:

View File

@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate mockgen -source=handlers.go -destination=handlers.mock.go -package=oidc TokenHandler JWKsHandler
//go:generate mockery
package oidc
package handlers
import (
"gopkg.in/square/go-jose.v2"

View File

@ -0,0 +1,112 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package handlers
import (
mock "github.com/stretchr/testify/mock"
jose "gopkg.in/square/go-jose.v2"
)
// MockJWKsHandler is an autogenerated mock type for the JWKsHandler type
type MockJWKsHandler struct {
mock.Mock
}
type MockJWKsHandler_Expecter struct {
mock *mock.Mock
}
func (_m *MockJWKsHandler) EXPECT() *MockJWKsHandler_Expecter {
return &MockJWKsHandler_Expecter{mock: &_m.Mock}
}
// KeySet provides a mock function with given fields:
func (_m *MockJWKsHandler) KeySet() jose.JSONWebKeySet {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for KeySet")
}
var r0 jose.JSONWebKeySet
if rf, ok := ret.Get(0).(func() jose.JSONWebKeySet); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(jose.JSONWebKeySet)
}
return r0
}
// MockJWKsHandler_KeySet_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'KeySet'
type MockJWKsHandler_KeySet_Call struct {
*mock.Call
}
// KeySet is a helper method to define mock.On call
func (_e *MockJWKsHandler_Expecter) KeySet() *MockJWKsHandler_KeySet_Call {
return &MockJWKsHandler_KeySet_Call{Call: _e.mock.On("KeySet")}
}
func (_c *MockJWKsHandler_KeySet_Call) Run(run func()) *MockJWKsHandler_KeySet_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockJWKsHandler_KeySet_Call) Return(_a0 jose.JSONWebKeySet) *MockJWKsHandler_KeySet_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockJWKsHandler_KeySet_Call) RunAndReturn(run func() jose.JSONWebKeySet) *MockJWKsHandler_KeySet_Call {
_c.Call.Return(run)
return _c
}
// NewMockJWKsHandler creates a new instance of MockJWKsHandler. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockJWKsHandler(t interface {
mock.TestingT
Cleanup(func())
}) *MockJWKsHandler {
mock := &MockJWKsHandler{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -0,0 +1,119 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by mockery v2.40.3. DO NOT EDIT.
package handlers
import mock "github.com/stretchr/testify/mock"
// MockTokenHandler is an autogenerated mock type for the TokenHandler type
type MockTokenHandler struct {
mock.Mock
}
type MockTokenHandler_Expecter struct {
mock *mock.Mock
}
func (_m *MockTokenHandler) EXPECT() *MockTokenHandler_Expecter {
return &MockTokenHandler_Expecter{mock: &_m.Mock}
}
// Token provides a mock function with given fields:
func (_m *MockTokenHandler) Token() (Token, error) {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Token")
}
var r0 Token
var r1 error
if rf, ok := ret.Get(0).(func() (Token, error)); ok {
return rf()
}
if rf, ok := ret.Get(0).(func() Token); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(Token)
}
if rf, ok := ret.Get(1).(func() error); ok {
r1 = rf()
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockTokenHandler_Token_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Token'
type MockTokenHandler_Token_Call struct {
*mock.Call
}
// Token is a helper method to define mock.On call
func (_e *MockTokenHandler_Expecter) Token() *MockTokenHandler_Token_Call {
return &MockTokenHandler_Token_Call{Call: _e.mock.On("Token")}
}
func (_c *MockTokenHandler_Token_Call) Run(run func()) *MockTokenHandler_Token_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockTokenHandler_Token_Call) Return(_a0 Token, _a1 error) *MockTokenHandler_Token_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockTokenHandler_Token_Call) RunAndReturn(run func() (Token, error)) *MockTokenHandler_Token_Call {
_c.Call.Return(run)
return _c
}
// NewMockTokenHandler creates a new instance of MockTokenHandler. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockTokenHandler(t interface {
mock.TestingT
Cleanup(func())
}) *MockTokenHandler {
mock := &MockTokenHandler{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@ -32,8 +32,8 @@ import (
"testing"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"gopkg.in/square/go-jose.v2"
"k8s.io/kubernetes/test/utils/oidc/handlers"
)
const (
@ -50,17 +50,17 @@ var (
type TestServer struct {
httpServer *httptest.Server
tokenHandler *MockTokenHandler
jwksHandler *MockJWKsHandler
tokenHandler *handlers.MockTokenHandler
jwksHandler *handlers.MockJWKsHandler
}
// JwksHandler is getter of JSON Web Key Sets handler
func (ts *TestServer) JwksHandler() *MockJWKsHandler {
func (ts *TestServer) JwksHandler() *handlers.MockJWKsHandler {
return ts.jwksHandler
}
// TokenHandler is getter of JWT token handler
func (ts *TestServer) TokenHandler() *MockTokenHandler {
func (ts *TestServer) TokenHandler() *handlers.MockTokenHandler {
return ts.tokenHandler
}
@ -98,17 +98,14 @@ func BuildAndRunTestServer(t *testing.T, caPath, caKeyPath, issuerOverride strin
}
httpServer.StartTLS()
mockCtrl := gomock.NewController(t)
t.Cleanup(func() {
mockCtrl.Finish()
httpServer.Close()
})
oidcServer := &TestServer{
httpServer: httpServer,
tokenHandler: NewMockTokenHandler(mockCtrl),
jwksHandler: NewMockJWKsHandler(mockCtrl),
tokenHandler: handlers.NewMockTokenHandler(t),
jwksHandler: handlers.NewMockJWKsHandler(t),
}
issuer := httpServer.URL
@ -197,10 +194,10 @@ func TokenHandlerBehaviorReturningPredefinedJWT[K JosePrivateKey](
t *testing.T,
privateKey K,
claims map[string]interface{}, accessToken, refreshToken string,
) func() (Token, error) {
) func() (handlers.Token, error) {
t.Helper()
return func() (Token, error) {
return func() (handlers.Token, error) {
signer, err := jose.NewSigner(jose.SigningKey{Algorithm: GetSignatureAlgorithm(privateKey), Key: privateKey}, nil)
require.NoError(t, err)
@ -212,7 +209,7 @@ func TokenHandlerBehaviorReturningPredefinedJWT[K JosePrivateKey](
idToken, err := idTokenSignature.CompactSerialize()
require.NoError(t, err)
return Token{
return handlers.Token{
IDToken: idToken,
AccessToken: accessToken,
RefreshToken: refreshToken,

21
vendor/github.com/stretchr/objx/.codeclimate.yml generated vendored Normal file
View File

@ -0,0 +1,21 @@
engines:
gofmt:
enabled: true
golint:
enabled: true
govet:
enabled: true
exclude_patterns:
- ".github/"
- "vendor/"
- "codegen/"
- "*.yml"
- ".*.yml"
- "*.md"
- "Gopkg.*"
- "doc.go"
- "type_specific_codegen_test.go"
- "type_specific_codegen.go"
- ".gitignore"
- "LICENSE"

11
vendor/github.com/stretchr/objx/.gitignore generated vendored Normal file
View File

@ -0,0 +1,11 @@
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

22
vendor/github.com/stretchr/objx/LICENSE generated vendored Normal file
View File

@ -0,0 +1,22 @@
The MIT License
Copyright (c) 2014 Stretchr, Inc.
Copyright (c) 2017-2018 objx contributors
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 the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

80
vendor/github.com/stretchr/objx/README.md generated vendored Normal file
View File

@ -0,0 +1,80 @@
# Objx
[![Build Status](https://travis-ci.org/stretchr/objx.svg?branch=master)](https://travis-ci.org/stretchr/objx)
[![Go Report Card](https://goreportcard.com/badge/github.com/stretchr/objx)](https://goreportcard.com/report/github.com/stretchr/objx)
[![Maintainability](https://api.codeclimate.com/v1/badges/1d64bc6c8474c2074f2b/maintainability)](https://codeclimate.com/github/stretchr/objx/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/1d64bc6c8474c2074f2b/test_coverage)](https://codeclimate.com/github/stretchr/objx/test_coverage)
[![Sourcegraph](https://sourcegraph.com/github.com/stretchr/objx/-/badge.svg)](https://sourcegraph.com/github.com/stretchr/objx)
[![GoDoc](https://godoc.org/github.com/stretchr/objx?status.svg)](https://godoc.org/github.com/stretchr/objx)
Objx - Go package for dealing with maps, slices, JSON and other data.
Get started:
- Install Objx with [one line of code](#installation), or [update it with another](#staying-up-to-date)
- Check out the API Documentation http://godoc.org/github.com/stretchr/objx
## Overview
Objx provides the `objx.Map` type, which is a `map[string]interface{}` that exposes a powerful `Get` method (among others) that allows you to easily and quickly get access to data within the map, without having to worry too much about type assertions, missing data, default values etc.
### Pattern
Objx uses a preditable pattern to make access data from within `map[string]interface{}` easy. Call one of the `objx.` functions to create your `objx.Map` to get going:
m, err := objx.FromJSON(json)
NOTE: Any methods or functions with the `Must` prefix will panic if something goes wrong, the rest will be optimistic and try to figure things out without panicking.
Use `Get` to access the value you're interested in. You can use dot and array
notation too:
m.Get("places[0].latlng")
Once you have sought the `Value` you're interested in, you can use the `Is*` methods to determine its type.
if m.Get("code").IsStr() { // Your code... }
Or you can just assume the type, and use one of the strong type methods to extract the real value:
m.Get("code").Int()
If there's no value there (or if it's the wrong type) then a default value will be returned, or you can be explicit about the default value.
Get("code").Int(-1)
If you're dealing with a slice of data as a value, Objx provides many useful methods for iterating, manipulating and selecting that data. You can find out more by exploring the index below.
### Reading data
A simple example of how to use Objx:
// Use MustFromJSON to make an objx.Map from some JSON
m := objx.MustFromJSON(`{"name": "Mat", "age": 30}`)
// Get the details
name := m.Get("name").Str()
age := m.Get("age").Int()
// Get their nickname (or use their name if they don't have one)
nickname := m.Get("nickname").Str(name)
### Ranging
Since `objx.Map` is a `map[string]interface{}` you can treat it as such. For example, to `range` the data, do what you would expect:
m := objx.MustFromJSON(json)
for key, value := range m {
// Your code...
}
## Installation
To install Objx, use go get:
go get github.com/stretchr/objx
### Staying up to date
To update Objx to the latest version, run:
go get -u github.com/stretchr/objx
### Supported go versions
We support the lastest three major Go versions, which are 1.10, 1.11 and 1.12 at the moment.
## Contributing
Please feel free to submit issues, fork the repository and send pull requests!

30
vendor/github.com/stretchr/objx/Taskfile.yml generated vendored Normal file
View File

@ -0,0 +1,30 @@
version: '2'
env:
GOFLAGS: -mod=vendor
tasks:
default:
deps: [test]
lint:
desc: Checks code style
cmds:
- gofmt -d -s *.go
- go vet ./...
silent: true
lint-fix:
desc: Fixes code style
cmds:
- gofmt -w -s *.go
test:
desc: Runs go tests
cmds:
- go test -race ./...
test-coverage:
desc: Runs go tests and calculates test coverage
cmds:
- go test -race -coverprofile=c.out ./...

197
vendor/github.com/stretchr/objx/accessors.go generated vendored Normal file
View File

@ -0,0 +1,197 @@
package objx
import (
"reflect"
"regexp"
"strconv"
"strings"
)
const (
// PathSeparator is the character used to separate the elements
// of the keypath.
//
// For example, `location.address.city`
PathSeparator string = "."
// arrayAccesRegexString is the regex used to extract the array number
// from the access path
arrayAccesRegexString = `^(.+)\[([0-9]+)\]$`
// mapAccessRegexString is the regex used to extract the map key
// from the access path
mapAccessRegexString = `^([^\[]*)\[([^\]]+)\](.*)$`
)
// arrayAccesRegex is the compiled arrayAccesRegexString
var arrayAccesRegex = regexp.MustCompile(arrayAccesRegexString)
// mapAccessRegex is the compiled mapAccessRegexString
var mapAccessRegex = regexp.MustCompile(mapAccessRegexString)
// Get gets the value using the specified selector and
// returns it inside a new Obj object.
//
// If it cannot find the value, Get will return a nil
// value inside an instance of Obj.
//
// Get can only operate directly on map[string]interface{} and []interface.
//
// Example
//
// To access the title of the third chapter of the second book, do:
//
// o.Get("books[1].chapters[2].title")
func (m Map) Get(selector string) *Value {
rawObj := access(m, selector, nil, false)
return &Value{data: rawObj}
}
// Set sets the value using the specified selector and
// returns the object on which Set was called.
//
// Set can only operate directly on map[string]interface{} and []interface
//
// Example
//
// To set the title of the third chapter of the second book, do:
//
// o.Set("books[1].chapters[2].title","Time to Go")
func (m Map) Set(selector string, value interface{}) Map {
access(m, selector, value, true)
return m
}
// getIndex returns the index, which is hold in s by two braches.
// It also returns s withour the index part, e.g. name[1] will return (1, name).
// If no index is found, -1 is returned
func getIndex(s string) (int, string) {
arrayMatches := arrayAccesRegex.FindStringSubmatch(s)
if len(arrayMatches) > 0 {
// Get the key into the map
selector := arrayMatches[1]
// Get the index into the array at the key
// We know this cannt fail because arrayMatches[2] is an int for sure
index, _ := strconv.Atoi(arrayMatches[2])
return index, selector
}
return -1, s
}
// getKey returns the key which is held in s by two brackets.
// It also returns the next selector.
func getKey(s string) (string, string) {
selSegs := strings.SplitN(s, PathSeparator, 2)
thisSel := selSegs[0]
nextSel := ""
if len(selSegs) > 1 {
nextSel = selSegs[1]
}
mapMatches := mapAccessRegex.FindStringSubmatch(s)
if len(mapMatches) > 0 {
if _, err := strconv.Atoi(mapMatches[2]); err != nil {
thisSel = mapMatches[1]
nextSel = "[" + mapMatches[2] + "]" + mapMatches[3]
if thisSel == "" {
thisSel = mapMatches[2]
nextSel = mapMatches[3]
}
if nextSel == "" {
selSegs = []string{"", ""}
} else if nextSel[0] == '.' {
nextSel = nextSel[1:]
}
}
}
return thisSel, nextSel
}
// access accesses the object using the selector and performs the
// appropriate action.
func access(current interface{}, selector string, value interface{}, isSet bool) interface{} {
thisSel, nextSel := getKey(selector)
indexes := []int{}
for strings.Contains(thisSel, "[") {
prevSel := thisSel
index := -1
index, thisSel = getIndex(thisSel)
indexes = append(indexes, index)
if prevSel == thisSel {
break
}
}
if curMap, ok := current.(Map); ok {
current = map[string]interface{}(curMap)
}
// get the object in question
switch current.(type) {
case map[string]interface{}:
curMSI := current.(map[string]interface{})
if nextSel == "" && isSet {
curMSI[thisSel] = value
return nil
}
_, ok := curMSI[thisSel].(map[string]interface{})
if !ok {
_, ok = curMSI[thisSel].(Map)
}
if (curMSI[thisSel] == nil || !ok) && len(indexes) == 0 && isSet {
curMSI[thisSel] = map[string]interface{}{}
}
current = curMSI[thisSel]
default:
current = nil
}
// do we need to access the item of an array?
if len(indexes) > 0 {
num := len(indexes)
for num > 0 {
num--
index := indexes[num]
indexes = indexes[:num]
if array, ok := interSlice(current); ok {
if index < len(array) {
current = array[index]
} else {
current = nil
break
}
}
}
}
if nextSel != "" {
current = access(current, nextSel, value, isSet)
}
return current
}
func interSlice(slice interface{}) ([]interface{}, bool) {
if array, ok := slice.([]interface{}); ok {
return array, ok
}
s := reflect.ValueOf(slice)
if s.Kind() != reflect.Slice {
return nil, false
}
ret := make([]interface{}, s.Len())
for i := 0; i < s.Len(); i++ {
ret[i] = s.Index(i).Interface()
}
return ret, true
}

280
vendor/github.com/stretchr/objx/conversions.go generated vendored Normal file
View File

@ -0,0 +1,280 @@
package objx
import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"net/url"
"strconv"
)
// SignatureSeparator is the character that is used to
// separate the Base64 string from the security signature.
const SignatureSeparator = "_"
// URLValuesSliceKeySuffix is the character that is used to
// specify a suffic for slices parsed by URLValues.
// If the suffix is set to "[i]", then the index of the slice
// is used in place of i
// Ex: Suffix "[]" would have the form a[]=b&a[]=c
// OR Suffix "[i]" would have the form a[0]=b&a[1]=c
// OR Suffix "" would have the form a=b&a=c
var urlValuesSliceKeySuffix = "[]"
const (
URLValuesSliceKeySuffixEmpty = ""
URLValuesSliceKeySuffixArray = "[]"
URLValuesSliceKeySuffixIndex = "[i]"
)
// SetURLValuesSliceKeySuffix sets the character that is used to
// specify a suffic for slices parsed by URLValues.
// If the suffix is set to "[i]", then the index of the slice
// is used in place of i
// Ex: Suffix "[]" would have the form a[]=b&a[]=c
// OR Suffix "[i]" would have the form a[0]=b&a[1]=c
// OR Suffix "" would have the form a=b&a=c
func SetURLValuesSliceKeySuffix(s string) error {
if s == URLValuesSliceKeySuffixEmpty || s == URLValuesSliceKeySuffixArray || s == URLValuesSliceKeySuffixIndex {
urlValuesSliceKeySuffix = s
return nil
}
return errors.New("objx: Invalid URLValuesSliceKeySuffix provided.")
}
// JSON converts the contained object to a JSON string
// representation
func (m Map) JSON() (string, error) {
for k, v := range m {
m[k] = cleanUp(v)
}
result, err := json.Marshal(m)
if err != nil {
err = errors.New("objx: JSON encode failed with: " + err.Error())
}
return string(result), err
}
func cleanUpInterfaceArray(in []interface{}) []interface{} {
result := make([]interface{}, len(in))
for i, v := range in {
result[i] = cleanUp(v)
}
return result
}
func cleanUpInterfaceMap(in map[interface{}]interface{}) Map {
result := Map{}
for k, v := range in {
result[fmt.Sprintf("%v", k)] = cleanUp(v)
}
return result
}
func cleanUpStringMap(in map[string]interface{}) Map {
result := Map{}
for k, v := range in {
result[k] = cleanUp(v)
}
return result
}
func cleanUpMSIArray(in []map[string]interface{}) []Map {
result := make([]Map, len(in))
for i, v := range in {
result[i] = cleanUpStringMap(v)
}
return result
}
func cleanUpMapArray(in []Map) []Map {
result := make([]Map, len(in))
for i, v := range in {
result[i] = cleanUpStringMap(v)
}
return result
}
func cleanUp(v interface{}) interface{} {
switch v := v.(type) {
case []interface{}:
return cleanUpInterfaceArray(v)
case []map[string]interface{}:
return cleanUpMSIArray(v)
case map[interface{}]interface{}:
return cleanUpInterfaceMap(v)
case Map:
return cleanUpStringMap(v)
case []Map:
return cleanUpMapArray(v)
default:
return v
}
}
// MustJSON converts the contained object to a JSON string
// representation and panics if there is an error
func (m Map) MustJSON() string {
result, err := m.JSON()
if err != nil {
panic(err.Error())
}
return result
}
// Base64 converts the contained object to a Base64 string
// representation of the JSON string representation
func (m Map) Base64() (string, error) {
var buf bytes.Buffer
jsonData, err := m.JSON()
if err != nil {
return "", err
}
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
_, _ = encoder.Write([]byte(jsonData))
_ = encoder.Close()
return buf.String(), nil
}
// MustBase64 converts the contained object to a Base64 string
// representation of the JSON string representation and panics
// if there is an error
func (m Map) MustBase64() string {
result, err := m.Base64()
if err != nil {
panic(err.Error())
}
return result
}
// SignedBase64 converts the contained object to a Base64 string
// representation of the JSON string representation and signs it
// using the provided key.
func (m Map) SignedBase64(key string) (string, error) {
base64, err := m.Base64()
if err != nil {
return "", err
}
sig := HashWithKey(base64, key)
return base64 + SignatureSeparator + sig, nil
}
// MustSignedBase64 converts the contained object to a Base64 string
// representation of the JSON string representation and signs it
// using the provided key and panics if there is an error
func (m Map) MustSignedBase64(key string) string {
result, err := m.SignedBase64(key)
if err != nil {
panic(err.Error())
}
return result
}
/*
URL Query
------------------------------------------------
*/
// URLValues creates a url.Values object from an Obj. This
// function requires that the wrapped object be a map[string]interface{}
func (m Map) URLValues() url.Values {
vals := make(url.Values)
m.parseURLValues(m, vals, "")
return vals
}
func (m Map) parseURLValues(queryMap Map, vals url.Values, key string) {
useSliceIndex := false
if urlValuesSliceKeySuffix == "[i]" {
useSliceIndex = true
}
for k, v := range queryMap {
val := &Value{data: v}
switch {
case val.IsObjxMap():
if key == "" {
m.parseURLValues(val.ObjxMap(), vals, k)
} else {
m.parseURLValues(val.ObjxMap(), vals, key+"["+k+"]")
}
case val.IsObjxMapSlice():
sliceKey := k
if key != "" {
sliceKey = key + "[" + k + "]"
}
if useSliceIndex {
for i, sv := range val.MustObjxMapSlice() {
sk := sliceKey + "[" + strconv.FormatInt(int64(i), 10) + "]"
m.parseURLValues(sv, vals, sk)
}
} else {
sliceKey = sliceKey + urlValuesSliceKeySuffix
for _, sv := range val.MustObjxMapSlice() {
m.parseURLValues(sv, vals, sliceKey)
}
}
case val.IsMSISlice():
sliceKey := k
if key != "" {
sliceKey = key + "[" + k + "]"
}
if useSliceIndex {
for i, sv := range val.MustMSISlice() {
sk := sliceKey + "[" + strconv.FormatInt(int64(i), 10) + "]"
m.parseURLValues(New(sv), vals, sk)
}
} else {
sliceKey = sliceKey + urlValuesSliceKeySuffix
for _, sv := range val.MustMSISlice() {
m.parseURLValues(New(sv), vals, sliceKey)
}
}
case val.IsStrSlice(), val.IsBoolSlice(),
val.IsFloat32Slice(), val.IsFloat64Slice(),
val.IsIntSlice(), val.IsInt8Slice(), val.IsInt16Slice(), val.IsInt32Slice(), val.IsInt64Slice(),
val.IsUintSlice(), val.IsUint8Slice(), val.IsUint16Slice(), val.IsUint32Slice(), val.IsUint64Slice():
sliceKey := k
if key != "" {
sliceKey = key + "[" + k + "]"
}
if useSliceIndex {
for i, sv := range val.StringSlice() {
sk := sliceKey + "[" + strconv.FormatInt(int64(i), 10) + "]"
vals.Set(sk, sv)
}
} else {
sliceKey = sliceKey + urlValuesSliceKeySuffix
vals[sliceKey] = val.StringSlice()
}
default:
if key == "" {
vals.Set(k, val.String())
} else {
vals.Set(key+"["+k+"]", val.String())
}
}
}
}
// URLQuery gets an encoded URL query representing the given
// Obj. This function requires that the wrapped object be a
// map[string]interface{}
func (m Map) URLQuery() (string, error) {
return m.URLValues().Encode(), nil
}

66
vendor/github.com/stretchr/objx/doc.go generated vendored Normal file
View File

@ -0,0 +1,66 @@
/*
Objx - Go package for dealing with maps, slices, JSON and other data.
Overview
Objx provides the `objx.Map` type, which is a `map[string]interface{}` that exposes
a powerful `Get` method (among others) that allows you to easily and quickly get
access to data within the map, without having to worry too much about type assertions,
missing data, default values etc.
Pattern
Objx uses a preditable pattern to make access data from within `map[string]interface{}` easy.
Call one of the `objx.` functions to create your `objx.Map` to get going:
m, err := objx.FromJSON(json)
NOTE: Any methods or functions with the `Must` prefix will panic if something goes wrong,
the rest will be optimistic and try to figure things out without panicking.
Use `Get` to access the value you're interested in. You can use dot and array
notation too:
m.Get("places[0].latlng")
Once you have sought the `Value` you're interested in, you can use the `Is*` methods to determine its type.
if m.Get("code").IsStr() { // Your code... }
Or you can just assume the type, and use one of the strong type methods to extract the real value:
m.Get("code").Int()
If there's no value there (or if it's the wrong type) then a default value will be returned,
or you can be explicit about the default value.
Get("code").Int(-1)
If you're dealing with a slice of data as a value, Objx provides many useful methods for iterating,
manipulating and selecting that data. You can find out more by exploring the index below.
Reading data
A simple example of how to use Objx:
// Use MustFromJSON to make an objx.Map from some JSON
m := objx.MustFromJSON(`{"name": "Mat", "age": 30}`)
// Get the details
name := m.Get("name").Str()
age := m.Get("age").Int()
// Get their nickname (or use their name if they don't have one)
nickname := m.Get("nickname").Str(name)
Ranging
Since `objx.Map` is a `map[string]interface{}` you can treat it as such.
For example, to `range` the data, do what you would expect:
m := objx.MustFromJSON(json)
for key, value := range m {
// Your code...
}
*/
package objx

215
vendor/github.com/stretchr/objx/map.go generated vendored Normal file
View File

@ -0,0 +1,215 @@
package objx
import (
"encoding/base64"
"encoding/json"
"errors"
"io/ioutil"
"net/url"
"strings"
)
// MSIConvertable is an interface that defines methods for converting your
// custom types to a map[string]interface{} representation.
type MSIConvertable interface {
// MSI gets a map[string]interface{} (msi) representing the
// object.
MSI() map[string]interface{}
}
// Map provides extended functionality for working with
// untyped data, in particular map[string]interface (msi).
type Map map[string]interface{}
// Value returns the internal value instance
func (m Map) Value() *Value {
return &Value{data: m}
}
// Nil represents a nil Map.
var Nil = New(nil)
// New creates a new Map containing the map[string]interface{} in the data argument.
// If the data argument is not a map[string]interface, New attempts to call the
// MSI() method on the MSIConvertable interface to create one.
func New(data interface{}) Map {
if _, ok := data.(map[string]interface{}); !ok {
if converter, ok := data.(MSIConvertable); ok {
data = converter.MSI()
} else {
return nil
}
}
return Map(data.(map[string]interface{}))
}
// MSI creates a map[string]interface{} and puts it inside a new Map.
//
// The arguments follow a key, value pattern.
//
//
// Returns nil if any key argument is non-string or if there are an odd number of arguments.
//
// Example
//
// To easily create Maps:
//
// m := objx.MSI("name", "Mat", "age", 29, "subobj", objx.MSI("active", true))
//
// // creates an Map equivalent to
// m := objx.Map{"name": "Mat", "age": 29, "subobj": objx.Map{"active": true}}
func MSI(keyAndValuePairs ...interface{}) Map {
newMap := Map{}
keyAndValuePairsLen := len(keyAndValuePairs)
if keyAndValuePairsLen%2 != 0 {
return nil
}
for i := 0; i < keyAndValuePairsLen; i = i + 2 {
key := keyAndValuePairs[i]
value := keyAndValuePairs[i+1]
// make sure the key is a string
keyString, keyStringOK := key.(string)
if !keyStringOK {
return nil
}
newMap[keyString] = value
}
return newMap
}
// ****** Conversion Constructors
// MustFromJSON creates a new Map containing the data specified in the
// jsonString.
//
// Panics if the JSON is invalid.
func MustFromJSON(jsonString string) Map {
o, err := FromJSON(jsonString)
if err != nil {
panic("objx: MustFromJSON failed with error: " + err.Error())
}
return o
}
// MustFromJSONSlice creates a new slice of Map containing the data specified in the
// jsonString. Works with jsons with a top level array
//
// Panics if the JSON is invalid.
func MustFromJSONSlice(jsonString string) []Map {
slice, err := FromJSONSlice(jsonString)
if err != nil {
panic("objx: MustFromJSONSlice failed with error: " + err.Error())
}
return slice
}
// FromJSON creates a new Map containing the data specified in the
// jsonString.
//
// Returns an error if the JSON is invalid.
func FromJSON(jsonString string) (Map, error) {
var m Map
err := json.Unmarshal([]byte(jsonString), &m)
if err != nil {
return Nil, err
}
return m, nil
}
// FromJSONSlice creates a new slice of Map containing the data specified in the
// jsonString. Works with jsons with a top level array
//
// Returns an error if the JSON is invalid.
func FromJSONSlice(jsonString string) ([]Map, error) {
var slice []Map
err := json.Unmarshal([]byte(jsonString), &slice)
if err != nil {
return nil, err
}
return slice, nil
}
// FromBase64 creates a new Obj containing the data specified
// in the Base64 string.
//
// The string is an encoded JSON string returned by Base64
func FromBase64(base64String string) (Map, error) {
decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(base64String))
decoded, err := ioutil.ReadAll(decoder)
if err != nil {
return nil, err
}
return FromJSON(string(decoded))
}
// MustFromBase64 creates a new Obj containing the data specified
// in the Base64 string and panics if there is an error.
//
// The string is an encoded JSON string returned by Base64
func MustFromBase64(base64String string) Map {
result, err := FromBase64(base64String)
if err != nil {
panic("objx: MustFromBase64 failed with error: " + err.Error())
}
return result
}
// FromSignedBase64 creates a new Obj containing the data specified
// in the Base64 string.
//
// The string is an encoded JSON string returned by SignedBase64
func FromSignedBase64(base64String, key string) (Map, error) {
parts := strings.Split(base64String, SignatureSeparator)
if len(parts) != 2 {
return nil, errors.New("objx: Signed base64 string is malformed")
}
sig := HashWithKey(parts[0], key)
if parts[1] != sig {
return nil, errors.New("objx: Signature for base64 data does not match")
}
return FromBase64(parts[0])
}
// MustFromSignedBase64 creates a new Obj containing the data specified
// in the Base64 string and panics if there is an error.
//
// The string is an encoded JSON string returned by Base64
func MustFromSignedBase64(base64String, key string) Map {
result, err := FromSignedBase64(base64String, key)
if err != nil {
panic("objx: MustFromSignedBase64 failed with error: " + err.Error())
}
return result
}
// FromURLQuery generates a new Obj by parsing the specified
// query.
//
// For queries with multiple values, the first value is selected.
func FromURLQuery(query string) (Map, error) {
vals, err := url.ParseQuery(query)
if err != nil {
return nil, err
}
m := Map{}
for k, vals := range vals {
m[k] = vals[0]
}
return m, nil
}
// MustFromURLQuery generates a new Obj by parsing the specified
// query.
//
// For queries with multiple values, the first value is selected.
//
// Panics if it encounters an error
func MustFromURLQuery(query string) Map {
o, err := FromURLQuery(query)
if err != nil {
panic("objx: MustFromURLQuery failed with error: " + err.Error())
}
return o
}

77
vendor/github.com/stretchr/objx/mutations.go generated vendored Normal file
View File

@ -0,0 +1,77 @@
package objx
// Exclude returns a new Map with the keys in the specified []string
// excluded.
func (m Map) Exclude(exclude []string) Map {
excluded := make(Map)
for k, v := range m {
if !contains(exclude, k) {
excluded[k] = v
}
}
return excluded
}
// Copy creates a shallow copy of the Obj.
func (m Map) Copy() Map {
copied := Map{}
for k, v := range m {
copied[k] = v
}
return copied
}
// Merge blends the specified map with a copy of this map and returns the result.
//
// Keys that appear in both will be selected from the specified map.
// This method requires that the wrapped object be a map[string]interface{}
func (m Map) Merge(merge Map) Map {
return m.Copy().MergeHere(merge)
}
// MergeHere blends the specified map with this map and returns the current map.
//
// Keys that appear in both will be selected from the specified map. The original map
// will be modified. This method requires that
// the wrapped object be a map[string]interface{}
func (m Map) MergeHere(merge Map) Map {
for k, v := range merge {
m[k] = v
}
return m
}
// Transform builds a new Obj giving the transformer a chance
// to change the keys and values as it goes. This method requires that
// the wrapped object be a map[string]interface{}
func (m Map) Transform(transformer func(key string, value interface{}) (string, interface{})) Map {
newMap := Map{}
for k, v := range m {
modifiedKey, modifiedVal := transformer(k, v)
newMap[modifiedKey] = modifiedVal
}
return newMap
}
// TransformKeys builds a new map using the specified key mapping.
//
// Unspecified keys will be unaltered.
// This method requires that the wrapped object be a map[string]interface{}
func (m Map) TransformKeys(mapping map[string]string) Map {
return m.Transform(func(key string, value interface{}) (string, interface{}) {
if newKey, ok := mapping[key]; ok {
return newKey, value
}
return key, value
})
}
// Checks if a string slice contains a string
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}

12
vendor/github.com/stretchr/objx/security.go generated vendored Normal file
View File

@ -0,0 +1,12 @@
package objx
import (
"crypto/sha1"
"encoding/hex"
)
// HashWithKey hashes the specified string using the security key
func HashWithKey(data, key string) string {
d := sha1.Sum([]byte(data + ":" + key))
return hex.EncodeToString(d[:])
}

17
vendor/github.com/stretchr/objx/tests.go generated vendored Normal file
View File

@ -0,0 +1,17 @@
package objx
// Has gets whether there is something at the specified selector
// or not.
//
// If m is nil, Has will always return false.
func (m Map) Has(selector string) bool {
if m == nil {
return false
}
return !m.Get(selector).IsNil()
}
// IsNil gets whether the data is nil or not.
func (v *Value) IsNil() bool {
return v == nil || v.data == nil
}

346
vendor/github.com/stretchr/objx/type_specific.go generated vendored Normal file
View File

@ -0,0 +1,346 @@
package objx
/*
MSI (map[string]interface{} and []map[string]interface{})
*/
// MSI gets the value as a map[string]interface{}, returns the optionalDefault
// value or a system default object if the value is the wrong type.
func (v *Value) MSI(optionalDefault ...map[string]interface{}) map[string]interface{} {
if s, ok := v.data.(map[string]interface{}); ok {
return s
}
if s, ok := v.data.(Map); ok {
return map[string]interface{}(s)
}
if len(optionalDefault) == 1 {
return optionalDefault[0]
}
return nil
}
// MustMSI gets the value as a map[string]interface{}.
//
// Panics if the object is not a map[string]interface{}.
func (v *Value) MustMSI() map[string]interface{} {
if s, ok := v.data.(Map); ok {
return map[string]interface{}(s)
}
return v.data.(map[string]interface{})
}
// MSISlice gets the value as a []map[string]interface{}, returns the optionalDefault
// value or nil if the value is not a []map[string]interface{}.
func (v *Value) MSISlice(optionalDefault ...[]map[string]interface{}) []map[string]interface{} {
if s, ok := v.data.([]map[string]interface{}); ok {
return s
}
s := v.ObjxMapSlice()
if s == nil {
if len(optionalDefault) == 1 {
return optionalDefault[0]
}
return nil
}
result := make([]map[string]interface{}, len(s))
for i := range s {
result[i] = s[i].Value().MSI()
}
return result
}
// MustMSISlice gets the value as a []map[string]interface{}.
//
// Panics if the object is not a []map[string]interface{}.
func (v *Value) MustMSISlice() []map[string]interface{} {
if s := v.MSISlice(); s != nil {
return s
}
return v.data.([]map[string]interface{})
}
// IsMSI gets whether the object contained is a map[string]interface{} or not.
func (v *Value) IsMSI() bool {
_, ok := v.data.(map[string]interface{})
if !ok {
_, ok = v.data.(Map)
}
return ok
}
// IsMSISlice gets whether the object contained is a []map[string]interface{} or not.
func (v *Value) IsMSISlice() bool {
_, ok := v.data.([]map[string]interface{})
if !ok {
_, ok = v.data.([]Map)
if !ok {
s, ok := v.data.([]interface{})
if ok {
for i := range s {
switch s[i].(type) {
case Map:
case map[string]interface{}:
default:
return false
}
}
return true
}
}
}
return ok
}
// EachMSI calls the specified callback for each object
// in the []map[string]interface{}.
//
// Panics if the object is the wrong type.
func (v *Value) EachMSI(callback func(int, map[string]interface{}) bool) *Value {
for index, val := range v.MustMSISlice() {
carryon := callback(index, val)
if !carryon {
break
}
}
return v
}
// WhereMSI uses the specified decider function to select items
// from the []map[string]interface{}. The object contained in the result will contain
// only the selected items.
func (v *Value) WhereMSI(decider func(int, map[string]interface{}) bool) *Value {
var selected []map[string]interface{}
v.EachMSI(func(index int, val map[string]interface{}) bool {
shouldSelect := decider(index, val)
if !shouldSelect {
selected = append(selected, val)
}
return true
})
return &Value{data: selected}
}
// GroupMSI uses the specified grouper function to group the items
// keyed by the return of the grouper. The object contained in the
// result will contain a map[string][]map[string]interface{}.
func (v *Value) GroupMSI(grouper func(int, map[string]interface{}) string) *Value {
groups := make(map[string][]map[string]interface{})
v.EachMSI(func(index int, val map[string]interface{}) bool {
group := grouper(index, val)
if _, ok := groups[group]; !ok {
groups[group] = make([]map[string]interface{}, 0)
}
groups[group] = append(groups[group], val)
return true
})
return &Value{data: groups}
}
// ReplaceMSI uses the specified function to replace each map[string]interface{}s
// by iterating each item. The data in the returned result will be a
// []map[string]interface{} containing the replaced items.
func (v *Value) ReplaceMSI(replacer func(int, map[string]interface{}) map[string]interface{}) *Value {
arr := v.MustMSISlice()
replaced := make([]map[string]interface{}, len(arr))
v.EachMSI(func(index int, val map[string]interface{}) bool {
replaced[index] = replacer(index, val)
return true
})
return &Value{data: replaced}
}
// CollectMSI uses the specified collector function to collect a value
// for each of the map[string]interface{}s in the slice. The data returned will be a
// []interface{}.
func (v *Value) CollectMSI(collector func(int, map[string]interface{}) interface{}) *Value {
arr := v.MustMSISlice()
collected := make([]interface{}, len(arr))
v.EachMSI(func(index int, val map[string]interface{}) bool {
collected[index] = collector(index, val)
return true
})
return &Value{data: collected}
}
/*
ObjxMap ((Map) and [](Map))
*/
// ObjxMap gets the value as a (Map), returns the optionalDefault
// value or a system default object if the value is the wrong type.
func (v *Value) ObjxMap(optionalDefault ...(Map)) Map {
if s, ok := v.data.((Map)); ok {
return s
}
if s, ok := v.data.(map[string]interface{}); ok {
return s
}
if len(optionalDefault) == 1 {
return optionalDefault[0]
}
return New(nil)
}
// MustObjxMap gets the value as a (Map).
//
// Panics if the object is not a (Map).
func (v *Value) MustObjxMap() Map {
if s, ok := v.data.(map[string]interface{}); ok {
return s
}
return v.data.((Map))
}
// ObjxMapSlice gets the value as a [](Map), returns the optionalDefault
// value or nil if the value is not a [](Map).
func (v *Value) ObjxMapSlice(optionalDefault ...[](Map)) [](Map) {
if s, ok := v.data.([]Map); ok {
return s
}
if s, ok := v.data.([]map[string]interface{}); ok {
result := make([]Map, len(s))
for i := range s {
result[i] = s[i]
}
return result
}
s, ok := v.data.([]interface{})
if !ok {
if len(optionalDefault) == 1 {
return optionalDefault[0]
}
return nil
}
result := make([]Map, len(s))
for i := range s {
switch s[i].(type) {
case Map:
result[i] = s[i].(Map)
case map[string]interface{}:
result[i] = New(s[i])
default:
return nil
}
}
return result
}
// MustObjxMapSlice gets the value as a [](Map).
//
// Panics if the object is not a [](Map).
func (v *Value) MustObjxMapSlice() [](Map) {
if s := v.ObjxMapSlice(); s != nil {
return s
}
return v.data.([](Map))
}
// IsObjxMap gets whether the object contained is a (Map) or not.
func (v *Value) IsObjxMap() bool {
_, ok := v.data.((Map))
if !ok {
_, ok = v.data.(map[string]interface{})
}
return ok
}
// IsObjxMapSlice gets whether the object contained is a [](Map) or not.
func (v *Value) IsObjxMapSlice() bool {
_, ok := v.data.([](Map))
if !ok {
_, ok = v.data.([]map[string]interface{})
if !ok {
s, ok := v.data.([]interface{})
if ok {
for i := range s {
switch s[i].(type) {
case Map:
case map[string]interface{}:
default:
return false
}
}
return true
}
}
}
return ok
}
// EachObjxMap calls the specified callback for each object
// in the [](Map).
//
// Panics if the object is the wrong type.
func (v *Value) EachObjxMap(callback func(int, Map) bool) *Value {
for index, val := range v.MustObjxMapSlice() {
carryon := callback(index, val)
if !carryon {
break
}
}
return v
}
// WhereObjxMap uses the specified decider function to select items
// from the [](Map). The object contained in the result will contain
// only the selected items.
func (v *Value) WhereObjxMap(decider func(int, Map) bool) *Value {
var selected [](Map)
v.EachObjxMap(func(index int, val Map) bool {
shouldSelect := decider(index, val)
if !shouldSelect {
selected = append(selected, val)
}
return true
})
return &Value{data: selected}
}
// GroupObjxMap uses the specified grouper function to group the items
// keyed by the return of the grouper. The object contained in the
// result will contain a map[string][](Map).
func (v *Value) GroupObjxMap(grouper func(int, Map) string) *Value {
groups := make(map[string][](Map))
v.EachObjxMap(func(index int, val Map) bool {
group := grouper(index, val)
if _, ok := groups[group]; !ok {
groups[group] = make([](Map), 0)
}
groups[group] = append(groups[group], val)
return true
})
return &Value{data: groups}
}
// ReplaceObjxMap uses the specified function to replace each (Map)s
// by iterating each item. The data in the returned result will be a
// [](Map) containing the replaced items.
func (v *Value) ReplaceObjxMap(replacer func(int, Map) Map) *Value {
arr := v.MustObjxMapSlice()
replaced := make([](Map), len(arr))
v.EachObjxMap(func(index int, val Map) bool {
replaced[index] = replacer(index, val)
return true
})
return &Value{data: replaced}
}
// CollectObjxMap uses the specified collector function to collect a value
// for each of the (Map)s in the slice. The data returned will be a
// []interface{}.
func (v *Value) CollectObjxMap(collector func(int, Map) interface{}) *Value {
arr := v.MustObjxMapSlice()
collected := make([]interface{}, len(arr))
v.EachObjxMap(func(index int, val Map) bool {
collected[index] = collector(index, val)
return true
})
return &Value{data: collected}
}

2261
vendor/github.com/stretchr/objx/type_specific_codegen.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

159
vendor/github.com/stretchr/objx/value.go generated vendored Normal file
View File

@ -0,0 +1,159 @@
package objx
import (
"fmt"
"strconv"
)
// Value provides methods for extracting interface{} data in various
// types.
type Value struct {
// data contains the raw data being managed by this Value
data interface{}
}
// Data returns the raw data contained by this Value
func (v *Value) Data() interface{} {
return v.data
}
// String returns the value always as a string
func (v *Value) String() string {
switch {
case v.IsNil():
return ""
case v.IsStr():
return v.Str()
case v.IsBool():
return strconv.FormatBool(v.Bool())
case v.IsFloat32():
return strconv.FormatFloat(float64(v.Float32()), 'f', -1, 32)
case v.IsFloat64():
return strconv.FormatFloat(v.Float64(), 'f', -1, 64)
case v.IsInt():
return strconv.FormatInt(int64(v.Int()), 10)
case v.IsInt8():
return strconv.FormatInt(int64(v.Int8()), 10)
case v.IsInt16():
return strconv.FormatInt(int64(v.Int16()), 10)
case v.IsInt32():
return strconv.FormatInt(int64(v.Int32()), 10)
case v.IsInt64():
return strconv.FormatInt(v.Int64(), 10)
case v.IsUint():
return strconv.FormatUint(uint64(v.Uint()), 10)
case v.IsUint8():
return strconv.FormatUint(uint64(v.Uint8()), 10)
case v.IsUint16():
return strconv.FormatUint(uint64(v.Uint16()), 10)
case v.IsUint32():
return strconv.FormatUint(uint64(v.Uint32()), 10)
case v.IsUint64():
return strconv.FormatUint(v.Uint64(), 10)
}
return fmt.Sprintf("%#v", v.Data())
}
// StringSlice returns the value always as a []string
func (v *Value) StringSlice(optionalDefault ...[]string) []string {
switch {
case v.IsStrSlice():
return v.MustStrSlice()
case v.IsBoolSlice():
slice := v.MustBoolSlice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatBool(iv)
}
return vals
case v.IsFloat32Slice():
slice := v.MustFloat32Slice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatFloat(float64(iv), 'f', -1, 32)
}
return vals
case v.IsFloat64Slice():
slice := v.MustFloat64Slice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatFloat(iv, 'f', -1, 64)
}
return vals
case v.IsIntSlice():
slice := v.MustIntSlice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatInt(int64(iv), 10)
}
return vals
case v.IsInt8Slice():
slice := v.MustInt8Slice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatInt(int64(iv), 10)
}
return vals
case v.IsInt16Slice():
slice := v.MustInt16Slice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatInt(int64(iv), 10)
}
return vals
case v.IsInt32Slice():
slice := v.MustInt32Slice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatInt(int64(iv), 10)
}
return vals
case v.IsInt64Slice():
slice := v.MustInt64Slice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatInt(iv, 10)
}
return vals
case v.IsUintSlice():
slice := v.MustUintSlice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatUint(uint64(iv), 10)
}
return vals
case v.IsUint8Slice():
slice := v.MustUint8Slice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatUint(uint64(iv), 10)
}
return vals
case v.IsUint16Slice():
slice := v.MustUint16Slice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatUint(uint64(iv), 10)
}
return vals
case v.IsUint32Slice():
slice := v.MustUint32Slice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatUint(uint64(iv), 10)
}
return vals
case v.IsUint64Slice():
slice := v.MustUint64Slice()
vals := make([]string, len(slice))
for i, iv := range slice {
vals[i] = strconv.FormatUint(iv, 10)
}
return vals
}
if len(optionalDefault) == 1 {
return optionalDefault[0]
}
return []string{}
}

44
vendor/github.com/stretchr/testify/mock/doc.go generated vendored Normal file
View File

@ -0,0 +1,44 @@
// Package mock provides a system by which it is possible to mock your objects
// and verify calls are happening as expected.
//
// # Example Usage
//
// The mock package provides an object, Mock, that tracks activity on another object. It is usually
// embedded into a test object as shown below:
//
// type MyTestObject struct {
// // add a Mock object instance
// mock.Mock
//
// // other fields go here as normal
// }
//
// When implementing the methods of an interface, you wire your functions up
// to call the Mock.Called(args...) method, and return the appropriate values.
//
// For example, to mock a method that saves the name and age of a person and returns
// the year of their birth or an error, you might write this:
//
// func (o *MyTestObject) SavePersonDetails(firstname, lastname string, age int) (int, error) {
// args := o.Called(firstname, lastname, age)
// return args.Int(0), args.Error(1)
// }
//
// The Int, Error and Bool methods are examples of strongly typed getters that take the argument
// index position. Given this argument list:
//
// (12, true, "Something")
//
// You could read them out strongly typed like this:
//
// args.Int(0)
// args.Bool(1)
// args.String(2)
//
// For objects of your own type, use the generic Arguments.Get(index) method and make a type assertion:
//
// return args.Get(0).(*MyObject), args.Get(1).(*AnotherObjectOfMine)
//
// This may cause a panic if the object you are getting is nil (the type assertion will fail), in those
// cases you should check for nil first.
package mock

1226
vendor/github.com/stretchr/testify/mock/mock.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

12
vendor/go.uber.org/mock/AUTHORS generated vendored
View File

@ -1,12 +0,0 @@
# This is the official list of GoMock authors for copyright purposes.
# This file is distinct from the CONTRIBUTORS files.
# See the latter for an explanation.
# Names should be added to this file as
# Name or Organization <email address>
# The email address is not required for organizations.
# Please keep the list sorted.
Alex Reece <awreece@gmail.com>
Google Inc.

202
vendor/go.uber.org/mock/LICENSE generated vendored
View File

@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,508 +0,0 @@
// Copyright 2010 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gomock
import (
"fmt"
"reflect"
"strconv"
"strings"
)
// Call represents an expected call to a mock.
type Call struct {
t TestHelper // for triggering test failures on invalid call setup
receiver any // the receiver of the method call
method string // the name of the method
methodType reflect.Type // the type of the method
args []Matcher // the args
origin string // file and line number of call setup
preReqs []*Call // prerequisite calls
// Expectations
minCalls, maxCalls int
numCalls int // actual number made
// actions are called when this Call is called. Each action gets the args and
// can set the return values by returning a non-nil slice. Actions run in the
// order they are created.
actions []func([]any) []any
}
// newCall creates a *Call. It requires the method type in order to support
// unexported methods.
func newCall(t TestHelper, receiver any, method string, methodType reflect.Type, args ...any) *Call {
t.Helper()
// TODO: check arity, types.
mArgs := make([]Matcher, len(args))
for i, arg := range args {
if m, ok := arg.(Matcher); ok {
mArgs[i] = m
} else if arg == nil {
// Handle nil specially so that passing a nil interface value
// will match the typed nils of concrete args.
mArgs[i] = Nil()
} else {
mArgs[i] = Eq(arg)
}
}
// callerInfo's skip should be updated if the number of calls between the user's test
// and this line changes, i.e. this code is wrapped in another anonymous function.
// 0 is us, 1 is RecordCallWithMethodType(), 2 is the generated recorder, and 3 is the user's test.
origin := callerInfo(3)
actions := []func([]any) []any{func([]any) []any {
// Synthesize the zero value for each of the return args' types.
rets := make([]any, methodType.NumOut())
for i := 0; i < methodType.NumOut(); i++ {
rets[i] = reflect.Zero(methodType.Out(i)).Interface()
}
return rets
}}
return &Call{t: t, receiver: receiver, method: method, methodType: methodType,
args: mArgs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions}
}
// AnyTimes allows the expectation to be called 0 or more times
func (c *Call) AnyTimes() *Call {
c.minCalls, c.maxCalls = 0, 1e8 // close enough to infinity
return c
}
// MinTimes requires the call to occur at least n times. If AnyTimes or MaxTimes have not been called or if MaxTimes
// was previously called with 1, MinTimes also sets the maximum number of calls to infinity.
func (c *Call) MinTimes(n int) *Call {
c.minCalls = n
if c.maxCalls == 1 {
c.maxCalls = 1e8
}
return c
}
// MaxTimes limits the number of calls to n times. If AnyTimes or MinTimes have not been called or if MinTimes was
// previously called with 1, MaxTimes also sets the minimum number of calls to 0.
func (c *Call) MaxTimes(n int) *Call {
c.maxCalls = n
if c.minCalls == 1 {
c.minCalls = 0
}
return c
}
// DoAndReturn declares the action to run when the call is matched.
// The return values from this function are returned by the mocked function.
// It takes an any argument to support n-arity functions.
// The anonymous function must match the function signature mocked method.
func (c *Call) DoAndReturn(f any) *Call {
// TODO: Check arity and types here, rather than dying badly elsewhere.
v := reflect.ValueOf(f)
c.addAction(func(args []any) []any {
c.t.Helper()
ft := v.Type()
if c.methodType.NumIn() != ft.NumIn() {
if ft.IsVariadic() {
c.t.Fatalf("wrong number of arguments in DoAndReturn func for %T.%v The function signature must match the mocked method, a variadic function cannot be used.",
c.receiver, c.method)
} else {
c.t.Fatalf("wrong number of arguments in DoAndReturn func for %T.%v: got %d, want %d [%s]",
c.receiver, c.method, ft.NumIn(), c.methodType.NumIn(), c.origin)
}
return nil
}
vArgs := make([]reflect.Value, len(args))
for i := 0; i < len(args); i++ {
if args[i] != nil {
vArgs[i] = reflect.ValueOf(args[i])
} else {
// Use the zero value for the arg.
vArgs[i] = reflect.Zero(ft.In(i))
}
}
vRets := v.Call(vArgs)
rets := make([]any, len(vRets))
for i, ret := range vRets {
rets[i] = ret.Interface()
}
return rets
})
return c
}
// Do declares the action to run when the call is matched. The function's
// return values are ignored to retain backward compatibility. To use the
// return values call DoAndReturn.
// It takes an any argument to support n-arity functions.
// The anonymous function must match the function signature mocked method.
func (c *Call) Do(f any) *Call {
// TODO: Check arity and types here, rather than dying badly elsewhere.
v := reflect.ValueOf(f)
c.addAction(func(args []any) []any {
c.t.Helper()
ft := v.Type()
if c.methodType.NumIn() != ft.NumIn() {
if ft.IsVariadic() {
c.t.Fatalf("wrong number of arguments in Do func for %T.%v The function signature must match the mocked method, a variadic function cannot be used.",
c.receiver, c.method)
} else {
c.t.Fatalf("wrong number of arguments in Do func for %T.%v: got %d, want %d [%s]",
c.receiver, c.method, ft.NumIn(), c.methodType.NumIn(), c.origin)
}
return nil
}
vArgs := make([]reflect.Value, len(args))
for i := 0; i < len(args); i++ {
if args[i] != nil {
vArgs[i] = reflect.ValueOf(args[i])
} else {
// Use the zero value for the arg.
vArgs[i] = reflect.Zero(ft.In(i))
}
}
v.Call(vArgs)
return nil
})
return c
}
// Return declares the values to be returned by the mocked function call.
func (c *Call) Return(rets ...any) *Call {
c.t.Helper()
mt := c.methodType
if len(rets) != mt.NumOut() {
c.t.Fatalf("wrong number of arguments to Return for %T.%v: got %d, want %d [%s]",
c.receiver, c.method, len(rets), mt.NumOut(), c.origin)
}
for i, ret := range rets {
if got, want := reflect.TypeOf(ret), mt.Out(i); got == want {
// Identical types; nothing to do.
} else if got == nil {
// Nil needs special handling.
switch want.Kind() {
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
// ok
default:
c.t.Fatalf("argument %d to Return for %T.%v is nil, but %v is not nillable [%s]",
i, c.receiver, c.method, want, c.origin)
}
} else if got.AssignableTo(want) {
// Assignable type relation. Make the assignment now so that the generated code
// can return the values with a type assertion.
v := reflect.New(want).Elem()
v.Set(reflect.ValueOf(ret))
rets[i] = v.Interface()
} else {
c.t.Fatalf("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s]",
i, c.receiver, c.method, got, want, c.origin)
}
}
c.addAction(func([]any) []any {
return rets
})
return c
}
// Times declares the exact number of times a function call is expected to be executed.
func (c *Call) Times(n int) *Call {
c.minCalls, c.maxCalls = n, n
return c
}
// SetArg declares an action that will set the nth argument's value,
// indirected through a pointer. Or, in the case of a slice and map, SetArg
// will copy value's elements/key-value pairs into the nth argument.
func (c *Call) SetArg(n int, value any) *Call {
c.t.Helper()
mt := c.methodType
// TODO: This will break on variadic methods.
// We will need to check those at invocation time.
if n < 0 || n >= mt.NumIn() {
c.t.Fatalf("SetArg(%d, ...) called for a method with %d args [%s]",
n, mt.NumIn(), c.origin)
}
// Permit setting argument through an interface.
// In the interface case, we don't (nay, can't) check the type here.
at := mt.In(n)
switch at.Kind() {
case reflect.Ptr:
dt := at.Elem()
if vt := reflect.TypeOf(value); !vt.AssignableTo(dt) {
c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]",
n, vt, dt, c.origin)
}
case reflect.Interface:
// nothing to do
case reflect.Slice:
// nothing to do
case reflect.Map:
// nothing to do
default:
c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice non-map type %v [%s]",
n, at, c.origin)
}
c.addAction(func(args []any) []any {
v := reflect.ValueOf(value)
switch reflect.TypeOf(args[n]).Kind() {
case reflect.Slice:
setSlice(args[n], v)
case reflect.Map:
setMap(args[n], v)
default:
reflect.ValueOf(args[n]).Elem().Set(v)
}
return nil
})
return c
}
// isPreReq returns true if other is a direct or indirect prerequisite to c.
func (c *Call) isPreReq(other *Call) bool {
for _, preReq := range c.preReqs {
if other == preReq || preReq.isPreReq(other) {
return true
}
}
return false
}
// After declares that the call may only match after preReq has been exhausted.
func (c *Call) After(preReq *Call) *Call {
c.t.Helper()
if c == preReq {
c.t.Fatalf("A call isn't allowed to be its own prerequisite")
}
if preReq.isPreReq(c) {
c.t.Fatalf("Loop in call order: %v is a prerequisite to %v (possibly indirectly).", c, preReq)
}
c.preReqs = append(c.preReqs, preReq)
return c
}
// Returns true if the minimum number of calls have been made.
func (c *Call) satisfied() bool {
return c.numCalls >= c.minCalls
}
// Returns true if the maximum number of calls have been made.
func (c *Call) exhausted() bool {
return c.numCalls >= c.maxCalls
}
func (c *Call) String() string {
args := make([]string, len(c.args))
for i, arg := range c.args {
args[i] = arg.String()
}
arguments := strings.Join(args, ", ")
return fmt.Sprintf("%T.%v(%s) %s", c.receiver, c.method, arguments, c.origin)
}
// Tests if the given call matches the expected call.
// If yes, returns nil. If no, returns error with message explaining why it does not match.
func (c *Call) matches(args []any) error {
if !c.methodType.IsVariadic() {
if len(args) != len(c.args) {
return fmt.Errorf("expected call at %s has the wrong number of arguments. Got: %d, want: %d",
c.origin, len(args), len(c.args))
}
for i, m := range c.args {
if !m.Matches(args[i]) {
return fmt.Errorf(
"expected call at %s doesn't match the argument at index %d.\nGot: %v\nWant: %v",
c.origin, i, formatGottenArg(m, args[i]), m,
)
}
}
} else {
if len(c.args) < c.methodType.NumIn()-1 {
return fmt.Errorf("expected call at %s has the wrong number of matchers. Got: %d, want: %d",
c.origin, len(c.args), c.methodType.NumIn()-1)
}
if len(c.args) != c.methodType.NumIn() && len(args) != len(c.args) {
return fmt.Errorf("expected call at %s has the wrong number of arguments. Got: %d, want: %d",
c.origin, len(args), len(c.args))
}
if len(args) < len(c.args)-1 {
return fmt.Errorf("expected call at %s has the wrong number of arguments. Got: %d, want: greater than or equal to %d",
c.origin, len(args), len(c.args)-1)
}
for i, m := range c.args {
if i < c.methodType.NumIn()-1 {
// Non-variadic args
if !m.Matches(args[i]) {
return fmt.Errorf("expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v",
c.origin, strconv.Itoa(i), formatGottenArg(m, args[i]), m)
}
continue
}
// The last arg has a possibility of a variadic argument, so let it branch
// sample: Foo(a int, b int, c ...int)
if i < len(c.args) && i < len(args) {
if m.Matches(args[i]) {
// Got Foo(a, b, c) want Foo(matcherA, matcherB, gomock.Any())
// Got Foo(a, b, c) want Foo(matcherA, matcherB, someSliceMatcher)
// Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC)
// Got Foo(a, b) want Foo(matcherA, matcherB)
// Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD)
continue
}
}
// The number of actual args don't match the number of matchers,
// or the last matcher is a slice and the last arg is not.
// If this function still matches it is because the last matcher
// matches all the remaining arguments or the lack of any.
// Convert the remaining arguments, if any, into a slice of the
// expected type.
vArgsType := c.methodType.In(c.methodType.NumIn() - 1)
vArgs := reflect.MakeSlice(vArgsType, 0, len(args)-i)
for _, arg := range args[i:] {
vArgs = reflect.Append(vArgs, reflect.ValueOf(arg))
}
if m.Matches(vArgs.Interface()) {
// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, gomock.Any())
// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, someSliceMatcher)
// Got Foo(a, b) want Foo(matcherA, matcherB, gomock.Any())
// Got Foo(a, b) want Foo(matcherA, matcherB, someEmptySliceMatcher)
break
}
// Wrong number of matchers or not match. Fail.
// Got Foo(a, b) want Foo(matcherA, matcherB, matcherC, matcherD)
// Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC, matcherD)
// Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD, matcherE)
// Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, matcherC, matcherD)
// Got Foo(a, b, c) want Foo(matcherA, matcherB)
return fmt.Errorf("expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v",
c.origin, strconv.Itoa(i), formatGottenArg(m, args[i:]), c.args[i])
}
}
// Check that all prerequisite calls have been satisfied.
for _, preReqCall := range c.preReqs {
if !preReqCall.satisfied() {
return fmt.Errorf("expected call at %s doesn't have a prerequisite call satisfied:\n%v\nshould be called before:\n%v",
c.origin, preReqCall, c)
}
}
// Check that the call is not exhausted.
if c.exhausted() {
return fmt.Errorf("expected call at %s has already been called the max number of times", c.origin)
}
return nil
}
// dropPrereqs tells the expected Call to not re-check prerequisite calls any
// longer, and to return its current set.
func (c *Call) dropPrereqs() (preReqs []*Call) {
preReqs = c.preReqs
c.preReqs = nil
return
}
func (c *Call) call() []func([]any) []any {
c.numCalls++
return c.actions
}
// InOrder declares that the given calls should occur in order.
// It panics if the type of any of the arguments isn't *Call or a generated
// mock with an embedded *Call.
func InOrder(args ...any) {
calls := make([]*Call, 0, len(args))
for i := 0; i < len(args); i++ {
if call := getCall(args[i]); call != nil {
calls = append(calls, call)
continue
}
panic(fmt.Sprintf(
"invalid argument at position %d of type %T, InOrder expects *gomock.Call or generated mock types with an embedded *gomock.Call",
i,
args[i],
))
}
for i := 1; i < len(calls); i++ {
calls[i].After(calls[i-1])
}
}
// getCall checks if the parameter is a *Call or a generated struct
// that wraps a *Call and returns the *Call pointer - if neither, it returns nil.
func getCall(arg any) *Call {
if call, ok := arg.(*Call); ok {
return call
}
t := reflect.ValueOf(arg)
if t.Kind() != reflect.Ptr && t.Kind() != reflect.Interface {
return nil
}
t = t.Elem()
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
if !f.CanInterface() {
continue
}
if call, ok := f.Interface().(*Call); ok {
return call
}
}
return nil
}
func setSlice(arg any, v reflect.Value) {
va := reflect.ValueOf(arg)
for i := 0; i < v.Len(); i++ {
va.Index(i).Set(v.Index(i))
}
}
func setMap(arg any, v reflect.Value) {
va := reflect.ValueOf(arg)
for _, e := range va.MapKeys() {
va.SetMapIndex(e, reflect.Value{})
}
for _, e := range v.MapKeys() {
va.SetMapIndex(e, v.MapIndex(e))
}
}
func (c *Call) addAction(action func([]any) []any) {
c.actions = append(c.actions, action)
}
func formatGottenArg(m Matcher, arg any) string {
got := fmt.Sprintf("%v (%T)", arg, arg)
if gs, ok := m.(GotFormatter); ok {
got = gs.Got(arg)
}
return got
}

View File

@ -1,164 +0,0 @@
// Copyright 2011 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gomock
import (
"bytes"
"errors"
"fmt"
"sync"
)
// callSet represents a set of expected calls, indexed by receiver and method
// name.
type callSet struct {
// Calls that are still expected.
expected map[callSetKey][]*Call
expectedMu *sync.Mutex
// Calls that have been exhausted.
exhausted map[callSetKey][]*Call
// when set to true, existing call expectations are overridden when new call expectations are made
allowOverride bool
}
// callSetKey is the key in the maps in callSet
type callSetKey struct {
receiver any
fname string
}
func newCallSet() *callSet {
return &callSet{
expected: make(map[callSetKey][]*Call),
expectedMu: &sync.Mutex{},
exhausted: make(map[callSetKey][]*Call),
}
}
func newOverridableCallSet() *callSet {
return &callSet{
expected: make(map[callSetKey][]*Call),
expectedMu: &sync.Mutex{},
exhausted: make(map[callSetKey][]*Call),
allowOverride: true,
}
}
// Add adds a new expected call.
func (cs callSet) Add(call *Call) {
key := callSetKey{call.receiver, call.method}
cs.expectedMu.Lock()
defer cs.expectedMu.Unlock()
m := cs.expected
if call.exhausted() {
m = cs.exhausted
}
if cs.allowOverride {
m[key] = make([]*Call, 0)
}
m[key] = append(m[key], call)
}
// Remove removes an expected call.
func (cs callSet) Remove(call *Call) {
key := callSetKey{call.receiver, call.method}
cs.expectedMu.Lock()
defer cs.expectedMu.Unlock()
calls := cs.expected[key]
for i, c := range calls {
if c == call {
// maintain order for remaining calls
cs.expected[key] = append(calls[:i], calls[i+1:]...)
cs.exhausted[key] = append(cs.exhausted[key], call)
break
}
}
}
// FindMatch searches for a matching call. Returns error with explanation message if no call matched.
func (cs callSet) FindMatch(receiver any, method string, args []any) (*Call, error) {
key := callSetKey{receiver, method}
cs.expectedMu.Lock()
defer cs.expectedMu.Unlock()
// Search through the expected calls.
expected := cs.expected[key]
var callsErrors bytes.Buffer
for _, call := range expected {
err := call.matches(args)
if err != nil {
_, _ = fmt.Fprintf(&callsErrors, "\n%v", err)
} else {
return call, nil
}
}
// If we haven't found a match then search through the exhausted calls so we
// get useful error messages.
exhausted := cs.exhausted[key]
for _, call := range exhausted {
if err := call.matches(args); err != nil {
_, _ = fmt.Fprintf(&callsErrors, "\n%v", err)
continue
}
_, _ = fmt.Fprintf(
&callsErrors, "all expected calls for method %q have been exhausted", method,
)
}
if len(expected)+len(exhausted) == 0 {
_, _ = fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method)
}
return nil, errors.New(callsErrors.String())
}
// Failures returns the calls that are not satisfied.
func (cs callSet) Failures() []*Call {
cs.expectedMu.Lock()
defer cs.expectedMu.Unlock()
failures := make([]*Call, 0, len(cs.expected))
for _, calls := range cs.expected {
for _, call := range calls {
if !call.satisfied() {
failures = append(failures, call)
}
}
}
return failures
}
// Satisfied returns true in case all expected calls in this callSet are satisfied.
func (cs callSet) Satisfied() bool {
cs.expectedMu.Lock()
defer cs.expectedMu.Unlock()
for _, calls := range cs.expected {
for _, call := range calls {
if !call.satisfied() {
return false
}
}
}
return true
}

View File

@ -1,318 +0,0 @@
// Copyright 2010 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gomock
import (
"context"
"fmt"
"reflect"
"runtime"
"sync"
)
// A TestReporter is something that can be used to report test failures. It
// is satisfied by the standard library's *testing.T.
type TestReporter interface {
Errorf(format string, args ...any)
Fatalf(format string, args ...any)
}
// TestHelper is a TestReporter that has the Helper method. It is satisfied
// by the standard library's *testing.T.
type TestHelper interface {
TestReporter
Helper()
}
// cleanuper is used to check if TestHelper also has the `Cleanup` method. A
// common pattern is to pass in a `*testing.T` to
// `NewController(t TestReporter)`. In Go 1.14+, `*testing.T` has a cleanup
// method. This can be utilized to call `Finish()` so the caller of this library
// does not have to.
type cleanuper interface {
Cleanup(func())
}
// A Controller represents the top-level control of a mock ecosystem. It
// defines the scope and lifetime of mock objects, as well as their
// expectations. It is safe to call Controller's methods from multiple
// goroutines. Each test should create a new Controller and invoke Finish via
// defer.
//
// func TestFoo(t *testing.T) {
// ctrl := gomock.NewController(t)
// // ..
// }
//
// func TestBar(t *testing.T) {
// t.Run("Sub-Test-1", st) {
// ctrl := gomock.NewController(st)
// // ..
// })
// t.Run("Sub-Test-2", st) {
// ctrl := gomock.NewController(st)
// // ..
// })
// })
type Controller struct {
// T should only be called within a generated mock. It is not intended to
// be used in user code and may be changed in future versions. T is the
// TestReporter passed in when creating the Controller via NewController.
// If the TestReporter does not implement a TestHelper it will be wrapped
// with a nopTestHelper.
T TestHelper
mu sync.Mutex
expectedCalls *callSet
finished bool
}
// NewController returns a new Controller. It is the preferred way to create a Controller.
//
// Passing [*testing.T] registers cleanup function to automatically call [Controller.Finish]
// when the test and all its subtests complete.
func NewController(t TestReporter, opts ...ControllerOption) *Controller {
h, ok := t.(TestHelper)
if !ok {
h = &nopTestHelper{t}
}
ctrl := &Controller{
T: h,
expectedCalls: newCallSet(),
}
for _, opt := range opts {
opt.apply(ctrl)
}
if c, ok := isCleanuper(ctrl.T); ok {
c.Cleanup(func() {
ctrl.T.Helper()
ctrl.finish(true, nil)
})
}
return ctrl
}
// ControllerOption configures how a Controller should behave.
type ControllerOption interface {
apply(*Controller)
}
type overridableExpectationsOption struct{}
// WithOverridableExpectations allows for overridable call expectations
// i.e., subsequent call expectations override existing call expectations
func WithOverridableExpectations() overridableExpectationsOption {
return overridableExpectationsOption{}
}
func (o overridableExpectationsOption) apply(ctrl *Controller) {
ctrl.expectedCalls = newOverridableCallSet()
}
type cancelReporter struct {
t TestHelper
cancel func()
}
func (r *cancelReporter) Errorf(format string, args ...any) {
r.t.Errorf(format, args...)
}
func (r *cancelReporter) Fatalf(format string, args ...any) {
defer r.cancel()
r.t.Fatalf(format, args...)
}
func (r *cancelReporter) Helper() {
r.t.Helper()
}
// WithContext returns a new Controller and a Context, which is cancelled on any
// fatal failure.
func WithContext(ctx context.Context, t TestReporter) (*Controller, context.Context) {
h, ok := t.(TestHelper)
if !ok {
h = &nopTestHelper{t: t}
}
ctx, cancel := context.WithCancel(ctx)
return NewController(&cancelReporter{t: h, cancel: cancel}), ctx
}
type nopTestHelper struct {
t TestReporter
}
func (h *nopTestHelper) Errorf(format string, args ...any) {
h.t.Errorf(format, args...)
}
func (h *nopTestHelper) Fatalf(format string, args ...any) {
h.t.Fatalf(format, args...)
}
func (h nopTestHelper) Helper() {}
// RecordCall is called by a mock. It should not be called by user code.
func (ctrl *Controller) RecordCall(receiver any, method string, args ...any) *Call {
ctrl.T.Helper()
recv := reflect.ValueOf(receiver)
for i := 0; i < recv.Type().NumMethod(); i++ {
if recv.Type().Method(i).Name == method {
return ctrl.RecordCallWithMethodType(receiver, method, recv.Method(i).Type(), args...)
}
}
ctrl.T.Fatalf("gomock: failed finding method %s on %T", method, receiver)
panic("unreachable")
}
// RecordCallWithMethodType is called by a mock. It should not be called by user code.
func (ctrl *Controller) RecordCallWithMethodType(receiver any, method string, methodType reflect.Type, args ...any) *Call {
ctrl.T.Helper()
call := newCall(ctrl.T, receiver, method, methodType, args...)
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
ctrl.expectedCalls.Add(call)
return call
}
// Call is called by a mock. It should not be called by user code.
func (ctrl *Controller) Call(receiver any, method string, args ...any) []any {
ctrl.T.Helper()
// Nest this code so we can use defer to make sure the lock is released.
actions := func() []func([]any) []any {
ctrl.T.Helper()
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
expected, err := ctrl.expectedCalls.FindMatch(receiver, method, args)
if err != nil {
// callerInfo's skip should be updated if the number of calls between the user's test
// and this line changes, i.e. this code is wrapped in another anonymous function.
// 0 is us, 1 is controller.Call(), 2 is the generated mock, and 3 is the user's test.
origin := callerInfo(3)
ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, args, origin, err)
}
// Two things happen here:
// * the matching call no longer needs to check prerequite calls,
// * and the prerequite calls are no longer expected, so remove them.
preReqCalls := expected.dropPrereqs()
for _, preReqCall := range preReqCalls {
ctrl.expectedCalls.Remove(preReqCall)
}
actions := expected.call()
if expected.exhausted() {
ctrl.expectedCalls.Remove(expected)
}
return actions
}()
var rets []any
for _, action := range actions {
if r := action(args); r != nil {
rets = r
}
}
return rets
}
// Finish checks to see if all the methods that were expected to be called were called.
// It is not idempotent and therefore can only be invoked once.
func (ctrl *Controller) Finish() {
// If we're currently panicking, probably because this is a deferred call.
// This must be recovered in the deferred function.
err := recover()
ctrl.finish(false, err)
}
// Satisfied returns whether all expected calls bound to this Controller have been satisfied.
// Calling Finish is then guaranteed to not fail due to missing calls.
func (ctrl *Controller) Satisfied() bool {
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
return ctrl.expectedCalls.Satisfied()
}
func (ctrl *Controller) finish(cleanup bool, panicErr any) {
ctrl.T.Helper()
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
if ctrl.finished {
if _, ok := isCleanuper(ctrl.T); !ok {
ctrl.T.Fatalf("Controller.Finish was called more than once. It has to be called exactly once.")
}
return
}
ctrl.finished = true
// Short-circuit, pass through the panic.
if panicErr != nil {
panic(panicErr)
}
// Check that all remaining expected calls are satisfied.
failures := ctrl.expectedCalls.Failures()
for _, call := range failures {
ctrl.T.Errorf("missing call(s) to %v", call)
}
if len(failures) != 0 {
if !cleanup {
ctrl.T.Fatalf("aborting test due to missing call(s)")
return
}
ctrl.T.Errorf("aborting test due to missing call(s)")
}
}
// callerInfo returns the file:line of the call site. skip is the number
// of stack frames to skip when reporting. 0 is callerInfo's call site.
func callerInfo(skip int) string {
if _, file, line, ok := runtime.Caller(skip + 1); ok {
return fmt.Sprintf("%s:%d", file, line)
}
return "unknown file"
}
// isCleanuper checks it if t's base TestReporter has a Cleanup method.
func isCleanuper(t TestReporter) (cleanuper, bool) {
tr := unwrapTestReporter(t)
c, ok := tr.(cleanuper)
return c, ok
}
// unwrapTestReporter unwraps TestReporter to the base implementation.
func unwrapTestReporter(t TestReporter) TestReporter {
tr := t
switch nt := t.(type) {
case *cancelReporter:
tr = nt.t
if h, check := tr.(*nopTestHelper); check {
tr = h.t
}
case *nopTestHelper:
tr = nt.t
default:
// not wrapped
}
return tr
}

View File

@ -1,60 +0,0 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package gomock is a mock framework for Go.
//
// Standard usage:
//
// (1) Define an interface that you wish to mock.
// type MyInterface interface {
// SomeMethod(x int64, y string)
// }
// (2) Use mockgen to generate a mock from the interface.
// (3) Use the mock in a test:
// func TestMyThing(t *testing.T) {
// mockCtrl := gomock.NewController(t)
// mockObj := something.NewMockMyInterface(mockCtrl)
// mockObj.EXPECT().SomeMethod(4, "blah")
// // pass mockObj to a real object and play with it.
// }
//
// By default, expected calls are not enforced to run in any particular order.
// Call order dependency can be enforced by use of InOrder and/or Call.After.
// Call.After can create more varied call order dependencies, but InOrder is
// often more convenient.
//
// The following examples create equivalent call order dependencies.
//
// Example of using Call.After to chain expected call order:
//
// firstCall := mockObj.EXPECT().SomeMethod(1, "first")
// secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall)
// mockObj.EXPECT().SomeMethod(3, "third").After(secondCall)
//
// Example of using InOrder to declare expected call order:
//
// gomock.InOrder(
// mockObj.EXPECT().SomeMethod(1, "first"),
// mockObj.EXPECT().SomeMethod(2, "second"),
// mockObj.EXPECT().SomeMethod(3, "third"),
// )
//
// The standard TestReporter most users will pass to `NewController` is a
// `*testing.T` from the context of the test. Note that this will use the
// standard `t.Error` and `t.Fatal` methods to report what happened in the test.
// In some cases this can leave your testing package in a weird state if global
// state is used since `t.Fatal` is like calling panic in the middle of a
// function. In these cases it is recommended that you pass in your own
// `TestReporter`.
package gomock

View File

@ -1,443 +0,0 @@
// Copyright 2010 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gomock
import (
"fmt"
"reflect"
"regexp"
"strings"
)
// A Matcher is a representation of a class of values.
// It is used to represent the valid or expected arguments to a mocked method.
type Matcher interface {
// Matches returns whether x is a match.
Matches(x any) bool
// String describes what the matcher matches.
String() string
}
// WantFormatter modifies the given Matcher's String() method to the given
// Stringer. This allows for control on how the "Want" is formatted when
// printing .
func WantFormatter(s fmt.Stringer, m Matcher) Matcher {
type matcher interface {
Matches(x any) bool
}
return struct {
matcher
fmt.Stringer
}{
matcher: m,
Stringer: s,
}
}
// StringerFunc type is an adapter to allow the use of ordinary functions as
// a Stringer. If f is a function with the appropriate signature,
// StringerFunc(f) is a Stringer that calls f.
type StringerFunc func() string
// String implements fmt.Stringer.
func (f StringerFunc) String() string {
return f()
}
// GotFormatter is used to better print failure messages. If a matcher
// implements GotFormatter, it will use the result from Got when printing
// the failure message.
type GotFormatter interface {
// Got is invoked with the received value. The result is used when
// printing the failure message.
Got(got any) string
}
// GotFormatterFunc type is an adapter to allow the use of ordinary
// functions as a GotFormatter. If f is a function with the appropriate
// signature, GotFormatterFunc(f) is a GotFormatter that calls f.
type GotFormatterFunc func(got any) string
// Got implements GotFormatter.
func (f GotFormatterFunc) Got(got any) string {
return f(got)
}
// GotFormatterAdapter attaches a GotFormatter to a Matcher.
func GotFormatterAdapter(s GotFormatter, m Matcher) Matcher {
return struct {
GotFormatter
Matcher
}{
GotFormatter: s,
Matcher: m,
}
}
type anyMatcher struct{}
func (anyMatcher) Matches(any) bool {
return true
}
func (anyMatcher) String() string {
return "is anything"
}
type condMatcher struct {
fn func(x any) bool
}
func (c condMatcher) Matches(x any) bool {
return c.fn(x)
}
func (condMatcher) String() string {
return "adheres to a custom condition"
}
type eqMatcher struct {
x any
}
func (e eqMatcher) Matches(x any) bool {
// In case, some value is nil
if e.x == nil || x == nil {
return reflect.DeepEqual(e.x, x)
}
// Check if types assignable and convert them to common type
x1Val := reflect.ValueOf(e.x)
x2Val := reflect.ValueOf(x)
if x1Val.Type().AssignableTo(x2Val.Type()) {
x1ValConverted := x1Val.Convert(x2Val.Type())
return reflect.DeepEqual(x1ValConverted.Interface(), x2Val.Interface())
}
return false
}
func (e eqMatcher) String() string {
return fmt.Sprintf("is equal to %v (%T)", e.x, e.x)
}
type nilMatcher struct{}
func (nilMatcher) Matches(x any) bool {
if x == nil {
return true
}
v := reflect.ValueOf(x)
switch v.Kind() {
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map,
reflect.Ptr, reflect.Slice:
return v.IsNil()
}
return false
}
func (nilMatcher) String() string {
return "is nil"
}
type notMatcher struct {
m Matcher
}
func (n notMatcher) Matches(x any) bool {
return !n.m.Matches(x)
}
func (n notMatcher) String() string {
return "not(" + n.m.String() + ")"
}
type regexMatcher struct {
regex *regexp.Regexp
}
func (m regexMatcher) Matches(x any) bool {
switch t := x.(type) {
case string:
return m.regex.MatchString(t)
case []byte:
return m.regex.Match(t)
default:
return false
}
}
func (m regexMatcher) String() string {
return "matches regex " + m.regex.String()
}
type assignableToTypeOfMatcher struct {
targetType reflect.Type
}
func (m assignableToTypeOfMatcher) Matches(x any) bool {
return reflect.TypeOf(x).AssignableTo(m.targetType)
}
func (m assignableToTypeOfMatcher) String() string {
return "is assignable to " + m.targetType.Name()
}
type anyOfMatcher struct {
matchers []Matcher
}
func (am anyOfMatcher) Matches(x any) bool {
for _, m := range am.matchers {
if m.Matches(x) {
return true
}
}
return false
}
func (am anyOfMatcher) String() string {
ss := make([]string, 0, len(am.matchers))
for _, matcher := range am.matchers {
ss = append(ss, matcher.String())
}
return strings.Join(ss, " | ")
}
type allMatcher struct {
matchers []Matcher
}
func (am allMatcher) Matches(x any) bool {
for _, m := range am.matchers {
if !m.Matches(x) {
return false
}
}
return true
}
func (am allMatcher) String() string {
ss := make([]string, 0, len(am.matchers))
for _, matcher := range am.matchers {
ss = append(ss, matcher.String())
}
return strings.Join(ss, "; ")
}
type lenMatcher struct {
i int
}
func (m lenMatcher) Matches(x any) bool {
v := reflect.ValueOf(x)
switch v.Kind() {
case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String:
return v.Len() == m.i
default:
return false
}
}
func (m lenMatcher) String() string {
return fmt.Sprintf("has length %d", m.i)
}
type inAnyOrderMatcher struct {
x any
}
func (m inAnyOrderMatcher) Matches(x any) bool {
given, ok := m.prepareValue(x)
if !ok {
return false
}
wanted, ok := m.prepareValue(m.x)
if !ok {
return false
}
if given.Len() != wanted.Len() {
return false
}
usedFromGiven := make([]bool, given.Len())
foundFromWanted := make([]bool, wanted.Len())
for i := 0; i < wanted.Len(); i++ {
wantedMatcher := Eq(wanted.Index(i).Interface())
for j := 0; j < given.Len(); j++ {
if usedFromGiven[j] {
continue
}
if wantedMatcher.Matches(given.Index(j).Interface()) {
foundFromWanted[i] = true
usedFromGiven[j] = true
break
}
}
}
missingFromWanted := 0
for _, found := range foundFromWanted {
if !found {
missingFromWanted++
}
}
extraInGiven := 0
for _, used := range usedFromGiven {
if !used {
extraInGiven++
}
}
return extraInGiven == 0 && missingFromWanted == 0
}
func (m inAnyOrderMatcher) prepareValue(x any) (reflect.Value, bool) {
xValue := reflect.ValueOf(x)
switch xValue.Kind() {
case reflect.Slice, reflect.Array:
return xValue, true
default:
return reflect.Value{}, false
}
}
func (m inAnyOrderMatcher) String() string {
return fmt.Sprintf("has the same elements as %v", m.x)
}
// Constructors
// All returns a composite Matcher that returns true if and only all of the
// matchers return true.
func All(ms ...Matcher) Matcher { return allMatcher{ms} }
// Any returns a matcher that always matches.
func Any() Matcher { return anyMatcher{} }
// Cond returns a matcher that matches when the given function returns true
// after passing it the parameter to the mock function.
// This is particularly useful in case you want to match over a field of a custom struct, or dynamic logic.
//
// Example usage:
//
// Cond(func(x any){return x.(int) == 1}).Matches(1) // returns true
// Cond(func(x any){return x.(int) == 2}).Matches(1) // returns false
func Cond(fn func(x any) bool) Matcher { return condMatcher{fn} }
// AnyOf returns a composite Matcher that returns true if at least one of the
// matchers returns true.
//
// Example usage:
//
// AnyOf(1, 2, 3).Matches(2) // returns true
// AnyOf(1, 2, 3).Matches(10) // returns false
// AnyOf(Nil(), Len(2)).Matches(nil) // returns true
// AnyOf(Nil(), Len(2)).Matches("hi") // returns true
// AnyOf(Nil(), Len(2)).Matches("hello") // returns false
func AnyOf(xs ...any) Matcher {
ms := make([]Matcher, 0, len(xs))
for _, x := range xs {
if m, ok := x.(Matcher); ok {
ms = append(ms, m)
} else {
ms = append(ms, Eq(x))
}
}
return anyOfMatcher{ms}
}
// Eq returns a matcher that matches on equality.
//
// Example usage:
//
// Eq(5).Matches(5) // returns true
// Eq(5).Matches(4) // returns false
func Eq(x any) Matcher { return eqMatcher{x} }
// Len returns a matcher that matches on length. This matcher returns false if
// is compared to a type that is not an array, chan, map, slice, or string.
func Len(i int) Matcher {
return lenMatcher{i}
}
// Nil returns a matcher that matches if the received value is nil.
//
// Example usage:
//
// var x *bytes.Buffer
// Nil().Matches(x) // returns true
// x = &bytes.Buffer{}
// Nil().Matches(x) // returns false
func Nil() Matcher { return nilMatcher{} }
// Not reverses the results of its given child matcher.
//
// Example usage:
//
// Not(Eq(5)).Matches(4) // returns true
// Not(Eq(5)).Matches(5) // returns false
func Not(x any) Matcher {
if m, ok := x.(Matcher); ok {
return notMatcher{m}
}
return notMatcher{Eq(x)}
}
// Regex checks whether parameter matches the associated regex.
//
// Example usage:
//
// Regex("[0-9]{2}:[0-9]{2}").Matches("23:02") // returns true
// Regex("[0-9]{2}:[0-9]{2}").Matches([]byte{'2', '3', ':', '0', '2'}) // returns true
// Regex("[0-9]{2}:[0-9]{2}").Matches("hello world") // returns false
// Regex("[0-9]{2}").Matches(21) // returns false as it's not a valid type
func Regex(regexStr string) Matcher {
return regexMatcher{regex: regexp.MustCompile(regexStr)}
}
// AssignableToTypeOf is a Matcher that matches if the parameter to the mock
// function is assignable to the type of the parameter to this function.
//
// Example usage:
//
// var s fmt.Stringer = &bytes.Buffer{}
// AssignableToTypeOf(s).Matches(time.Second) // returns true
// AssignableToTypeOf(s).Matches(99) // returns false
//
// var ctx = reflect.TypeOf((*context.Context)(nil)).Elem()
// AssignableToTypeOf(ctx).Matches(context.Background()) // returns true
func AssignableToTypeOf(x any) Matcher {
if xt, ok := x.(reflect.Type); ok {
return assignableToTypeOfMatcher{xt}
}
return assignableToTypeOfMatcher{reflect.TypeOf(x)}
}
// InAnyOrder is a Matcher that returns true for collections of the same elements ignoring the order.
//
// Example usage:
//
// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 3, 2}) // returns true
// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 2}) // returns false
func InAnyOrder(x any) Matcher {
return inAnyOrderMatcher{x}
}

7
vendor/modules.txt vendored
View File

@ -593,9 +593,13 @@ github.com/spf13/pflag
# github.com/stoewer/go-strcase v1.2.0
## explicit; go 1.11
github.com/stoewer/go-strcase
# github.com/stretchr/objx v0.5.0
## explicit; go 1.12
github.com/stretchr/objx
# github.com/stretchr/testify v1.8.4
## explicit; go 1.20
github.com/stretchr/testify/assert
github.com/stretchr/testify/mock
github.com/stretchr/testify/require
# github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
## explicit
@ -800,9 +804,6 @@ go.starlark.net/syntax
## explicit; go 1.20
go.uber.org/goleak
go.uber.org/goleak/internal/stack
# go.uber.org/mock v0.4.0
## explicit; go 1.20
go.uber.org/mock/gomock
# go.uber.org/multierr v1.11.0
## explicit; go 1.19
go.uber.org/multierr