diff --git a/LICENSES/vendor/github.com/stretchr/objx/LICENSE b/LICENSES/vendor/github.com/stretchr/objx/LICENSE new file mode 100644 index 00000000000..420e4cf6d71 --- /dev/null +++ b/LICENSES/vendor/github.com/stretchr/objx/LICENSE @@ -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 diff --git a/LICENSES/vendor/go.uber.org/mock/LICENSE b/LICENSES/vendor/go.uber.org/mock/LICENSE deleted file mode 100644 index a458d087259..00000000000 --- a/LICENSES/vendor/go.uber.org/mock/LICENSE +++ /dev/null @@ -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 diff --git a/go.mod b/go.mod index ea104bb5b87..331cb49349c 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 801ba1952ab..c793af04957 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/hack/tools/go.mod b/hack/tools/go.mod index 6715d801c67..42353a02995 100644 --- a/hack/tools/go.mod +++ b/hack/tools/go.mod @@ -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 diff --git a/hack/tools/go.sum b/hack/tools/go.sum index 76d874b4e32..5b3798ae2e4 100644 --- a/hack/tools/go.sum +++ b/hack/tools/go.sum @@ -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= diff --git a/hack/tools/tools.go b/hack/tools/tools.go index 1b3e73c8769..42b52202d47 100644 --- a/hack/tools/tools.go +++ b/hack/tools/tools.go @@ -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" diff --git a/hack/update-mocks.sh b/hack/update-mocks.sh index 6eac6f3385e..9a6bbb85637 100755 --- a/hack/update-mocks.sh +++ b/hack/update-mocks.sh @@ -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")")" diff --git a/pkg/kubelet/apis/podresources/.mockery.yaml b/pkg/kubelet/apis/podresources/.mockery.yaml new file mode 100644 index 00000000000..d25fc0979c7 --- /dev/null +++ b/pkg/kubelet/apis/podresources/.mockery.yaml @@ -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: diff --git a/pkg/kubelet/apis/podresources/server_v1_test.go b/pkg/kubelet/apis/podresources/server_v1_test.go index 7af2db35302..aaa560fc4f0 100644 --- a/pkg/kubelet/apis/podresources/server_v1_test.go +++ b/pkg/kubelet/apis/podresources/server_v1_test.go @@ -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{ diff --git a/pkg/kubelet/apis/podresources/server_v1alpha1_test.go b/pkg/kubelet/apis/podresources/server_v1alpha1_test.go index 8cf53ae7f36..a286b0fafc7 100644 --- a/pkg/kubelet/apis/podresources/server_v1alpha1_test.go +++ b/pkg/kubelet/apis/podresources/server_v1alpha1_test.go @@ -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, diff --git a/pkg/kubelet/apis/podresources/testing/cpus_provider.go b/pkg/kubelet/apis/podresources/testing/cpus_provider.go new file mode 100644 index 00000000000..972b2bfe133 --- /dev/null +++ b/pkg/kubelet/apis/podresources/testing/cpus_provider.go @@ -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 +} diff --git a/pkg/kubelet/apis/podresources/testing/devices_provider.go b/pkg/kubelet/apis/podresources/testing/devices_provider.go new file mode 100644 index 00000000000..862f4535351 --- /dev/null +++ b/pkg/kubelet/apis/podresources/testing/devices_provider.go @@ -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 +} diff --git a/pkg/kubelet/apis/podresources/testing/dynamic_resources_provider.go b/pkg/kubelet/apis/podresources/testing/dynamic_resources_provider.go new file mode 100644 index 00000000000..7d0cec493b1 --- /dev/null +++ b/pkg/kubelet/apis/podresources/testing/dynamic_resources_provider.go @@ -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 +} diff --git a/pkg/kubelet/apis/podresources/testing/memory_provider.go b/pkg/kubelet/apis/podresources/testing/memory_provider.go new file mode 100644 index 00000000000..bf0a7af34cc --- /dev/null +++ b/pkg/kubelet/apis/podresources/testing/memory_provider.go @@ -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 +} diff --git a/pkg/kubelet/apis/podresources/testing/pods_provider.go b/pkg/kubelet/apis/podresources/testing/pods_provider.go new file mode 100644 index 00000000000..e0e23736e64 --- /dev/null +++ b/pkg/kubelet/apis/podresources/testing/pods_provider.go @@ -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 +} diff --git a/pkg/kubelet/apis/podresources/testing/provider_mock.go b/pkg/kubelet/apis/podresources/testing/provider_mock.go deleted file mode 100644 index 9e717a578ca..00000000000 --- a/pkg/kubelet/apis/podresources/testing/provider_mock.go +++ /dev/null @@ -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) -} diff --git a/pkg/kubelet/apis/podresources/types.go b/pkg/kubelet/apis/podresources/types.go index 155d42abbcc..ee1269d969b 100644 --- a/pkg/kubelet/apis/podresources/types.go +++ b/pkg/kubelet/apis/podresources/types.go @@ -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 ( diff --git a/pkg/kubelet/cadvisor/.mockery.yaml b/pkg/kubelet/cadvisor/.mockery.yaml new file mode 100644 index 00000000000..b8d6ef3efaa --- /dev/null +++ b/pkg/kubelet/cadvisor/.mockery.yaml @@ -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: diff --git a/pkg/kubelet/cadvisor/testing/cadvisor_mock.go b/pkg/kubelet/cadvisor/testing/cadvisor_mock.go index 036b3290f16..695753a6d7c 100644 --- a/pkg/kubelet/cadvisor/testing/cadvisor_mock.go +++ b/pkg/kubelet/cadvisor/testing/cadvisor_mock.go @@ -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)) -} diff --git a/pkg/kubelet/cadvisor/types.go b/pkg/kubelet/cadvisor/types.go index d1b95afc8f7..bfdb9c60eaa 100644 --- a/pkg/kubelet/cadvisor/types.go +++ b/pkg/kubelet/cadvisor/types.go @@ -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 ( diff --git a/pkg/kubelet/cm/container_manager_linux_test.go b/pkg/kubelet/cm/container_manager_linux_test.go index 55287439694..97f4f9c0836 100644 --- a/pkg/kubelet/cm/container_manager_linux_test.go +++ b/pkg/kubelet/cm/container_manager_linux_test.go @@ -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 diff --git a/pkg/kubelet/container/.mockery.yaml b/pkg/kubelet/container/.mockery.yaml new file mode 100644 index 00000000000..84489a0095f --- /dev/null +++ b/pkg/kubelet/container/.mockery.yaml @@ -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: diff --git a/pkg/kubelet/container/runtime.go b/pkg/kubelet/container/runtime.go index 32bd2858299..b6c4ff6624d 100644 --- a/pkg/kubelet/container/runtime.go +++ b/pkg/kubelet/container/runtime.go @@ -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 ( diff --git a/pkg/kubelet/container/runtime_cache.go b/pkg/kubelet/container/runtime_cache.go index 2615d68f730..ea4b155e0d0 100644 --- a/pkg/kubelet/container/runtime_cache.go +++ b/pkg/kubelet/container/runtime_cache.go @@ -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 ( diff --git a/pkg/kubelet/container/testing/mock_runtime_cache.go b/pkg/kubelet/container/testing/mock_runtime_cache.go index b2c52c6c5f7..e4cd71d80b3 100644 --- a/pkg/kubelet/container/testing/mock_runtime_cache.go +++ b/pkg/kubelet/container/testing/mock_runtime_cache.go @@ -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) -} diff --git a/pkg/kubelet/container/testing/mockdirentry.go b/pkg/kubelet/container/testing/mockdirentry.go index 6b31aa14328..0a091df1d49 100644 --- a/pkg/kubelet/container/testing/mockdirentry.go +++ b/pkg/kubelet/container/testing/mockdirentry.go @@ -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)) -} diff --git a/pkg/kubelet/container/testing/runtime_mock.go b/pkg/kubelet/container/testing/runtime_mock.go index 39cf4342f41..e461f86adc7 100644 --- a/pkg/kubelet/container/testing/runtime_mock.go +++ b/pkg/kubelet/container/testing/runtime_mock.go @@ -14,710 +14,1297 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by MockGen. DO NOT EDIT. -// Source: runtime.go -// -// Generated by this command: -// -// mockgen -source=runtime.go -destination=testing/runtime_mock.go -package=testing Runtime -// +// Code generated by mockery v2.40.3. DO NOT EDIT. -// Package testing is a generated GoMock package. package testing import ( context "context" - io "io" - url "net/url" - reflect "reflect" - time "time" - gomock "go.uber.org/mock/gomock" - v1 "k8s.io/api/core/v1" - types "k8s.io/apimachinery/pkg/types" - remotecommand "k8s.io/client-go/tools/remotecommand" - flowcontrol "k8s.io/client-go/util/flowcontrol" - v10 "k8s.io/cri-api/pkg/apis/runtime/v1" container "k8s.io/kubernetes/pkg/kubelet/container" + + corev1 "k8s.io/api/core/v1" + + flowcontrol "k8s.io/client-go/util/flowcontrol" + + io "io" + + mock "github.com/stretchr/testify/mock" + + types "k8s.io/apimachinery/pkg/types" + + v1 "k8s.io/cri-api/pkg/apis/runtime/v1" ) -// MockVersion is a mock of Version interface. -type MockVersion struct { - ctrl *gomock.Controller - recorder *MockVersionMockRecorder -} - -// MockVersionMockRecorder is the mock recorder for MockVersion. -type MockVersionMockRecorder struct { - mock *MockVersion -} - -// NewMockVersion creates a new mock instance. -func NewMockVersion(ctrl *gomock.Controller) *MockVersion { - mock := &MockVersion{ctrl: ctrl} - mock.recorder = &MockVersionMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockVersion) EXPECT() *MockVersionMockRecorder { - return m.recorder -} - -// Compare mocks base method. -func (m *MockVersion) Compare(other string) (int, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Compare", other) - ret0, _ := ret[0].(int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Compare indicates an expected call of Compare. -func (mr *MockVersionMockRecorder) Compare(other any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Compare", reflect.TypeOf((*MockVersion)(nil).Compare), other) -} - -// String mocks base method. -func (m *MockVersion) String() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "String") - ret0, _ := ret[0].(string) - return ret0 -} - -// String indicates an expected call of String. -func (mr *MockVersionMockRecorder) String() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "String", reflect.TypeOf((*MockVersion)(nil).String)) -} - -// MockRuntime is a mock of Runtime interface. +// MockRuntime is an autogenerated mock type for the Runtime type type MockRuntime struct { - ctrl *gomock.Controller - recorder *MockRuntimeMockRecorder + mock.Mock } -// MockRuntimeMockRecorder is the mock recorder for MockRuntime. -type MockRuntimeMockRecorder struct { - mock *MockRuntime +type MockRuntime_Expecter struct { + mock *mock.Mock } -// NewMockRuntime creates a new mock instance. -func NewMockRuntime(ctrl *gomock.Controller) *MockRuntime { - mock := &MockRuntime{ctrl: ctrl} - mock.recorder = &MockRuntimeMockRecorder{mock} +func (_m *MockRuntime) EXPECT() *MockRuntime_Expecter { + return &MockRuntime_Expecter{mock: &_m.Mock} +} + +// APIVersion provides a mock function with given fields: +func (_m *MockRuntime) APIVersion() (container.Version, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for APIVersion") + } + + var r0 container.Version + var r1 error + if rf, ok := ret.Get(0).(func() (container.Version, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() container.Version); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(container.Version) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_APIVersion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'APIVersion' +type MockRuntime_APIVersion_Call struct { + *mock.Call +} + +// APIVersion is a helper method to define mock.On call +func (_e *MockRuntime_Expecter) APIVersion() *MockRuntime_APIVersion_Call { + return &MockRuntime_APIVersion_Call{Call: _e.mock.On("APIVersion")} +} + +func (_c *MockRuntime_APIVersion_Call) Run(run func()) *MockRuntime_APIVersion_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockRuntime_APIVersion_Call) Return(_a0 container.Version, _a1 error) *MockRuntime_APIVersion_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_APIVersion_Call) RunAndReturn(run func() (container.Version, error)) *MockRuntime_APIVersion_Call { + _c.Call.Return(run) + return _c +} + +// CheckpointContainer provides a mock function with given fields: ctx, options +func (_m *MockRuntime) CheckpointContainer(ctx context.Context, options *v1.CheckpointContainerRequest) error { + ret := _m.Called(ctx, options) + + if len(ret) == 0 { + panic("no return value specified for CheckpointContainer") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *v1.CheckpointContainerRequest) error); ok { + r0 = rf(ctx, options) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntime_CheckpointContainer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckpointContainer' +type MockRuntime_CheckpointContainer_Call struct { + *mock.Call +} + +// CheckpointContainer is a helper method to define mock.On call +// - ctx context.Context +// - options *v1.CheckpointContainerRequest +func (_e *MockRuntime_Expecter) CheckpointContainer(ctx interface{}, options interface{}) *MockRuntime_CheckpointContainer_Call { + return &MockRuntime_CheckpointContainer_Call{Call: _e.mock.On("CheckpointContainer", ctx, options)} +} + +func (_c *MockRuntime_CheckpointContainer_Call) Run(run func(ctx context.Context, options *v1.CheckpointContainerRequest)) *MockRuntime_CheckpointContainer_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*v1.CheckpointContainerRequest)) + }) + return _c +} + +func (_c *MockRuntime_CheckpointContainer_Call) Return(_a0 error) *MockRuntime_CheckpointContainer_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntime_CheckpointContainer_Call) RunAndReturn(run func(context.Context, *v1.CheckpointContainerRequest) error) *MockRuntime_CheckpointContainer_Call { + _c.Call.Return(run) + return _c +} + +// DeleteContainer provides a mock function with given fields: ctx, containerID +func (_m *MockRuntime) DeleteContainer(ctx context.Context, containerID container.ContainerID) error { + ret := _m.Called(ctx, containerID) + + if len(ret) == 0 { + panic("no return value specified for DeleteContainer") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, container.ContainerID) error); ok { + r0 = rf(ctx, containerID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntime_DeleteContainer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteContainer' +type MockRuntime_DeleteContainer_Call struct { + *mock.Call +} + +// DeleteContainer is a helper method to define mock.On call +// - ctx context.Context +// - containerID container.ContainerID +func (_e *MockRuntime_Expecter) DeleteContainer(ctx interface{}, containerID interface{}) *MockRuntime_DeleteContainer_Call { + return &MockRuntime_DeleteContainer_Call{Call: _e.mock.On("DeleteContainer", ctx, containerID)} +} + +func (_c *MockRuntime_DeleteContainer_Call) Run(run func(ctx context.Context, containerID container.ContainerID)) *MockRuntime_DeleteContainer_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(container.ContainerID)) + }) + return _c +} + +func (_c *MockRuntime_DeleteContainer_Call) Return(_a0 error) *MockRuntime_DeleteContainer_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntime_DeleteContainer_Call) RunAndReturn(run func(context.Context, container.ContainerID) error) *MockRuntime_DeleteContainer_Call { + _c.Call.Return(run) + return _c +} + +// GarbageCollect provides a mock function with given fields: ctx, gcPolicy, allSourcesReady, evictNonDeletedPods +func (_m *MockRuntime) GarbageCollect(ctx context.Context, gcPolicy container.GCPolicy, allSourcesReady bool, evictNonDeletedPods bool) error { + ret := _m.Called(ctx, gcPolicy, allSourcesReady, evictNonDeletedPods) + + if len(ret) == 0 { + panic("no return value specified for GarbageCollect") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, container.GCPolicy, bool, bool) error); ok { + r0 = rf(ctx, gcPolicy, allSourcesReady, evictNonDeletedPods) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntime_GarbageCollect_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GarbageCollect' +type MockRuntime_GarbageCollect_Call struct { + *mock.Call +} + +// GarbageCollect is a helper method to define mock.On call +// - ctx context.Context +// - gcPolicy container.GCPolicy +// - allSourcesReady bool +// - evictNonDeletedPods bool +func (_e *MockRuntime_Expecter) GarbageCollect(ctx interface{}, gcPolicy interface{}, allSourcesReady interface{}, evictNonDeletedPods interface{}) *MockRuntime_GarbageCollect_Call { + return &MockRuntime_GarbageCollect_Call{Call: _e.mock.On("GarbageCollect", ctx, gcPolicy, allSourcesReady, evictNonDeletedPods)} +} + +func (_c *MockRuntime_GarbageCollect_Call) Run(run func(ctx context.Context, gcPolicy container.GCPolicy, allSourcesReady bool, evictNonDeletedPods bool)) *MockRuntime_GarbageCollect_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(container.GCPolicy), args[2].(bool), args[3].(bool)) + }) + return _c +} + +func (_c *MockRuntime_GarbageCollect_Call) Return(_a0 error) *MockRuntime_GarbageCollect_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntime_GarbageCollect_Call) RunAndReturn(run func(context.Context, container.GCPolicy, bool, bool) error) *MockRuntime_GarbageCollect_Call { + _c.Call.Return(run) + return _c +} + +// GeneratePodStatus provides a mock function with given fields: event +func (_m *MockRuntime) GeneratePodStatus(event *v1.ContainerEventResponse) (*container.PodStatus, error) { + ret := _m.Called(event) + + if len(ret) == 0 { + panic("no return value specified for GeneratePodStatus") + } + + var r0 *container.PodStatus + var r1 error + if rf, ok := ret.Get(0).(func(*v1.ContainerEventResponse) (*container.PodStatus, error)); ok { + return rf(event) + } + if rf, ok := ret.Get(0).(func(*v1.ContainerEventResponse) *container.PodStatus); ok { + r0 = rf(event) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*container.PodStatus) + } + } + + if rf, ok := ret.Get(1).(func(*v1.ContainerEventResponse) error); ok { + r1 = rf(event) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_GeneratePodStatus_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GeneratePodStatus' +type MockRuntime_GeneratePodStatus_Call struct { + *mock.Call +} + +// GeneratePodStatus is a helper method to define mock.On call +// - event *v1.ContainerEventResponse +func (_e *MockRuntime_Expecter) GeneratePodStatus(event interface{}) *MockRuntime_GeneratePodStatus_Call { + return &MockRuntime_GeneratePodStatus_Call{Call: _e.mock.On("GeneratePodStatus", event)} +} + +func (_c *MockRuntime_GeneratePodStatus_Call) Run(run func(event *v1.ContainerEventResponse)) *MockRuntime_GeneratePodStatus_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*v1.ContainerEventResponse)) + }) + return _c +} + +func (_c *MockRuntime_GeneratePodStatus_Call) Return(_a0 *container.PodStatus, _a1 error) *MockRuntime_GeneratePodStatus_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_GeneratePodStatus_Call) RunAndReturn(run func(*v1.ContainerEventResponse) (*container.PodStatus, error)) *MockRuntime_GeneratePodStatus_Call { + _c.Call.Return(run) + return _c +} + +// GetContainerLogs provides a mock function with given fields: ctx, pod, containerID, logOptions, stdout, stderr +func (_m *MockRuntime) GetContainerLogs(ctx context.Context, pod *corev1.Pod, containerID container.ContainerID, logOptions *corev1.PodLogOptions, stdout io.Writer, stderr io.Writer) error { + ret := _m.Called(ctx, pod, containerID, logOptions, stdout, stderr) + + if len(ret) == 0 { + panic("no return value specified for GetContainerLogs") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *corev1.Pod, container.ContainerID, *corev1.PodLogOptions, io.Writer, io.Writer) error); ok { + r0 = rf(ctx, pod, containerID, logOptions, stdout, stderr) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntime_GetContainerLogs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetContainerLogs' +type MockRuntime_GetContainerLogs_Call struct { + *mock.Call +} + +// GetContainerLogs is a helper method to define mock.On call +// - ctx context.Context +// - pod *corev1.Pod +// - containerID container.ContainerID +// - logOptions *corev1.PodLogOptions +// - stdout io.Writer +// - stderr io.Writer +func (_e *MockRuntime_Expecter) GetContainerLogs(ctx interface{}, pod interface{}, containerID interface{}, logOptions interface{}, stdout interface{}, stderr interface{}) *MockRuntime_GetContainerLogs_Call { + return &MockRuntime_GetContainerLogs_Call{Call: _e.mock.On("GetContainerLogs", ctx, pod, containerID, logOptions, stdout, stderr)} +} + +func (_c *MockRuntime_GetContainerLogs_Call) Run(run func(ctx context.Context, pod *corev1.Pod, containerID container.ContainerID, logOptions *corev1.PodLogOptions, stdout io.Writer, stderr io.Writer)) *MockRuntime_GetContainerLogs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*corev1.Pod), args[2].(container.ContainerID), args[3].(*corev1.PodLogOptions), args[4].(io.Writer), args[5].(io.Writer)) + }) + return _c +} + +func (_c *MockRuntime_GetContainerLogs_Call) Return(err error) *MockRuntime_GetContainerLogs_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockRuntime_GetContainerLogs_Call) RunAndReturn(run func(context.Context, *corev1.Pod, container.ContainerID, *corev1.PodLogOptions, io.Writer, io.Writer) error) *MockRuntime_GetContainerLogs_Call { + _c.Call.Return(run) + return _c +} + +// GetImageRef provides a mock function with given fields: ctx, image +func (_m *MockRuntime) GetImageRef(ctx context.Context, image container.ImageSpec) (string, error) { + ret := _m.Called(ctx, image) + + if len(ret) == 0 { + panic("no return value specified for GetImageRef") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, container.ImageSpec) (string, error)); ok { + return rf(ctx, image) + } + if rf, ok := ret.Get(0).(func(context.Context, container.ImageSpec) string); ok { + r0 = rf(ctx, image) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, container.ImageSpec) error); ok { + r1 = rf(ctx, image) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_GetImageRef_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetImageRef' +type MockRuntime_GetImageRef_Call struct { + *mock.Call +} + +// GetImageRef is a helper method to define mock.On call +// - ctx context.Context +// - image container.ImageSpec +func (_e *MockRuntime_Expecter) GetImageRef(ctx interface{}, image interface{}) *MockRuntime_GetImageRef_Call { + return &MockRuntime_GetImageRef_Call{Call: _e.mock.On("GetImageRef", ctx, image)} +} + +func (_c *MockRuntime_GetImageRef_Call) Run(run func(ctx context.Context, image container.ImageSpec)) *MockRuntime_GetImageRef_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(container.ImageSpec)) + }) + return _c +} + +func (_c *MockRuntime_GetImageRef_Call) Return(_a0 string, _a1 error) *MockRuntime_GetImageRef_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_GetImageRef_Call) RunAndReturn(run func(context.Context, container.ImageSpec) (string, error)) *MockRuntime_GetImageRef_Call { + _c.Call.Return(run) + return _c +} + +// GetImageSize provides a mock function with given fields: ctx, image +func (_m *MockRuntime) GetImageSize(ctx context.Context, image container.ImageSpec) (uint64, error) { + ret := _m.Called(ctx, image) + + if len(ret) == 0 { + panic("no return value specified for GetImageSize") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, container.ImageSpec) (uint64, error)); ok { + return rf(ctx, image) + } + if rf, ok := ret.Get(0).(func(context.Context, container.ImageSpec) uint64); ok { + r0 = rf(ctx, image) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context, container.ImageSpec) error); ok { + r1 = rf(ctx, image) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_GetImageSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetImageSize' +type MockRuntime_GetImageSize_Call struct { + *mock.Call +} + +// GetImageSize is a helper method to define mock.On call +// - ctx context.Context +// - image container.ImageSpec +func (_e *MockRuntime_Expecter) GetImageSize(ctx interface{}, image interface{}) *MockRuntime_GetImageSize_Call { + return &MockRuntime_GetImageSize_Call{Call: _e.mock.On("GetImageSize", ctx, image)} +} + +func (_c *MockRuntime_GetImageSize_Call) Run(run func(ctx context.Context, image container.ImageSpec)) *MockRuntime_GetImageSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(container.ImageSpec)) + }) + return _c +} + +func (_c *MockRuntime_GetImageSize_Call) Return(_a0 uint64, _a1 error) *MockRuntime_GetImageSize_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_GetImageSize_Call) RunAndReturn(run func(context.Context, container.ImageSpec) (uint64, error)) *MockRuntime_GetImageSize_Call { + _c.Call.Return(run) + return _c +} + +// GetPodStatus provides a mock function with given fields: ctx, uid, name, namespace +func (_m *MockRuntime) GetPodStatus(ctx context.Context, uid types.UID, name string, namespace string) (*container.PodStatus, error) { + ret := _m.Called(ctx, uid, name, namespace) + + if len(ret) == 0 { + panic("no return value specified for GetPodStatus") + } + + var r0 *container.PodStatus + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.UID, string, string) (*container.PodStatus, error)); ok { + return rf(ctx, uid, name, namespace) + } + if rf, ok := ret.Get(0).(func(context.Context, types.UID, string, string) *container.PodStatus); ok { + r0 = rf(ctx, uid, name, namespace) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*container.PodStatus) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.UID, string, string) error); ok { + r1 = rf(ctx, uid, name, namespace) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_GetPodStatus_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodStatus' +type MockRuntime_GetPodStatus_Call struct { + *mock.Call +} + +// GetPodStatus is a helper method to define mock.On call +// - ctx context.Context +// - uid types.UID +// - name string +// - namespace string +func (_e *MockRuntime_Expecter) GetPodStatus(ctx interface{}, uid interface{}, name interface{}, namespace interface{}) *MockRuntime_GetPodStatus_Call { + return &MockRuntime_GetPodStatus_Call{Call: _e.mock.On("GetPodStatus", ctx, uid, name, namespace)} +} + +func (_c *MockRuntime_GetPodStatus_Call) Run(run func(ctx context.Context, uid types.UID, name string, namespace string)) *MockRuntime_GetPodStatus_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.UID), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockRuntime_GetPodStatus_Call) Return(_a0 *container.PodStatus, _a1 error) *MockRuntime_GetPodStatus_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_GetPodStatus_Call) RunAndReturn(run func(context.Context, types.UID, string, string) (*container.PodStatus, error)) *MockRuntime_GetPodStatus_Call { + _c.Call.Return(run) + return _c +} + +// GetPods provides a mock function with given fields: ctx, all +func (_m *MockRuntime) GetPods(ctx context.Context, all bool) ([]*container.Pod, error) { + ret := _m.Called(ctx, all) + + 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, bool) ([]*container.Pod, error)); ok { + return rf(ctx, all) + } + if rf, ok := ret.Get(0).(func(context.Context, bool) []*container.Pod); ok { + r0 = rf(ctx, all) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*container.Pod) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, bool) error); ok { + r1 = rf(ctx, all) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_GetPods_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPods' +type MockRuntime_GetPods_Call struct { + *mock.Call +} + +// GetPods is a helper method to define mock.On call +// - ctx context.Context +// - all bool +func (_e *MockRuntime_Expecter) GetPods(ctx interface{}, all interface{}) *MockRuntime_GetPods_Call { + return &MockRuntime_GetPods_Call{Call: _e.mock.On("GetPods", ctx, all)} +} + +func (_c *MockRuntime_GetPods_Call) Run(run func(ctx context.Context, all bool)) *MockRuntime_GetPods_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(bool)) + }) + return _c +} + +func (_c *MockRuntime_GetPods_Call) Return(_a0 []*container.Pod, _a1 error) *MockRuntime_GetPods_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_GetPods_Call) RunAndReturn(run func(context.Context, bool) ([]*container.Pod, error)) *MockRuntime_GetPods_Call { + _c.Call.Return(run) + return _c +} + +// ImageFsInfo provides a mock function with given fields: ctx +func (_m *MockRuntime) ImageFsInfo(ctx context.Context) (*v1.ImageFsInfoResponse, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ImageFsInfo") + } + + var r0 *v1.ImageFsInfoResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*v1.ImageFsInfoResponse, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *v1.ImageFsInfoResponse); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ImageFsInfoResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_ImageFsInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ImageFsInfo' +type MockRuntime_ImageFsInfo_Call struct { + *mock.Call +} + +// ImageFsInfo is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockRuntime_Expecter) ImageFsInfo(ctx interface{}) *MockRuntime_ImageFsInfo_Call { + return &MockRuntime_ImageFsInfo_Call{Call: _e.mock.On("ImageFsInfo", ctx)} +} + +func (_c *MockRuntime_ImageFsInfo_Call) Run(run func(ctx context.Context)) *MockRuntime_ImageFsInfo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockRuntime_ImageFsInfo_Call) Return(_a0 *v1.ImageFsInfoResponse, _a1 error) *MockRuntime_ImageFsInfo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_ImageFsInfo_Call) RunAndReturn(run func(context.Context) (*v1.ImageFsInfoResponse, error)) *MockRuntime_ImageFsInfo_Call { + _c.Call.Return(run) + return _c +} + +// ImageStats provides a mock function with given fields: ctx +func (_m *MockRuntime) ImageStats(ctx context.Context) (*container.ImageStats, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ImageStats") + } + + var r0 *container.ImageStats + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*container.ImageStats, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *container.ImageStats); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*container.ImageStats) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_ImageStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ImageStats' +type MockRuntime_ImageStats_Call struct { + *mock.Call +} + +// ImageStats is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockRuntime_Expecter) ImageStats(ctx interface{}) *MockRuntime_ImageStats_Call { + return &MockRuntime_ImageStats_Call{Call: _e.mock.On("ImageStats", ctx)} +} + +func (_c *MockRuntime_ImageStats_Call) Run(run func(ctx context.Context)) *MockRuntime_ImageStats_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockRuntime_ImageStats_Call) Return(_a0 *container.ImageStats, _a1 error) *MockRuntime_ImageStats_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_ImageStats_Call) RunAndReturn(run func(context.Context) (*container.ImageStats, error)) *MockRuntime_ImageStats_Call { + _c.Call.Return(run) + return _c +} + +// KillPod provides a mock function with given fields: ctx, pod, runningPod, gracePeriodOverride +func (_m *MockRuntime) KillPod(ctx context.Context, pod *corev1.Pod, runningPod container.Pod, gracePeriodOverride *int64) error { + ret := _m.Called(ctx, pod, runningPod, gracePeriodOverride) + + if len(ret) == 0 { + panic("no return value specified for KillPod") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *corev1.Pod, container.Pod, *int64) error); ok { + r0 = rf(ctx, pod, runningPod, gracePeriodOverride) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntime_KillPod_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'KillPod' +type MockRuntime_KillPod_Call struct { + *mock.Call +} + +// KillPod is a helper method to define mock.On call +// - ctx context.Context +// - pod *corev1.Pod +// - runningPod container.Pod +// - gracePeriodOverride *int64 +func (_e *MockRuntime_Expecter) KillPod(ctx interface{}, pod interface{}, runningPod interface{}, gracePeriodOverride interface{}) *MockRuntime_KillPod_Call { + return &MockRuntime_KillPod_Call{Call: _e.mock.On("KillPod", ctx, pod, runningPod, gracePeriodOverride)} +} + +func (_c *MockRuntime_KillPod_Call) Run(run func(ctx context.Context, pod *corev1.Pod, runningPod container.Pod, gracePeriodOverride *int64)) *MockRuntime_KillPod_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*corev1.Pod), args[2].(container.Pod), args[3].(*int64)) + }) + return _c +} + +func (_c *MockRuntime_KillPod_Call) Return(_a0 error) *MockRuntime_KillPod_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntime_KillPod_Call) RunAndReturn(run func(context.Context, *corev1.Pod, container.Pod, *int64) error) *MockRuntime_KillPod_Call { + _c.Call.Return(run) + return _c +} + +// ListImages provides a mock function with given fields: ctx +func (_m *MockRuntime) ListImages(ctx context.Context) ([]container.Image, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ListImages") + } + + var r0 []container.Image + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]container.Image, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []container.Image); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]container.Image) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_ListImages_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListImages' +type MockRuntime_ListImages_Call struct { + *mock.Call +} + +// ListImages is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockRuntime_Expecter) ListImages(ctx interface{}) *MockRuntime_ListImages_Call { + return &MockRuntime_ListImages_Call{Call: _e.mock.On("ListImages", ctx)} +} + +func (_c *MockRuntime_ListImages_Call) Run(run func(ctx context.Context)) *MockRuntime_ListImages_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockRuntime_ListImages_Call) Return(_a0 []container.Image, _a1 error) *MockRuntime_ListImages_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_ListImages_Call) RunAndReturn(run func(context.Context) ([]container.Image, error)) *MockRuntime_ListImages_Call { + _c.Call.Return(run) + return _c +} + +// ListMetricDescriptors provides a mock function with given fields: ctx +func (_m *MockRuntime) ListMetricDescriptors(ctx context.Context) ([]*v1.MetricDescriptor, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ListMetricDescriptors") + } + + var r0 []*v1.MetricDescriptor + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]*v1.MetricDescriptor, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []*v1.MetricDescriptor); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*v1.MetricDescriptor) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_ListMetricDescriptors_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListMetricDescriptors' +type MockRuntime_ListMetricDescriptors_Call struct { + *mock.Call +} + +// ListMetricDescriptors is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockRuntime_Expecter) ListMetricDescriptors(ctx interface{}) *MockRuntime_ListMetricDescriptors_Call { + return &MockRuntime_ListMetricDescriptors_Call{Call: _e.mock.On("ListMetricDescriptors", ctx)} +} + +func (_c *MockRuntime_ListMetricDescriptors_Call) Run(run func(ctx context.Context)) *MockRuntime_ListMetricDescriptors_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockRuntime_ListMetricDescriptors_Call) Return(_a0 []*v1.MetricDescriptor, _a1 error) *MockRuntime_ListMetricDescriptors_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_ListMetricDescriptors_Call) RunAndReturn(run func(context.Context) ([]*v1.MetricDescriptor, error)) *MockRuntime_ListMetricDescriptors_Call { + _c.Call.Return(run) + return _c +} + +// ListPodSandboxMetrics provides a mock function with given fields: ctx +func (_m *MockRuntime) ListPodSandboxMetrics(ctx context.Context) ([]*v1.PodSandboxMetrics, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ListPodSandboxMetrics") + } + + var r0 []*v1.PodSandboxMetrics + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]*v1.PodSandboxMetrics, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []*v1.PodSandboxMetrics); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*v1.PodSandboxMetrics) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_ListPodSandboxMetrics_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListPodSandboxMetrics' +type MockRuntime_ListPodSandboxMetrics_Call struct { + *mock.Call +} + +// ListPodSandboxMetrics is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockRuntime_Expecter) ListPodSandboxMetrics(ctx interface{}) *MockRuntime_ListPodSandboxMetrics_Call { + return &MockRuntime_ListPodSandboxMetrics_Call{Call: _e.mock.On("ListPodSandboxMetrics", ctx)} +} + +func (_c *MockRuntime_ListPodSandboxMetrics_Call) Run(run func(ctx context.Context)) *MockRuntime_ListPodSandboxMetrics_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockRuntime_ListPodSandboxMetrics_Call) Return(_a0 []*v1.PodSandboxMetrics, _a1 error) *MockRuntime_ListPodSandboxMetrics_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_ListPodSandboxMetrics_Call) RunAndReturn(run func(context.Context) ([]*v1.PodSandboxMetrics, error)) *MockRuntime_ListPodSandboxMetrics_Call { + _c.Call.Return(run) + return _c +} + +// PullImage provides a mock function with given fields: ctx, image, pullSecrets, podSandboxConfig +func (_m *MockRuntime) PullImage(ctx context.Context, image container.ImageSpec, pullSecrets []corev1.Secret, podSandboxConfig *v1.PodSandboxConfig) (string, error) { + ret := _m.Called(ctx, image, pullSecrets, podSandboxConfig) + + if len(ret) == 0 { + panic("no return value specified for PullImage") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, container.ImageSpec, []corev1.Secret, *v1.PodSandboxConfig) (string, error)); ok { + return rf(ctx, image, pullSecrets, podSandboxConfig) + } + if rf, ok := ret.Get(0).(func(context.Context, container.ImageSpec, []corev1.Secret, *v1.PodSandboxConfig) string); ok { + r0 = rf(ctx, image, pullSecrets, podSandboxConfig) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, container.ImageSpec, []corev1.Secret, *v1.PodSandboxConfig) error); ok { + r1 = rf(ctx, image, pullSecrets, podSandboxConfig) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_PullImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PullImage' +type MockRuntime_PullImage_Call struct { + *mock.Call +} + +// PullImage is a helper method to define mock.On call +// - ctx context.Context +// - image container.ImageSpec +// - pullSecrets []corev1.Secret +// - podSandboxConfig *v1.PodSandboxConfig +func (_e *MockRuntime_Expecter) PullImage(ctx interface{}, image interface{}, pullSecrets interface{}, podSandboxConfig interface{}) *MockRuntime_PullImage_Call { + return &MockRuntime_PullImage_Call{Call: _e.mock.On("PullImage", ctx, image, pullSecrets, podSandboxConfig)} +} + +func (_c *MockRuntime_PullImage_Call) Run(run func(ctx context.Context, image container.ImageSpec, pullSecrets []corev1.Secret, podSandboxConfig *v1.PodSandboxConfig)) *MockRuntime_PullImage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(container.ImageSpec), args[2].([]corev1.Secret), args[3].(*v1.PodSandboxConfig)) + }) + return _c +} + +func (_c *MockRuntime_PullImage_Call) Return(_a0 string, _a1 error) *MockRuntime_PullImage_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_PullImage_Call) RunAndReturn(run func(context.Context, container.ImageSpec, []corev1.Secret, *v1.PodSandboxConfig) (string, error)) *MockRuntime_PullImage_Call { + _c.Call.Return(run) + return _c +} + +// RemoveImage provides a mock function with given fields: ctx, image +func (_m *MockRuntime) RemoveImage(ctx context.Context, image container.ImageSpec) error { + ret := _m.Called(ctx, image) + + if len(ret) == 0 { + panic("no return value specified for RemoveImage") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, container.ImageSpec) error); ok { + r0 = rf(ctx, image) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntime_RemoveImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveImage' +type MockRuntime_RemoveImage_Call struct { + *mock.Call +} + +// RemoveImage is a helper method to define mock.On call +// - ctx context.Context +// - image container.ImageSpec +func (_e *MockRuntime_Expecter) RemoveImage(ctx interface{}, image interface{}) *MockRuntime_RemoveImage_Call { + return &MockRuntime_RemoveImage_Call{Call: _e.mock.On("RemoveImage", ctx, image)} +} + +func (_c *MockRuntime_RemoveImage_Call) Run(run func(ctx context.Context, image container.ImageSpec)) *MockRuntime_RemoveImage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(container.ImageSpec)) + }) + return _c +} + +func (_c *MockRuntime_RemoveImage_Call) Return(_a0 error) *MockRuntime_RemoveImage_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntime_RemoveImage_Call) RunAndReturn(run func(context.Context, container.ImageSpec) error) *MockRuntime_RemoveImage_Call { + _c.Call.Return(run) + return _c +} + +// Status provides a mock function with given fields: ctx +func (_m *MockRuntime) Status(ctx context.Context) (*container.RuntimeStatus, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Status") + } + + var r0 *container.RuntimeStatus + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*container.RuntimeStatus, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *container.RuntimeStatus); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*container.RuntimeStatus) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_Status_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Status' +type MockRuntime_Status_Call struct { + *mock.Call +} + +// Status is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockRuntime_Expecter) Status(ctx interface{}) *MockRuntime_Status_Call { + return &MockRuntime_Status_Call{Call: _e.mock.On("Status", ctx)} +} + +func (_c *MockRuntime_Status_Call) Run(run func(ctx context.Context)) *MockRuntime_Status_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockRuntime_Status_Call) Return(_a0 *container.RuntimeStatus, _a1 error) *MockRuntime_Status_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_Status_Call) RunAndReturn(run func(context.Context) (*container.RuntimeStatus, error)) *MockRuntime_Status_Call { + _c.Call.Return(run) + return _c +} + +// SyncPod provides a mock function with given fields: ctx, pod, podStatus, pullSecrets, backOff +func (_m *MockRuntime) SyncPod(ctx context.Context, pod *corev1.Pod, podStatus *container.PodStatus, pullSecrets []corev1.Secret, backOff *flowcontrol.Backoff) container.PodSyncResult { + ret := _m.Called(ctx, pod, podStatus, pullSecrets, backOff) + + if len(ret) == 0 { + panic("no return value specified for SyncPod") + } + + var r0 container.PodSyncResult + if rf, ok := ret.Get(0).(func(context.Context, *corev1.Pod, *container.PodStatus, []corev1.Secret, *flowcontrol.Backoff) container.PodSyncResult); ok { + r0 = rf(ctx, pod, podStatus, pullSecrets, backOff) + } else { + r0 = ret.Get(0).(container.PodSyncResult) + } + + return r0 +} + +// MockRuntime_SyncPod_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SyncPod' +type MockRuntime_SyncPod_Call struct { + *mock.Call +} + +// SyncPod is a helper method to define mock.On call +// - ctx context.Context +// - pod *corev1.Pod +// - podStatus *container.PodStatus +// - pullSecrets []corev1.Secret +// - backOff *flowcontrol.Backoff +func (_e *MockRuntime_Expecter) SyncPod(ctx interface{}, pod interface{}, podStatus interface{}, pullSecrets interface{}, backOff interface{}) *MockRuntime_SyncPod_Call { + return &MockRuntime_SyncPod_Call{Call: _e.mock.On("SyncPod", ctx, pod, podStatus, pullSecrets, backOff)} +} + +func (_c *MockRuntime_SyncPod_Call) Run(run func(ctx context.Context, pod *corev1.Pod, podStatus *container.PodStatus, pullSecrets []corev1.Secret, backOff *flowcontrol.Backoff)) *MockRuntime_SyncPod_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*corev1.Pod), args[2].(*container.PodStatus), args[3].([]corev1.Secret), args[4].(*flowcontrol.Backoff)) + }) + return _c +} + +func (_c *MockRuntime_SyncPod_Call) Return(_a0 container.PodSyncResult) *MockRuntime_SyncPod_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntime_SyncPod_Call) RunAndReturn(run func(context.Context, *corev1.Pod, *container.PodStatus, []corev1.Secret, *flowcontrol.Backoff) container.PodSyncResult) *MockRuntime_SyncPod_Call { + _c.Call.Return(run) + return _c +} + +// Type provides a mock function with given fields: +func (_m *MockRuntime) Type() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Type") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// MockRuntime_Type_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Type' +type MockRuntime_Type_Call struct { + *mock.Call +} + +// Type is a helper method to define mock.On call +func (_e *MockRuntime_Expecter) Type() *MockRuntime_Type_Call { + return &MockRuntime_Type_Call{Call: _e.mock.On("Type")} +} + +func (_c *MockRuntime_Type_Call) Run(run func()) *MockRuntime_Type_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockRuntime_Type_Call) Return(_a0 string) *MockRuntime_Type_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntime_Type_Call) RunAndReturn(run func() string) *MockRuntime_Type_Call { + _c.Call.Return(run) + return _c +} + +// UpdatePodCIDR provides a mock function with given fields: ctx, podCIDR +func (_m *MockRuntime) UpdatePodCIDR(ctx context.Context, podCIDR string) error { + ret := _m.Called(ctx, podCIDR) + + if len(ret) == 0 { + panic("no return value specified for UpdatePodCIDR") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, podCIDR) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntime_UpdatePodCIDR_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdatePodCIDR' +type MockRuntime_UpdatePodCIDR_Call struct { + *mock.Call +} + +// UpdatePodCIDR is a helper method to define mock.On call +// - ctx context.Context +// - podCIDR string +func (_e *MockRuntime_Expecter) UpdatePodCIDR(ctx interface{}, podCIDR interface{}) *MockRuntime_UpdatePodCIDR_Call { + return &MockRuntime_UpdatePodCIDR_Call{Call: _e.mock.On("UpdatePodCIDR", ctx, podCIDR)} +} + +func (_c *MockRuntime_UpdatePodCIDR_Call) Run(run func(ctx context.Context, podCIDR string)) *MockRuntime_UpdatePodCIDR_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockRuntime_UpdatePodCIDR_Call) Return(_a0 error) *MockRuntime_UpdatePodCIDR_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntime_UpdatePodCIDR_Call) RunAndReturn(run func(context.Context, string) error) *MockRuntime_UpdatePodCIDR_Call { + _c.Call.Return(run) + return _c +} + +// Version provides a mock function with given fields: ctx +func (_m *MockRuntime) Version(ctx context.Context) (container.Version, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Version") + } + + var r0 container.Version + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (container.Version, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) container.Version); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(container.Version) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntime_Version_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Version' +type MockRuntime_Version_Call struct { + *mock.Call +} + +// Version is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockRuntime_Expecter) Version(ctx interface{}) *MockRuntime_Version_Call { + return &MockRuntime_Version_Call{Call: _e.mock.On("Version", ctx)} +} + +func (_c *MockRuntime_Version_Call) Run(run func(ctx context.Context)) *MockRuntime_Version_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockRuntime_Version_Call) Return(_a0 container.Version, _a1 error) *MockRuntime_Version_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntime_Version_Call) RunAndReturn(run func(context.Context) (container.Version, error)) *MockRuntime_Version_Call { + _c.Call.Return(run) + return _c +} + +// NewMockRuntime creates a new instance of MockRuntime. 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 NewMockRuntime(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRuntime { + mock := &MockRuntime{} + 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 *MockRuntime) EXPECT() *MockRuntimeMockRecorder { - return m.recorder -} - -// APIVersion mocks base method. -func (m *MockRuntime) APIVersion() (container.Version, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "APIVersion") - ret0, _ := ret[0].(container.Version) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// APIVersion indicates an expected call of APIVersion. -func (mr *MockRuntimeMockRecorder) APIVersion() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "APIVersion", reflect.TypeOf((*MockRuntime)(nil).APIVersion)) -} - -// CheckpointContainer mocks base method. -func (m *MockRuntime) CheckpointContainer(ctx context.Context, options *v10.CheckpointContainerRequest) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CheckpointContainer", ctx, options) - ret0, _ := ret[0].(error) - return ret0 -} - -// CheckpointContainer indicates an expected call of CheckpointContainer. -func (mr *MockRuntimeMockRecorder) CheckpointContainer(ctx, options any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CheckpointContainer", reflect.TypeOf((*MockRuntime)(nil).CheckpointContainer), ctx, options) -} - -// DeleteContainer mocks base method. -func (m *MockRuntime) DeleteContainer(ctx context.Context, containerID container.ContainerID) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteContainer", ctx, containerID) - ret0, _ := ret[0].(error) - return ret0 -} - -// DeleteContainer indicates an expected call of DeleteContainer. -func (mr *MockRuntimeMockRecorder) DeleteContainer(ctx, containerID any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteContainer", reflect.TypeOf((*MockRuntime)(nil).DeleteContainer), ctx, containerID) -} - -// GarbageCollect mocks base method. -func (m *MockRuntime) GarbageCollect(ctx context.Context, gcPolicy container.GCPolicy, allSourcesReady, evictNonDeletedPods bool) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GarbageCollect", ctx, gcPolicy, allSourcesReady, evictNonDeletedPods) - ret0, _ := ret[0].(error) - return ret0 -} - -// GarbageCollect indicates an expected call of GarbageCollect. -func (mr *MockRuntimeMockRecorder) GarbageCollect(ctx, gcPolicy, allSourcesReady, evictNonDeletedPods any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GarbageCollect", reflect.TypeOf((*MockRuntime)(nil).GarbageCollect), ctx, gcPolicy, allSourcesReady, evictNonDeletedPods) -} - -// GeneratePodStatus mocks base method. -func (m *MockRuntime) GeneratePodStatus(event *v10.ContainerEventResponse) (*container.PodStatus, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GeneratePodStatus", event) - ret0, _ := ret[0].(*container.PodStatus) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GeneratePodStatus indicates an expected call of GeneratePodStatus. -func (mr *MockRuntimeMockRecorder) GeneratePodStatus(event any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GeneratePodStatus", reflect.TypeOf((*MockRuntime)(nil).GeneratePodStatus), event) -} - -// GetContainerLogs mocks base method. -func (m *MockRuntime) GetContainerLogs(ctx context.Context, pod *v1.Pod, containerID container.ContainerID, logOptions *v1.PodLogOptions, stdout, stderr io.Writer) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetContainerLogs", ctx, pod, containerID, logOptions, stdout, stderr) - ret0, _ := ret[0].(error) - return ret0 -} - -// GetContainerLogs indicates an expected call of GetContainerLogs. -func (mr *MockRuntimeMockRecorder) GetContainerLogs(ctx, pod, containerID, logOptions, stdout, stderr any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetContainerLogs", reflect.TypeOf((*MockRuntime)(nil).GetContainerLogs), ctx, pod, containerID, logOptions, stdout, stderr) -} - -// GetImageRef mocks base method. -func (m *MockRuntime) GetImageRef(ctx context.Context, image container.ImageSpec) (string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetImageRef", ctx, image) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetImageRef indicates an expected call of GetImageRef. -func (mr *MockRuntimeMockRecorder) GetImageRef(ctx, image any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetImageRef", reflect.TypeOf((*MockRuntime)(nil).GetImageRef), ctx, image) -} - -// GetImageSize mocks base method. -func (m *MockRuntime) GetImageSize(ctx context.Context, image container.ImageSpec) (uint64, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetImageSize", ctx, image) - ret0, _ := ret[0].(uint64) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetImageSize indicates an expected call of GetImageSize. -func (mr *MockRuntimeMockRecorder) GetImageSize(ctx, image any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetImageSize", reflect.TypeOf((*MockRuntime)(nil).GetImageSize), ctx, image) -} - -// GetPodStatus mocks base method. -func (m *MockRuntime) GetPodStatus(ctx context.Context, uid types.UID, name, namespace string) (*container.PodStatus, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetPodStatus", ctx, uid, name, namespace) - ret0, _ := ret[0].(*container.PodStatus) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetPodStatus indicates an expected call of GetPodStatus. -func (mr *MockRuntimeMockRecorder) GetPodStatus(ctx, uid, name, namespace any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodStatus", reflect.TypeOf((*MockRuntime)(nil).GetPodStatus), ctx, uid, name, namespace) -} - -// GetPods mocks base method. -func (m *MockRuntime) GetPods(ctx context.Context, all bool) ([]*container.Pod, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetPods", ctx, all) - ret0, _ := ret[0].([]*container.Pod) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetPods indicates an expected call of GetPods. -func (mr *MockRuntimeMockRecorder) GetPods(ctx, all any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPods", reflect.TypeOf((*MockRuntime)(nil).GetPods), ctx, all) -} - -// ImageFsInfo mocks base method. -func (m *MockRuntime) ImageFsInfo(ctx context.Context) (*v10.ImageFsInfoResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ImageFsInfo", ctx) - ret0, _ := ret[0].(*v10.ImageFsInfoResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ImageFsInfo indicates an expected call of ImageFsInfo. -func (mr *MockRuntimeMockRecorder) ImageFsInfo(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageFsInfo", reflect.TypeOf((*MockRuntime)(nil).ImageFsInfo), ctx) -} - -// ImageStats mocks base method. -func (m *MockRuntime) ImageStats(ctx context.Context) (*container.ImageStats, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ImageStats", ctx) - ret0, _ := ret[0].(*container.ImageStats) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ImageStats indicates an expected call of ImageStats. -func (mr *MockRuntimeMockRecorder) ImageStats(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageStats", reflect.TypeOf((*MockRuntime)(nil).ImageStats), ctx) -} - -// KillPod mocks base method. -func (m *MockRuntime) KillPod(ctx context.Context, pod *v1.Pod, runningPod container.Pod, gracePeriodOverride *int64) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "KillPod", ctx, pod, runningPod, gracePeriodOverride) - ret0, _ := ret[0].(error) - return ret0 -} - -// KillPod indicates an expected call of KillPod. -func (mr *MockRuntimeMockRecorder) KillPod(ctx, pod, runningPod, gracePeriodOverride any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "KillPod", reflect.TypeOf((*MockRuntime)(nil).KillPod), ctx, pod, runningPod, gracePeriodOverride) -} - -// ListImages mocks base method. -func (m *MockRuntime) ListImages(ctx context.Context) ([]container.Image, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListImages", ctx) - ret0, _ := ret[0].([]container.Image) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ListImages indicates an expected call of ListImages. -func (mr *MockRuntimeMockRecorder) ListImages(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListImages", reflect.TypeOf((*MockRuntime)(nil).ListImages), ctx) -} - -// ListMetricDescriptors mocks base method. -func (m *MockRuntime) ListMetricDescriptors(ctx context.Context) ([]*v10.MetricDescriptor, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListMetricDescriptors", ctx) - ret0, _ := ret[0].([]*v10.MetricDescriptor) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ListMetricDescriptors indicates an expected call of ListMetricDescriptors. -func (mr *MockRuntimeMockRecorder) ListMetricDescriptors(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListMetricDescriptors", reflect.TypeOf((*MockRuntime)(nil).ListMetricDescriptors), ctx) -} - -// ListPodSandboxMetrics mocks base method. -func (m *MockRuntime) ListPodSandboxMetrics(ctx context.Context) ([]*v10.PodSandboxMetrics, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListPodSandboxMetrics", ctx) - ret0, _ := ret[0].([]*v10.PodSandboxMetrics) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ListPodSandboxMetrics indicates an expected call of ListPodSandboxMetrics. -func (mr *MockRuntimeMockRecorder) ListPodSandboxMetrics(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListPodSandboxMetrics", reflect.TypeOf((*MockRuntime)(nil).ListPodSandboxMetrics), ctx) -} - -// PullImage mocks base method. -func (m *MockRuntime) PullImage(ctx context.Context, image container.ImageSpec, pullSecrets []v1.Secret, podSandboxConfig *v10.PodSandboxConfig) (string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PullImage", ctx, image, pullSecrets, podSandboxConfig) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PullImage indicates an expected call of PullImage. -func (mr *MockRuntimeMockRecorder) PullImage(ctx, image, pullSecrets, podSandboxConfig any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PullImage", reflect.TypeOf((*MockRuntime)(nil).PullImage), ctx, image, pullSecrets, podSandboxConfig) -} - -// RemoveImage mocks base method. -func (m *MockRuntime) RemoveImage(ctx context.Context, image container.ImageSpec) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RemoveImage", ctx, image) - ret0, _ := ret[0].(error) - return ret0 -} - -// RemoveImage indicates an expected call of RemoveImage. -func (mr *MockRuntimeMockRecorder) RemoveImage(ctx, image any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveImage", reflect.TypeOf((*MockRuntime)(nil).RemoveImage), ctx, image) -} - -// Status mocks base method. -func (m *MockRuntime) Status(ctx context.Context) (*container.RuntimeStatus, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Status", ctx) - ret0, _ := ret[0].(*container.RuntimeStatus) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Status indicates an expected call of Status. -func (mr *MockRuntimeMockRecorder) Status(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Status", reflect.TypeOf((*MockRuntime)(nil).Status), ctx) -} - -// SyncPod mocks base method. -func (m *MockRuntime) SyncPod(ctx context.Context, pod *v1.Pod, podStatus *container.PodStatus, pullSecrets []v1.Secret, backOff *flowcontrol.Backoff) container.PodSyncResult { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SyncPod", ctx, pod, podStatus, pullSecrets, backOff) - ret0, _ := ret[0].(container.PodSyncResult) - return ret0 -} - -// SyncPod indicates an expected call of SyncPod. -func (mr *MockRuntimeMockRecorder) SyncPod(ctx, pod, podStatus, pullSecrets, backOff any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SyncPod", reflect.TypeOf((*MockRuntime)(nil).SyncPod), ctx, pod, podStatus, pullSecrets, backOff) -} - -// Type mocks base method. -func (m *MockRuntime) Type() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Type") - ret0, _ := ret[0].(string) - return ret0 -} - -// Type indicates an expected call of Type. -func (mr *MockRuntimeMockRecorder) Type() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Type", reflect.TypeOf((*MockRuntime)(nil).Type)) -} - -// UpdatePodCIDR mocks base method. -func (m *MockRuntime) UpdatePodCIDR(ctx context.Context, podCIDR string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdatePodCIDR", ctx, podCIDR) - ret0, _ := ret[0].(error) - return ret0 -} - -// UpdatePodCIDR indicates an expected call of UpdatePodCIDR. -func (mr *MockRuntimeMockRecorder) UpdatePodCIDR(ctx, podCIDR any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdatePodCIDR", reflect.TypeOf((*MockRuntime)(nil).UpdatePodCIDR), ctx, podCIDR) -} - -// Version mocks base method. -func (m *MockRuntime) Version(ctx context.Context) (container.Version, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Version", ctx) - ret0, _ := ret[0].(container.Version) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Version indicates an expected call of Version. -func (mr *MockRuntimeMockRecorder) Version(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Version", reflect.TypeOf((*MockRuntime)(nil).Version), ctx) -} - -// MockStreamingRuntime is a mock of StreamingRuntime interface. -type MockStreamingRuntime struct { - ctrl *gomock.Controller - recorder *MockStreamingRuntimeMockRecorder -} - -// MockStreamingRuntimeMockRecorder is the mock recorder for MockStreamingRuntime. -type MockStreamingRuntimeMockRecorder struct { - mock *MockStreamingRuntime -} - -// NewMockStreamingRuntime creates a new mock instance. -func NewMockStreamingRuntime(ctrl *gomock.Controller) *MockStreamingRuntime { - mock := &MockStreamingRuntime{ctrl: ctrl} - mock.recorder = &MockStreamingRuntimeMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockStreamingRuntime) EXPECT() *MockStreamingRuntimeMockRecorder { - return m.recorder -} - -// GetAttach mocks base method. -func (m *MockStreamingRuntime) GetAttach(ctx context.Context, id container.ContainerID, stdin, stdout, stderr, tty bool) (*url.URL, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAttach", ctx, id, stdin, stdout, stderr, tty) - ret0, _ := ret[0].(*url.URL) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetAttach indicates an expected call of GetAttach. -func (mr *MockStreamingRuntimeMockRecorder) GetAttach(ctx, id, stdin, stdout, stderr, tty any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAttach", reflect.TypeOf((*MockStreamingRuntime)(nil).GetAttach), ctx, id, stdin, stdout, stderr, tty) -} - -// GetExec mocks base method. -func (m *MockStreamingRuntime) GetExec(ctx context.Context, id container.ContainerID, cmd []string, stdin, stdout, stderr, tty bool) (*url.URL, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetExec", ctx, id, cmd, stdin, stdout, stderr, tty) - ret0, _ := ret[0].(*url.URL) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetExec indicates an expected call of GetExec. -func (mr *MockStreamingRuntimeMockRecorder) GetExec(ctx, id, cmd, stdin, stdout, stderr, tty any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetExec", reflect.TypeOf((*MockStreamingRuntime)(nil).GetExec), ctx, id, cmd, stdin, stdout, stderr, tty) -} - -// GetPortForward mocks base method. -func (m *MockStreamingRuntime) GetPortForward(ctx context.Context, podName, podNamespace string, podUID types.UID, ports []int32) (*url.URL, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetPortForward", ctx, podName, podNamespace, podUID, ports) - ret0, _ := ret[0].(*url.URL) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetPortForward indicates an expected call of GetPortForward. -func (mr *MockStreamingRuntimeMockRecorder) GetPortForward(ctx, podName, podNamespace, podUID, ports any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPortForward", reflect.TypeOf((*MockStreamingRuntime)(nil).GetPortForward), ctx, podName, podNamespace, podUID, ports) -} - -// MockImageService is a mock of ImageService interface. -type MockImageService struct { - ctrl *gomock.Controller - recorder *MockImageServiceMockRecorder -} - -// MockImageServiceMockRecorder is the mock recorder for MockImageService. -type MockImageServiceMockRecorder struct { - mock *MockImageService -} - -// NewMockImageService creates a new mock instance. -func NewMockImageService(ctrl *gomock.Controller) *MockImageService { - mock := &MockImageService{ctrl: ctrl} - mock.recorder = &MockImageServiceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockImageService) EXPECT() *MockImageServiceMockRecorder { - return m.recorder -} - -// GetImageRef mocks base method. -func (m *MockImageService) GetImageRef(ctx context.Context, image container.ImageSpec) (string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetImageRef", ctx, image) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetImageRef indicates an expected call of GetImageRef. -func (mr *MockImageServiceMockRecorder) GetImageRef(ctx, image any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetImageRef", reflect.TypeOf((*MockImageService)(nil).GetImageRef), ctx, image) -} - -// GetImageSize mocks base method. -func (m *MockImageService) GetImageSize(ctx context.Context, image container.ImageSpec) (uint64, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetImageSize", ctx, image) - ret0, _ := ret[0].(uint64) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetImageSize indicates an expected call of GetImageSize. -func (mr *MockImageServiceMockRecorder) GetImageSize(ctx, image any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetImageSize", reflect.TypeOf((*MockImageService)(nil).GetImageSize), ctx, image) -} - -// ImageFsInfo mocks base method. -func (m *MockImageService) ImageFsInfo(ctx context.Context) (*v10.ImageFsInfoResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ImageFsInfo", ctx) - ret0, _ := ret[0].(*v10.ImageFsInfoResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ImageFsInfo indicates an expected call of ImageFsInfo. -func (mr *MockImageServiceMockRecorder) ImageFsInfo(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageFsInfo", reflect.TypeOf((*MockImageService)(nil).ImageFsInfo), ctx) -} - -// ImageStats mocks base method. -func (m *MockImageService) ImageStats(ctx context.Context) (*container.ImageStats, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ImageStats", ctx) - ret0, _ := ret[0].(*container.ImageStats) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ImageStats indicates an expected call of ImageStats. -func (mr *MockImageServiceMockRecorder) ImageStats(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageStats", reflect.TypeOf((*MockImageService)(nil).ImageStats), ctx) -} - -// ListImages mocks base method. -func (m *MockImageService) ListImages(ctx context.Context) ([]container.Image, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListImages", ctx) - ret0, _ := ret[0].([]container.Image) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ListImages indicates an expected call of ListImages. -func (mr *MockImageServiceMockRecorder) ListImages(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListImages", reflect.TypeOf((*MockImageService)(nil).ListImages), ctx) -} - -// PullImage mocks base method. -func (m *MockImageService) PullImage(ctx context.Context, image container.ImageSpec, pullSecrets []v1.Secret, podSandboxConfig *v10.PodSandboxConfig) (string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PullImage", ctx, image, pullSecrets, podSandboxConfig) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PullImage indicates an expected call of PullImage. -func (mr *MockImageServiceMockRecorder) PullImage(ctx, image, pullSecrets, podSandboxConfig any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PullImage", reflect.TypeOf((*MockImageService)(nil).PullImage), ctx, image, pullSecrets, podSandboxConfig) -} - -// RemoveImage mocks base method. -func (m *MockImageService) RemoveImage(ctx context.Context, image container.ImageSpec) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RemoveImage", ctx, image) - ret0, _ := ret[0].(error) - return ret0 -} - -// RemoveImage indicates an expected call of RemoveImage. -func (mr *MockImageServiceMockRecorder) RemoveImage(ctx, image any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveImage", reflect.TypeOf((*MockImageService)(nil).RemoveImage), ctx, image) -} - -// MockAttacher is a mock of Attacher interface. -type MockAttacher struct { - ctrl *gomock.Controller - recorder *MockAttacherMockRecorder -} - -// MockAttacherMockRecorder is the mock recorder for MockAttacher. -type MockAttacherMockRecorder struct { - mock *MockAttacher -} - -// NewMockAttacher creates a new mock instance. -func NewMockAttacher(ctrl *gomock.Controller) *MockAttacher { - mock := &MockAttacher{ctrl: ctrl} - mock.recorder = &MockAttacherMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockAttacher) EXPECT() *MockAttacherMockRecorder { - return m.recorder -} - -// AttachContainer mocks base method. -func (m *MockAttacher) AttachContainer(ctx context.Context, id container.ContainerID, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AttachContainer", ctx, id, stdin, stdout, stderr, tty, resize) - ret0, _ := ret[0].(error) - return ret0 -} - -// AttachContainer indicates an expected call of AttachContainer. -func (mr *MockAttacherMockRecorder) AttachContainer(ctx, id, stdin, stdout, stderr, tty, resize any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AttachContainer", reflect.TypeOf((*MockAttacher)(nil).AttachContainer), ctx, id, stdin, stdout, stderr, tty, resize) -} - -// MockCommandRunner is a mock of CommandRunner interface. -type MockCommandRunner struct { - ctrl *gomock.Controller - recorder *MockCommandRunnerMockRecorder -} - -// MockCommandRunnerMockRecorder is the mock recorder for MockCommandRunner. -type MockCommandRunnerMockRecorder struct { - mock *MockCommandRunner -} - -// NewMockCommandRunner creates a new mock instance. -func NewMockCommandRunner(ctrl *gomock.Controller) *MockCommandRunner { - mock := &MockCommandRunner{ctrl: ctrl} - mock.recorder = &MockCommandRunnerMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockCommandRunner) EXPECT() *MockCommandRunnerMockRecorder { - return m.recorder -} - -// RunInContainer mocks base method. -func (m *MockCommandRunner) RunInContainer(ctx context.Context, id container.ContainerID, cmd []string, timeout time.Duration) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RunInContainer", ctx, id, cmd, timeout) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// RunInContainer indicates an expected call of RunInContainer. -func (mr *MockCommandRunnerMockRecorder) RunInContainer(ctx, id, cmd, timeout any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RunInContainer", reflect.TypeOf((*MockCommandRunner)(nil).RunInContainer), ctx, id, cmd, timeout) -} diff --git a/pkg/kubelet/eviction/.mockery.yaml b/pkg/kubelet/eviction/.mockery.yaml new file mode 100644 index 00000000000..e179b752c1d --- /dev/null +++ b/pkg/kubelet/eviction/.mockery.yaml @@ -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: diff --git a/pkg/kubelet/eviction/eviction_manager_test.go b/pkg/kubelet/eviction/eviction_manager_test.go index afb38d2a768..7da01fcc1fd 100644 --- a/pkg/kubelet/eviction/eviction_manager_test.go +++ b/pkg/kubelet/eviction/eviction_manager_test.go @@ -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} diff --git a/pkg/kubelet/eviction/memory_threshold_notifier_test.go b/pkg/kubelet/eviction/memory_threshold_notifier_test.go index 9b41f5eed3d..8e64988bf0c 100644 --- a/pkg/kubelet/eviction/memory_threshold_notifier_test.go +++ b/pkg/kubelet/eviction/memory_threshold_notifier_test.go @@ -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{}{} } diff --git a/pkg/kubelet/eviction/mock_cgroup_notifier_test.go b/pkg/kubelet/eviction/mock_cgroup_notifier_test.go new file mode 100644 index 00000000000..5c128ec98cd --- /dev/null +++ b/pkg/kubelet/eviction/mock_cgroup_notifier_test.go @@ -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 +} diff --git a/pkg/kubelet/eviction/mock_notifier_factory_test.go b/pkg/kubelet/eviction/mock_notifier_factory_test.go new file mode 100644 index 00000000000..3bdc12173b4 --- /dev/null +++ b/pkg/kubelet/eviction/mock_notifier_factory_test.go @@ -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 +} diff --git a/pkg/kubelet/eviction/mock_threshold_notifier_test.go b/pkg/kubelet/eviction/mock_threshold_notifier_test.go index 232dbc3f581..47841bd0109 100644 --- a/pkg/kubelet/eviction/mock_threshold_notifier_test.go +++ b/pkg/kubelet/eviction/mock_threshold_notifier_test.go @@ -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) -} diff --git a/pkg/kubelet/eviction/types.go b/pkg/kubelet/eviction/types.go index 3a83a3e31ef..7963698b840 100644 --- a/pkg/kubelet/eviction/types.go +++ b/pkg/kubelet/eviction/types.go @@ -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 ( diff --git a/pkg/kubelet/images/image_gc_manager_test.go b/pkg/kubelet/images/image_gc_manager_test.go index aae70e4b8ae..ec5ec9c85ae 100644 --- a/pkg/kubelet/images/image_gc_manager_test.go +++ b/pkg/kubelet/images/image_gc_manager_test.go @@ -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, diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index 55b8a02089c..027073e2a85 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -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, diff --git a/pkg/kubelet/kuberuntime/kuberuntime_gc_test.go b/pkg/kubelet/kuberuntime/kuberuntime_gc_test.go index 3f0207fb1aa..d0208fd07e5 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_gc_test.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_gc_test.go @@ -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) } diff --git a/pkg/kubelet/metrics/collectors/resource_metrics_test.go b/pkg/kubelet/metrics/collectors/resource_metrics_test.go index bf252822acf..29ab3f3f309 100644 --- a/pkg/kubelet/metrics/collectors/resource_metrics_test.go +++ b/pkg/kubelet/metrics/collectors/resource_metrics_test.go @@ -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 { diff --git a/pkg/kubelet/metrics/collectors/volume_stats_test.go b/pkg/kubelet/metrics/collectors/volume_stats_test.go index 07b46d82f9f..d5d2e824e8a 100644 --- a/pkg/kubelet/metrics/collectors/volume_stats_test.go +++ b/pkg/kubelet/metrics/collectors/volume_stats_test.go @@ -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) } diff --git a/pkg/kubelet/pleg/generic_test.go b/pkg/kubelet/pleg/generic_test.go index b8703f6011a..355ab2aabc6 100644 --- a/pkg/kubelet/pleg/generic_test.go +++ b/pkg/kubelet/pleg/generic_test.go @@ -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() diff --git a/pkg/kubelet/pod/.mockery.yaml b/pkg/kubelet/pod/.mockery.yaml new file mode 100644 index 00000000000..3a60e89a749 --- /dev/null +++ b/pkg/kubelet/pod/.mockery.yaml @@ -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: diff --git a/pkg/kubelet/pod/pod_manager.go b/pkg/kubelet/pod/pod_manager.go index a1c911e3a61..87363ac5f45 100644 --- a/pkg/kubelet/pod/pod_manager.go +++ b/pkg/kubelet/pod/pod_manager.go @@ -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 ( diff --git a/pkg/kubelet/pod/testing/mock_manager.go b/pkg/kubelet/pod/testing/mock_manager.go index e0ec89fda02..779318a0024 100644 --- a/pkg/kubelet/pod/testing/mock_manager.go +++ b/pkg/kubelet/pod/testing/mock_manager.go @@ -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) -} diff --git a/pkg/kubelet/runonce_test.go b/pkg/kubelet/runonce_test.go index 8693b8d4a1e..34e46e5963d 100644 --- a/pkg/kubelet/runonce_test.go +++ b/pkg/kubelet/runonce_test.go @@ -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{} diff --git a/pkg/kubelet/server/stats/.mockery.yaml b/pkg/kubelet/server/stats/.mockery.yaml new file mode 100644 index 00000000000..f419d6d8c5c --- /dev/null +++ b/pkg/kubelet/server/stats/.mockery.yaml @@ -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: diff --git a/pkg/kubelet/server/stats/handler.go b/pkg/kubelet/server/stats/handler.go index b25029024df..09c8cfbc212 100644 --- a/pkg/kubelet/server/stats/handler.go +++ b/pkg/kubelet/server/stats/handler.go @@ -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 ( diff --git a/pkg/kubelet/server/stats/summary.go b/pkg/kubelet/server/stats/summary.go index dacf3bf7e81..afc2f475a65 100644 --- a/pkg/kubelet/server/stats/summary.go +++ b/pkg/kubelet/server/stats/summary.go @@ -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 ( diff --git a/pkg/kubelet/server/stats/summary_test.go b/pkg/kubelet/server/stats/summary_test.go index aaeac7c5136..a818d513f24 100644 --- a/pkg/kubelet/server/stats/summary_test.go +++ b/pkg/kubelet/server/stats/summary_test.go @@ -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) diff --git a/pkg/kubelet/server/stats/summary_windows_test.go b/pkg/kubelet/server/stats/summary_windows_test.go index b0581cbfce9..27e74f285ec 100644 --- a/pkg/kubelet/server/stats/summary_windows_test.go +++ b/pkg/kubelet/server/stats/summary_windows_test.go @@ -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() diff --git a/pkg/kubelet/server/stats/testing/mock_stats_provider.go b/pkg/kubelet/server/stats/testing/mock_stats_provider.go index 585e7f6e61d..892598cf3c3 100644 --- a/pkg/kubelet/server/stats/testing/mock_stats_provider.go +++ b/pkg/kubelet/server/stats/testing/mock_stats_provider.go @@ -14,304 +14,1021 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by MockGen. DO NOT EDIT. -// Source: handler.go -// -// Generated by this command: -// -// mockgen -source=handler.go -destination=testing/mock_stats_provider.go -package=testing Provider -// +// Code generated by mockery v2.40.3. DO NOT EDIT. -// Package testing is a generated GoMock package. package testing import ( context "context" - reflect "reflect" - v1 "github.com/google/cadvisor/info/v1" - v2 "github.com/google/cadvisor/info/v2" - gomock "go.uber.org/mock/gomock" - v10 "k8s.io/api/core/v1" - types "k8s.io/apimachinery/pkg/types" - v1alpha1 "k8s.io/kubelet/pkg/apis/stats/v1alpha1" cm "k8s.io/kubernetes/pkg/kubelet/cm" + + infov1 "github.com/google/cadvisor/info/v1" + + mock "github.com/stretchr/testify/mock" + + types "k8s.io/apimachinery/pkg/types" + + v1 "k8s.io/api/core/v1" + + v1alpha1 "k8s.io/kubelet/pkg/apis/stats/v1alpha1" + + v2 "github.com/google/cadvisor/info/v2" + volume "k8s.io/kubernetes/pkg/volume" ) -// MockProvider is a mock of Provider interface. +// MockProvider is an autogenerated mock type for the Provider type type MockProvider struct { - ctrl *gomock.Controller - recorder *MockProviderMockRecorder + mock.Mock } -// MockProviderMockRecorder is the mock recorder for MockProvider. -type MockProviderMockRecorder struct { - mock *MockProvider +type MockProvider_Expecter struct { + mock *mock.Mock } -// NewMockProvider creates a new mock instance. -func NewMockProvider(ctrl *gomock.Controller) *MockProvider { - mock := &MockProvider{ctrl: ctrl} - mock.recorder = &MockProviderMockRecorder{mock} +func (_m *MockProvider) EXPECT() *MockProvider_Expecter { + return &MockProvider_Expecter{mock: &_m.Mock} +} + +// GetCgroupCPUAndMemoryStats provides a mock function with given fields: cgroupName, updateStats +func (_m *MockProvider) GetCgroupCPUAndMemoryStats(cgroupName string, updateStats bool) (*v1alpha1.ContainerStats, error) { + ret := _m.Called(cgroupName, updateStats) + + if len(ret) == 0 { + panic("no return value specified for GetCgroupCPUAndMemoryStats") + } + + var r0 *v1alpha1.ContainerStats + var r1 error + if rf, ok := ret.Get(0).(func(string, bool) (*v1alpha1.ContainerStats, error)); ok { + return rf(cgroupName, updateStats) + } + if rf, ok := ret.Get(0).(func(string, bool) *v1alpha1.ContainerStats); ok { + r0 = rf(cgroupName, updateStats) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1alpha1.ContainerStats) + } + } + + if rf, ok := ret.Get(1).(func(string, bool) error); ok { + r1 = rf(cgroupName, updateStats) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockProvider_GetCgroupCPUAndMemoryStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCgroupCPUAndMemoryStats' +type MockProvider_GetCgroupCPUAndMemoryStats_Call struct { + *mock.Call +} + +// GetCgroupCPUAndMemoryStats is a helper method to define mock.On call +// - cgroupName string +// - updateStats bool +func (_e *MockProvider_Expecter) GetCgroupCPUAndMemoryStats(cgroupName interface{}, updateStats interface{}) *MockProvider_GetCgroupCPUAndMemoryStats_Call { + return &MockProvider_GetCgroupCPUAndMemoryStats_Call{Call: _e.mock.On("GetCgroupCPUAndMemoryStats", cgroupName, updateStats)} +} + +func (_c *MockProvider_GetCgroupCPUAndMemoryStats_Call) Run(run func(cgroupName string, updateStats bool)) *MockProvider_GetCgroupCPUAndMemoryStats_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *MockProvider_GetCgroupCPUAndMemoryStats_Call) Return(_a0 *v1alpha1.ContainerStats, _a1 error) *MockProvider_GetCgroupCPUAndMemoryStats_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_GetCgroupCPUAndMemoryStats_Call) RunAndReturn(run func(string, bool) (*v1alpha1.ContainerStats, error)) *MockProvider_GetCgroupCPUAndMemoryStats_Call { + _c.Call.Return(run) + return _c +} + +// GetCgroupStats provides a mock function with given fields: cgroupName, updateStats +func (_m *MockProvider) GetCgroupStats(cgroupName string, updateStats bool) (*v1alpha1.ContainerStats, *v1alpha1.NetworkStats, error) { + ret := _m.Called(cgroupName, updateStats) + + if len(ret) == 0 { + panic("no return value specified for GetCgroupStats") + } + + var r0 *v1alpha1.ContainerStats + var r1 *v1alpha1.NetworkStats + var r2 error + if rf, ok := ret.Get(0).(func(string, bool) (*v1alpha1.ContainerStats, *v1alpha1.NetworkStats, error)); ok { + return rf(cgroupName, updateStats) + } + if rf, ok := ret.Get(0).(func(string, bool) *v1alpha1.ContainerStats); ok { + r0 = rf(cgroupName, updateStats) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1alpha1.ContainerStats) + } + } + + if rf, ok := ret.Get(1).(func(string, bool) *v1alpha1.NetworkStats); ok { + r1 = rf(cgroupName, updateStats) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*v1alpha1.NetworkStats) + } + } + + if rf, ok := ret.Get(2).(func(string, bool) error); ok { + r2 = rf(cgroupName, updateStats) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockProvider_GetCgroupStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCgroupStats' +type MockProvider_GetCgroupStats_Call struct { + *mock.Call +} + +// GetCgroupStats is a helper method to define mock.On call +// - cgroupName string +// - updateStats bool +func (_e *MockProvider_Expecter) GetCgroupStats(cgroupName interface{}, updateStats interface{}) *MockProvider_GetCgroupStats_Call { + return &MockProvider_GetCgroupStats_Call{Call: _e.mock.On("GetCgroupStats", cgroupName, updateStats)} +} + +func (_c *MockProvider_GetCgroupStats_Call) Run(run func(cgroupName string, updateStats bool)) *MockProvider_GetCgroupStats_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *MockProvider_GetCgroupStats_Call) Return(_a0 *v1alpha1.ContainerStats, _a1 *v1alpha1.NetworkStats, _a2 error) *MockProvider_GetCgroupStats_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockProvider_GetCgroupStats_Call) RunAndReturn(run func(string, bool) (*v1alpha1.ContainerStats, *v1alpha1.NetworkStats, error)) *MockProvider_GetCgroupStats_Call { + _c.Call.Return(run) + return _c +} + +// GetNode provides a mock function with given fields: +func (_m *MockProvider) GetNode() (*v1.Node, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetNode") + } + + var r0 *v1.Node + var r1 error + if rf, ok := ret.Get(0).(func() (*v1.Node, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *v1.Node); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.Node) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockProvider_GetNode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNode' +type MockProvider_GetNode_Call struct { + *mock.Call +} + +// GetNode is a helper method to define mock.On call +func (_e *MockProvider_Expecter) GetNode() *MockProvider_GetNode_Call { + return &MockProvider_GetNode_Call{Call: _e.mock.On("GetNode")} +} + +func (_c *MockProvider_GetNode_Call) Run(run func()) *MockProvider_GetNode_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockProvider_GetNode_Call) Return(_a0 *v1.Node, _a1 error) *MockProvider_GetNode_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_GetNode_Call) RunAndReturn(run func() (*v1.Node, error)) *MockProvider_GetNode_Call { + _c.Call.Return(run) + return _c +} + +// GetNodeConfig provides a mock function with given fields: +func (_m *MockProvider) GetNodeConfig() cm.NodeConfig { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetNodeConfig") + } + + var r0 cm.NodeConfig + if rf, ok := ret.Get(0).(func() cm.NodeConfig); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(cm.NodeConfig) + } + + return r0 +} + +// MockProvider_GetNodeConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNodeConfig' +type MockProvider_GetNodeConfig_Call struct { + *mock.Call +} + +// GetNodeConfig is a helper method to define mock.On call +func (_e *MockProvider_Expecter) GetNodeConfig() *MockProvider_GetNodeConfig_Call { + return &MockProvider_GetNodeConfig_Call{Call: _e.mock.On("GetNodeConfig")} +} + +func (_c *MockProvider_GetNodeConfig_Call) Run(run func()) *MockProvider_GetNodeConfig_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockProvider_GetNodeConfig_Call) Return(_a0 cm.NodeConfig) *MockProvider_GetNodeConfig_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockProvider_GetNodeConfig_Call) RunAndReturn(run func() cm.NodeConfig) *MockProvider_GetNodeConfig_Call { + _c.Call.Return(run) + return _c +} + +// GetPodByCgroupfs provides a mock function with given fields: cgroupfs +func (_m *MockProvider) GetPodByCgroupfs(cgroupfs string) (*v1.Pod, bool) { + ret := _m.Called(cgroupfs) + + if len(ret) == 0 { + panic("no return value specified for GetPodByCgroupfs") + } + + var r0 *v1.Pod + var r1 bool + if rf, ok := ret.Get(0).(func(string) (*v1.Pod, bool)); ok { + return rf(cgroupfs) + } + if rf, ok := ret.Get(0).(func(string) *v1.Pod); ok { + r0 = rf(cgroupfs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.Pod) + } + } + + if rf, ok := ret.Get(1).(func(string) bool); ok { + r1 = rf(cgroupfs) + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// MockProvider_GetPodByCgroupfs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodByCgroupfs' +type MockProvider_GetPodByCgroupfs_Call struct { + *mock.Call +} + +// GetPodByCgroupfs is a helper method to define mock.On call +// - cgroupfs string +func (_e *MockProvider_Expecter) GetPodByCgroupfs(cgroupfs interface{}) *MockProvider_GetPodByCgroupfs_Call { + return &MockProvider_GetPodByCgroupfs_Call{Call: _e.mock.On("GetPodByCgroupfs", cgroupfs)} +} + +func (_c *MockProvider_GetPodByCgroupfs_Call) Run(run func(cgroupfs string)) *MockProvider_GetPodByCgroupfs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockProvider_GetPodByCgroupfs_Call) Return(_a0 *v1.Pod, _a1 bool) *MockProvider_GetPodByCgroupfs_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_GetPodByCgroupfs_Call) RunAndReturn(run func(string) (*v1.Pod, bool)) *MockProvider_GetPodByCgroupfs_Call { + _c.Call.Return(run) + return _c +} + +// GetPodByName provides a mock function with given fields: namespace, name +func (_m *MockProvider) 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 +} + +// MockProvider_GetPodByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodByName' +type MockProvider_GetPodByName_Call struct { + *mock.Call +} + +// GetPodByName is a helper method to define mock.On call +// - namespace string +// - name string +func (_e *MockProvider_Expecter) GetPodByName(namespace interface{}, name interface{}) *MockProvider_GetPodByName_Call { + return &MockProvider_GetPodByName_Call{Call: _e.mock.On("GetPodByName", namespace, name)} +} + +func (_c *MockProvider_GetPodByName_Call) Run(run func(namespace string, name string)) *MockProvider_GetPodByName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string)) + }) + return _c +} + +func (_c *MockProvider_GetPodByName_Call) Return(_a0 *v1.Pod, _a1 bool) *MockProvider_GetPodByName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_GetPodByName_Call) RunAndReturn(run func(string, string) (*v1.Pod, bool)) *MockProvider_GetPodByName_Call { + _c.Call.Return(run) + return _c +} + +// GetPodCgroupRoot provides a mock function with given fields: +func (_m *MockProvider) GetPodCgroupRoot() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetPodCgroupRoot") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// MockProvider_GetPodCgroupRoot_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodCgroupRoot' +type MockProvider_GetPodCgroupRoot_Call struct { + *mock.Call +} + +// GetPodCgroupRoot is a helper method to define mock.On call +func (_e *MockProvider_Expecter) GetPodCgroupRoot() *MockProvider_GetPodCgroupRoot_Call { + return &MockProvider_GetPodCgroupRoot_Call{Call: _e.mock.On("GetPodCgroupRoot")} +} + +func (_c *MockProvider_GetPodCgroupRoot_Call) Run(run func()) *MockProvider_GetPodCgroupRoot_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockProvider_GetPodCgroupRoot_Call) Return(_a0 string) *MockProvider_GetPodCgroupRoot_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockProvider_GetPodCgroupRoot_Call) RunAndReturn(run func() string) *MockProvider_GetPodCgroupRoot_Call { + _c.Call.Return(run) + return _c +} + +// GetPods provides a mock function with given fields: +func (_m *MockProvider) 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 +} + +// MockProvider_GetPods_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPods' +type MockProvider_GetPods_Call struct { + *mock.Call +} + +// GetPods is a helper method to define mock.On call +func (_e *MockProvider_Expecter) GetPods() *MockProvider_GetPods_Call { + return &MockProvider_GetPods_Call{Call: _e.mock.On("GetPods")} +} + +func (_c *MockProvider_GetPods_Call) Run(run func()) *MockProvider_GetPods_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockProvider_GetPods_Call) Return(_a0 []*v1.Pod) *MockProvider_GetPods_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockProvider_GetPods_Call) RunAndReturn(run func() []*v1.Pod) *MockProvider_GetPods_Call { + _c.Call.Return(run) + return _c +} + +// GetRequestedContainersInfo provides a mock function with given fields: containerName, options +func (_m *MockProvider) GetRequestedContainersInfo(containerName string, options v2.RequestOptions) (map[string]*infov1.ContainerInfo, error) { + ret := _m.Called(containerName, options) + + if len(ret) == 0 { + panic("no return value specified for GetRequestedContainersInfo") + } + + var r0 map[string]*infov1.ContainerInfo + var r1 error + if rf, ok := ret.Get(0).(func(string, v2.RequestOptions) (map[string]*infov1.ContainerInfo, error)); ok { + return rf(containerName, options) + } + if rf, ok := ret.Get(0).(func(string, v2.RequestOptions) map[string]*infov1.ContainerInfo); ok { + r0 = rf(containerName, options) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[string]*infov1.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 +} + +// MockProvider_GetRequestedContainersInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRequestedContainersInfo' +type MockProvider_GetRequestedContainersInfo_Call struct { + *mock.Call +} + +// GetRequestedContainersInfo is a helper method to define mock.On call +// - containerName string +// - options v2.RequestOptions +func (_e *MockProvider_Expecter) GetRequestedContainersInfo(containerName interface{}, options interface{}) *MockProvider_GetRequestedContainersInfo_Call { + return &MockProvider_GetRequestedContainersInfo_Call{Call: _e.mock.On("GetRequestedContainersInfo", containerName, options)} +} + +func (_c *MockProvider_GetRequestedContainersInfo_Call) Run(run func(containerName string, options v2.RequestOptions)) *MockProvider_GetRequestedContainersInfo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(v2.RequestOptions)) + }) + return _c +} + +func (_c *MockProvider_GetRequestedContainersInfo_Call) Return(_a0 map[string]*infov1.ContainerInfo, _a1 error) *MockProvider_GetRequestedContainersInfo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_GetRequestedContainersInfo_Call) RunAndReturn(run func(string, v2.RequestOptions) (map[string]*infov1.ContainerInfo, error)) *MockProvider_GetRequestedContainersInfo_Call { + _c.Call.Return(run) + return _c +} + +// ImageFsStats provides a mock function with given fields: ctx +func (_m *MockProvider) ImageFsStats(ctx context.Context) (*v1alpha1.FsStats, *v1alpha1.FsStats, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ImageFsStats") + } + + var r0 *v1alpha1.FsStats + var r1 *v1alpha1.FsStats + var r2 error + if rf, ok := ret.Get(0).(func(context.Context) (*v1alpha1.FsStats, *v1alpha1.FsStats, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *v1alpha1.FsStats); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1alpha1.FsStats) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) *v1alpha1.FsStats); ok { + r1 = rf(ctx) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*v1alpha1.FsStats) + } + } + + if rf, ok := ret.Get(2).(func(context.Context) error); ok { + r2 = rf(ctx) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockProvider_ImageFsStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ImageFsStats' +type MockProvider_ImageFsStats_Call struct { + *mock.Call +} + +// ImageFsStats is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockProvider_Expecter) ImageFsStats(ctx interface{}) *MockProvider_ImageFsStats_Call { + return &MockProvider_ImageFsStats_Call{Call: _e.mock.On("ImageFsStats", ctx)} +} + +func (_c *MockProvider_ImageFsStats_Call) Run(run func(ctx context.Context)) *MockProvider_ImageFsStats_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockProvider_ImageFsStats_Call) Return(imageFs *v1alpha1.FsStats, containerFs *v1alpha1.FsStats, callErr error) *MockProvider_ImageFsStats_Call { + _c.Call.Return(imageFs, containerFs, callErr) + return _c +} + +func (_c *MockProvider_ImageFsStats_Call) RunAndReturn(run func(context.Context) (*v1alpha1.FsStats, *v1alpha1.FsStats, error)) *MockProvider_ImageFsStats_Call { + _c.Call.Return(run) + return _c +} + +// ListBlockVolumesForPod provides a mock function with given fields: podUID +func (_m *MockProvider) ListBlockVolumesForPod(podUID types.UID) (map[string]volume.BlockVolume, bool) { + ret := _m.Called(podUID) + + if len(ret) == 0 { + panic("no return value specified for ListBlockVolumesForPod") + } + + var r0 map[string]volume.BlockVolume + var r1 bool + if rf, ok := ret.Get(0).(func(types.UID) (map[string]volume.BlockVolume, bool)); ok { + return rf(podUID) + } + if rf, ok := ret.Get(0).(func(types.UID) map[string]volume.BlockVolume); ok { + r0 = rf(podUID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[string]volume.BlockVolume) + } + } + + if rf, ok := ret.Get(1).(func(types.UID) bool); ok { + r1 = rf(podUID) + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// MockProvider_ListBlockVolumesForPod_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListBlockVolumesForPod' +type MockProvider_ListBlockVolumesForPod_Call struct { + *mock.Call +} + +// ListBlockVolumesForPod is a helper method to define mock.On call +// - podUID types.UID +func (_e *MockProvider_Expecter) ListBlockVolumesForPod(podUID interface{}) *MockProvider_ListBlockVolumesForPod_Call { + return &MockProvider_ListBlockVolumesForPod_Call{Call: _e.mock.On("ListBlockVolumesForPod", podUID)} +} + +func (_c *MockProvider_ListBlockVolumesForPod_Call) Run(run func(podUID types.UID)) *MockProvider_ListBlockVolumesForPod_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(types.UID)) + }) + return _c +} + +func (_c *MockProvider_ListBlockVolumesForPod_Call) Return(_a0 map[string]volume.BlockVolume, _a1 bool) *MockProvider_ListBlockVolumesForPod_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_ListBlockVolumesForPod_Call) RunAndReturn(run func(types.UID) (map[string]volume.BlockVolume, bool)) *MockProvider_ListBlockVolumesForPod_Call { + _c.Call.Return(run) + return _c +} + +// ListPodCPUAndMemoryStats provides a mock function with given fields: ctx +func (_m *MockProvider) ListPodCPUAndMemoryStats(ctx context.Context) ([]v1alpha1.PodStats, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ListPodCPUAndMemoryStats") + } + + var r0 []v1alpha1.PodStats + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]v1alpha1.PodStats, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []v1alpha1.PodStats); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]v1alpha1.PodStats) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockProvider_ListPodCPUAndMemoryStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListPodCPUAndMemoryStats' +type MockProvider_ListPodCPUAndMemoryStats_Call struct { + *mock.Call +} + +// ListPodCPUAndMemoryStats is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockProvider_Expecter) ListPodCPUAndMemoryStats(ctx interface{}) *MockProvider_ListPodCPUAndMemoryStats_Call { + return &MockProvider_ListPodCPUAndMemoryStats_Call{Call: _e.mock.On("ListPodCPUAndMemoryStats", ctx)} +} + +func (_c *MockProvider_ListPodCPUAndMemoryStats_Call) Run(run func(ctx context.Context)) *MockProvider_ListPodCPUAndMemoryStats_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockProvider_ListPodCPUAndMemoryStats_Call) Return(_a0 []v1alpha1.PodStats, _a1 error) *MockProvider_ListPodCPUAndMemoryStats_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_ListPodCPUAndMemoryStats_Call) RunAndReturn(run func(context.Context) ([]v1alpha1.PodStats, error)) *MockProvider_ListPodCPUAndMemoryStats_Call { + _c.Call.Return(run) + return _c +} + +// ListPodStats provides a mock function with given fields: ctx +func (_m *MockProvider) ListPodStats(ctx context.Context) ([]v1alpha1.PodStats, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ListPodStats") + } + + var r0 []v1alpha1.PodStats + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]v1alpha1.PodStats, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []v1alpha1.PodStats); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]v1alpha1.PodStats) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockProvider_ListPodStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListPodStats' +type MockProvider_ListPodStats_Call struct { + *mock.Call +} + +// ListPodStats is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockProvider_Expecter) ListPodStats(ctx interface{}) *MockProvider_ListPodStats_Call { + return &MockProvider_ListPodStats_Call{Call: _e.mock.On("ListPodStats", ctx)} +} + +func (_c *MockProvider_ListPodStats_Call) Run(run func(ctx context.Context)) *MockProvider_ListPodStats_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockProvider_ListPodStats_Call) Return(_a0 []v1alpha1.PodStats, _a1 error) *MockProvider_ListPodStats_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_ListPodStats_Call) RunAndReturn(run func(context.Context) ([]v1alpha1.PodStats, error)) *MockProvider_ListPodStats_Call { + _c.Call.Return(run) + return _c +} + +// ListPodStatsAndUpdateCPUNanoCoreUsage provides a mock function with given fields: ctx +func (_m *MockProvider) ListPodStatsAndUpdateCPUNanoCoreUsage(ctx context.Context) ([]v1alpha1.PodStats, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ListPodStatsAndUpdateCPUNanoCoreUsage") + } + + var r0 []v1alpha1.PodStats + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]v1alpha1.PodStats, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []v1alpha1.PodStats); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]v1alpha1.PodStats) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockProvider_ListPodStatsAndUpdateCPUNanoCoreUsage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListPodStatsAndUpdateCPUNanoCoreUsage' +type MockProvider_ListPodStatsAndUpdateCPUNanoCoreUsage_Call struct { + *mock.Call +} + +// ListPodStatsAndUpdateCPUNanoCoreUsage is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockProvider_Expecter) ListPodStatsAndUpdateCPUNanoCoreUsage(ctx interface{}) *MockProvider_ListPodStatsAndUpdateCPUNanoCoreUsage_Call { + return &MockProvider_ListPodStatsAndUpdateCPUNanoCoreUsage_Call{Call: _e.mock.On("ListPodStatsAndUpdateCPUNanoCoreUsage", ctx)} +} + +func (_c *MockProvider_ListPodStatsAndUpdateCPUNanoCoreUsage_Call) Run(run func(ctx context.Context)) *MockProvider_ListPodStatsAndUpdateCPUNanoCoreUsage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockProvider_ListPodStatsAndUpdateCPUNanoCoreUsage_Call) Return(_a0 []v1alpha1.PodStats, _a1 error) *MockProvider_ListPodStatsAndUpdateCPUNanoCoreUsage_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_ListPodStatsAndUpdateCPUNanoCoreUsage_Call) RunAndReturn(run func(context.Context) ([]v1alpha1.PodStats, error)) *MockProvider_ListPodStatsAndUpdateCPUNanoCoreUsage_Call { + _c.Call.Return(run) + return _c +} + +// ListVolumesForPod provides a mock function with given fields: podUID +func (_m *MockProvider) ListVolumesForPod(podUID types.UID) (map[string]volume.Volume, bool) { + ret := _m.Called(podUID) + + if len(ret) == 0 { + panic("no return value specified for ListVolumesForPod") + } + + var r0 map[string]volume.Volume + var r1 bool + if rf, ok := ret.Get(0).(func(types.UID) (map[string]volume.Volume, bool)); ok { + return rf(podUID) + } + if rf, ok := ret.Get(0).(func(types.UID) map[string]volume.Volume); ok { + r0 = rf(podUID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[string]volume.Volume) + } + } + + if rf, ok := ret.Get(1).(func(types.UID) bool); ok { + r1 = rf(podUID) + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// MockProvider_ListVolumesForPod_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListVolumesForPod' +type MockProvider_ListVolumesForPod_Call struct { + *mock.Call +} + +// ListVolumesForPod is a helper method to define mock.On call +// - podUID types.UID +func (_e *MockProvider_Expecter) ListVolumesForPod(podUID interface{}) *MockProvider_ListVolumesForPod_Call { + return &MockProvider_ListVolumesForPod_Call{Call: _e.mock.On("ListVolumesForPod", podUID)} +} + +func (_c *MockProvider_ListVolumesForPod_Call) Run(run func(podUID types.UID)) *MockProvider_ListVolumesForPod_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(types.UID)) + }) + return _c +} + +func (_c *MockProvider_ListVolumesForPod_Call) Return(_a0 map[string]volume.Volume, _a1 bool) *MockProvider_ListVolumesForPod_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_ListVolumesForPod_Call) RunAndReturn(run func(types.UID) (map[string]volume.Volume, bool)) *MockProvider_ListVolumesForPod_Call { + _c.Call.Return(run) + return _c +} + +// RlimitStats provides a mock function with given fields: +func (_m *MockProvider) RlimitStats() (*v1alpha1.RlimitStats, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RlimitStats") + } + + var r0 *v1alpha1.RlimitStats + var r1 error + if rf, ok := ret.Get(0).(func() (*v1alpha1.RlimitStats, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *v1alpha1.RlimitStats); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1alpha1.RlimitStats) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockProvider_RlimitStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RlimitStats' +type MockProvider_RlimitStats_Call struct { + *mock.Call +} + +// RlimitStats is a helper method to define mock.On call +func (_e *MockProvider_Expecter) RlimitStats() *MockProvider_RlimitStats_Call { + return &MockProvider_RlimitStats_Call{Call: _e.mock.On("RlimitStats")} +} + +func (_c *MockProvider_RlimitStats_Call) Run(run func()) *MockProvider_RlimitStats_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockProvider_RlimitStats_Call) Return(_a0 *v1alpha1.RlimitStats, _a1 error) *MockProvider_RlimitStats_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_RlimitStats_Call) RunAndReturn(run func() (*v1alpha1.RlimitStats, error)) *MockProvider_RlimitStats_Call { + _c.Call.Return(run) + return _c +} + +// RootFsStats provides a mock function with given fields: +func (_m *MockProvider) RootFsStats() (*v1alpha1.FsStats, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RootFsStats") + } + + var r0 *v1alpha1.FsStats + var r1 error + if rf, ok := ret.Get(0).(func() (*v1alpha1.FsStats, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *v1alpha1.FsStats); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1alpha1.FsStats) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockProvider_RootFsStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RootFsStats' +type MockProvider_RootFsStats_Call struct { + *mock.Call +} + +// RootFsStats is a helper method to define mock.On call +func (_e *MockProvider_Expecter) RootFsStats() *MockProvider_RootFsStats_Call { + return &MockProvider_RootFsStats_Call{Call: _e.mock.On("RootFsStats")} +} + +func (_c *MockProvider_RootFsStats_Call) Run(run func()) *MockProvider_RootFsStats_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockProvider_RootFsStats_Call) Return(_a0 *v1alpha1.FsStats, _a1 error) *MockProvider_RootFsStats_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockProvider_RootFsStats_Call) RunAndReturn(run func() (*v1alpha1.FsStats, error)) *MockProvider_RootFsStats_Call { + _c.Call.Return(run) + return _c +} + +// NewMockProvider creates a new instance of MockProvider. 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 NewMockProvider(t interface { + mock.TestingT + Cleanup(func()) +}) *MockProvider { + mock := &MockProvider{} + 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 *MockProvider) EXPECT() *MockProviderMockRecorder { - return m.recorder -} - -// GetCgroupCPUAndMemoryStats mocks base method. -func (m *MockProvider) GetCgroupCPUAndMemoryStats(cgroupName string, updateStats bool) (*v1alpha1.ContainerStats, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetCgroupCPUAndMemoryStats", cgroupName, updateStats) - ret0, _ := ret[0].(*v1alpha1.ContainerStats) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetCgroupCPUAndMemoryStats indicates an expected call of GetCgroupCPUAndMemoryStats. -func (mr *MockProviderMockRecorder) GetCgroupCPUAndMemoryStats(cgroupName, updateStats any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCgroupCPUAndMemoryStats", reflect.TypeOf((*MockProvider)(nil).GetCgroupCPUAndMemoryStats), cgroupName, updateStats) -} - -// GetCgroupStats mocks base method. -func (m *MockProvider) GetCgroupStats(cgroupName string, updateStats bool) (*v1alpha1.ContainerStats, *v1alpha1.NetworkStats, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetCgroupStats", cgroupName, updateStats) - ret0, _ := ret[0].(*v1alpha1.ContainerStats) - ret1, _ := ret[1].(*v1alpha1.NetworkStats) - ret2, _ := ret[2].(error) - return ret0, ret1, ret2 -} - -// GetCgroupStats indicates an expected call of GetCgroupStats. -func (mr *MockProviderMockRecorder) GetCgroupStats(cgroupName, updateStats any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCgroupStats", reflect.TypeOf((*MockProvider)(nil).GetCgroupStats), cgroupName, updateStats) -} - -// GetNode mocks base method. -func (m *MockProvider) GetNode() (*v10.Node, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetNode") - ret0, _ := ret[0].(*v10.Node) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetNode indicates an expected call of GetNode. -func (mr *MockProviderMockRecorder) GetNode() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNode", reflect.TypeOf((*MockProvider)(nil).GetNode)) -} - -// GetNodeConfig mocks base method. -func (m *MockProvider) GetNodeConfig() cm.NodeConfig { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetNodeConfig") - ret0, _ := ret[0].(cm.NodeConfig) - return ret0 -} - -// GetNodeConfig indicates an expected call of GetNodeConfig. -func (mr *MockProviderMockRecorder) GetNodeConfig() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNodeConfig", reflect.TypeOf((*MockProvider)(nil).GetNodeConfig)) -} - -// GetPodByCgroupfs mocks base method. -func (m *MockProvider) GetPodByCgroupfs(cgroupfs string) (*v10.Pod, bool) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetPodByCgroupfs", cgroupfs) - ret0, _ := ret[0].(*v10.Pod) - ret1, _ := ret[1].(bool) - return ret0, ret1 -} - -// GetPodByCgroupfs indicates an expected call of GetPodByCgroupfs. -func (mr *MockProviderMockRecorder) GetPodByCgroupfs(cgroupfs any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodByCgroupfs", reflect.TypeOf((*MockProvider)(nil).GetPodByCgroupfs), cgroupfs) -} - -// GetPodByName mocks base method. -func (m *MockProvider) GetPodByName(namespace, name string) (*v10.Pod, bool) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetPodByName", namespace, name) - ret0, _ := ret[0].(*v10.Pod) - ret1, _ := ret[1].(bool) - return ret0, ret1 -} - -// GetPodByName indicates an expected call of GetPodByName. -func (mr *MockProviderMockRecorder) GetPodByName(namespace, name any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodByName", reflect.TypeOf((*MockProvider)(nil).GetPodByName), namespace, name) -} - -// GetPodCgroupRoot mocks base method. -func (m *MockProvider) GetPodCgroupRoot() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetPodCgroupRoot") - ret0, _ := ret[0].(string) - return ret0 -} - -// GetPodCgroupRoot indicates an expected call of GetPodCgroupRoot. -func (mr *MockProviderMockRecorder) GetPodCgroupRoot() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPodCgroupRoot", reflect.TypeOf((*MockProvider)(nil).GetPodCgroupRoot)) -} - -// GetPods mocks base method. -func (m *MockProvider) GetPods() []*v10.Pod { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetPods") - ret0, _ := ret[0].([]*v10.Pod) - return ret0 -} - -// GetPods indicates an expected call of GetPods. -func (mr *MockProviderMockRecorder) GetPods() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPods", reflect.TypeOf((*MockProvider)(nil).GetPods)) -} - -// GetRequestedContainersInfo mocks base method. -func (m *MockProvider) 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 *MockProviderMockRecorder) GetRequestedContainersInfo(containerName, options any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRequestedContainersInfo", reflect.TypeOf((*MockProvider)(nil).GetRequestedContainersInfo), containerName, options) -} - -// ImageFsStats mocks base method. -func (m *MockProvider) ImageFsStats(ctx context.Context) (*v1alpha1.FsStats, *v1alpha1.FsStats, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ImageFsStats", ctx) - ret0, _ := ret[0].(*v1alpha1.FsStats) - ret1, _ := ret[1].(*v1alpha1.FsStats) - ret2, _ := ret[2].(error) - return ret0, ret1, ret2 -} - -// ImageFsStats indicates an expected call of ImageFsStats. -func (mr *MockProviderMockRecorder) ImageFsStats(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageFsStats", reflect.TypeOf((*MockProvider)(nil).ImageFsStats), ctx) -} - -// ListBlockVolumesForPod mocks base method. -func (m *MockProvider) ListBlockVolumesForPod(podUID types.UID) (map[string]volume.BlockVolume, bool) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListBlockVolumesForPod", podUID) - ret0, _ := ret[0].(map[string]volume.BlockVolume) - ret1, _ := ret[1].(bool) - return ret0, ret1 -} - -// ListBlockVolumesForPod indicates an expected call of ListBlockVolumesForPod. -func (mr *MockProviderMockRecorder) ListBlockVolumesForPod(podUID any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListBlockVolumesForPod", reflect.TypeOf((*MockProvider)(nil).ListBlockVolumesForPod), podUID) -} - -// ListPodCPUAndMemoryStats mocks base method. -func (m *MockProvider) ListPodCPUAndMemoryStats(ctx context.Context) ([]v1alpha1.PodStats, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListPodCPUAndMemoryStats", ctx) - ret0, _ := ret[0].([]v1alpha1.PodStats) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ListPodCPUAndMemoryStats indicates an expected call of ListPodCPUAndMemoryStats. -func (mr *MockProviderMockRecorder) ListPodCPUAndMemoryStats(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListPodCPUAndMemoryStats", reflect.TypeOf((*MockProvider)(nil).ListPodCPUAndMemoryStats), ctx) -} - -// ListPodStats mocks base method. -func (m *MockProvider) ListPodStats(ctx context.Context) ([]v1alpha1.PodStats, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListPodStats", ctx) - ret0, _ := ret[0].([]v1alpha1.PodStats) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ListPodStats indicates an expected call of ListPodStats. -func (mr *MockProviderMockRecorder) ListPodStats(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListPodStats", reflect.TypeOf((*MockProvider)(nil).ListPodStats), ctx) -} - -// ListPodStatsAndUpdateCPUNanoCoreUsage mocks base method. -func (m *MockProvider) ListPodStatsAndUpdateCPUNanoCoreUsage(ctx context.Context) ([]v1alpha1.PodStats, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListPodStatsAndUpdateCPUNanoCoreUsage", ctx) - ret0, _ := ret[0].([]v1alpha1.PodStats) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ListPodStatsAndUpdateCPUNanoCoreUsage indicates an expected call of ListPodStatsAndUpdateCPUNanoCoreUsage. -func (mr *MockProviderMockRecorder) ListPodStatsAndUpdateCPUNanoCoreUsage(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListPodStatsAndUpdateCPUNanoCoreUsage", reflect.TypeOf((*MockProvider)(nil).ListPodStatsAndUpdateCPUNanoCoreUsage), ctx) -} - -// ListVolumesForPod mocks base method. -func (m *MockProvider) ListVolumesForPod(podUID types.UID) (map[string]volume.Volume, bool) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListVolumesForPod", podUID) - ret0, _ := ret[0].(map[string]volume.Volume) - ret1, _ := ret[1].(bool) - return ret0, ret1 -} - -// ListVolumesForPod indicates an expected call of ListVolumesForPod. -func (mr *MockProviderMockRecorder) ListVolumesForPod(podUID any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListVolumesForPod", reflect.TypeOf((*MockProvider)(nil).ListVolumesForPod), podUID) -} - -// RlimitStats mocks base method. -func (m *MockProvider) RlimitStats() (*v1alpha1.RlimitStats, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RlimitStats") - ret0, _ := ret[0].(*v1alpha1.RlimitStats) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// RlimitStats indicates an expected call of RlimitStats. -func (mr *MockProviderMockRecorder) RlimitStats() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RlimitStats", reflect.TypeOf((*MockProvider)(nil).RlimitStats)) -} - -// RootFsStats mocks base method. -func (m *MockProvider) RootFsStats() (*v1alpha1.FsStats, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RootFsStats") - ret0, _ := ret[0].(*v1alpha1.FsStats) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// RootFsStats indicates an expected call of RootFsStats. -func (mr *MockProviderMockRecorder) RootFsStats() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RootFsStats", reflect.TypeOf((*MockProvider)(nil).RootFsStats)) -} diff --git a/pkg/kubelet/server/stats/testing/mock_summary_provider.go b/pkg/kubelet/server/stats/testing/mock_summary_provider.go index b3905461a46..7e9f12bc8b2 100644 --- a/pkg/kubelet/server/stats/testing/mock_summary_provider.go +++ b/pkg/kubelet/server/stats/testing/mock_summary_provider.go @@ -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) -} diff --git a/pkg/kubelet/server/stats/volume_stat_calculator_test.go b/pkg/kubelet/server/stats/volume_stat_calculator_test.go index 2daf08285cc..1144e1c7a4b 100644 --- a/pkg/kubelet/server/stats/volume_stat_calculator_test.go +++ b/pkg/kubelet/server/stats/volume_stat_calculator_test.go @@ -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{}} diff --git a/pkg/kubelet/stats/cadvisor_stats_provider_test.go b/pkg/kubelet/stats/cadvisor_stats_provider_test.go index 85b4aa55164..a535ba98149 100644 --- a/pkg/kubelet/stats/cadvisor_stats_provider_test.go +++ b/pkg/kubelet/stats/cadvisor_stats_provider_test.go @@ -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} diff --git a/pkg/kubelet/stats/cri_stats_provider_test.go b/pkg/kubelet/stats/cri_stats_provider_test.go index ea5b616dfca..5a12b3e8a30 100644 --- a/pkg/kubelet/stats/cri_stats_provider_test.go +++ b/pkg/kubelet/stats/cri_stats_provider_test.go @@ -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) diff --git a/pkg/kubelet/stats/provider_test.go b/pkg/kubelet/stats/provider_test.go index 17caba130b4..3a80d633ca0 100644 --- a/pkg/kubelet/stats/provider_test.go +++ b/pkg/kubelet/stats/provider_test.go @@ -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) ) diff --git a/pkg/kubelet/status/.mockery.yaml b/pkg/kubelet/status/.mockery.yaml new file mode 100644 index 00000000000..e57d22e2ee2 --- /dev/null +++ b/pkg/kubelet/status/.mockery.yaml @@ -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: diff --git a/pkg/kubelet/status/status_manager.go b/pkg/kubelet/status/status_manager.go index f1d85ad9ddf..cc60a56718a 100644 --- a/pkg/kubelet/status/status_manager.go +++ b/pkg/kubelet/status/status_manager.go @@ -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 ( diff --git a/pkg/kubelet/status/testing/mock_pod_status_provider.go b/pkg/kubelet/status/testing/mock_pod_status_provider.go index dee531217e2..31261d4d994 100644 --- a/pkg/kubelet/status/testing/mock_pod_status_provider.go +++ b/pkg/kubelet/status/testing/mock_pod_status_provider.go @@ -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) -} diff --git a/test/e2e/storage/drivers/csi-test/driver/.mockery.yaml b/test/e2e/storage/drivers/csi-test/driver/.mockery.yaml new file mode 100644 index 00000000000..2ccaee23392 --- /dev/null +++ b/test/e2e/storage/drivers/csi-test/driver/.mockery.yaml @@ -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: diff --git a/test/e2e/storage/drivers/csi-test/driver/driver.go b/test/e2e/storage/drivers/csi-test/driver/driver.go index 92869db4c87..4ac8212753c 100644 --- a/test/e2e/storage/drivers/csi-test/driver/driver.go +++ b/test/e2e/storage/drivers/csi-test/driver/driver.go @@ -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 diff --git a/test/e2e/storage/drivers/csi-test/driver/driver.mock.go b/test/e2e/storage/drivers/csi-test/driver/driver.mock.go deleted file mode 100644 index 8346c4e54e7..00000000000 --- a/test/e2e/storage/drivers/csi-test/driver/driver.mock.go +++ /dev/null @@ -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) -} diff --git a/test/e2e/storage/drivers/csi-test/driver/mock_controller_server.go b/test/e2e/storage/drivers/csi-test/driver/mock_controller_server.go new file mode 100644 index 00000000000..8b2a9f71280 --- /dev/null +++ b/test/e2e/storage/drivers/csi-test/driver/mock_controller_server.go @@ -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 +} diff --git a/test/e2e/storage/drivers/csi-test/driver/mock_identity_server.go b/test/e2e/storage/drivers/csi-test/driver/mock_identity_server.go new file mode 100644 index 00000000000..9e7038e45f1 --- /dev/null +++ b/test/e2e/storage/drivers/csi-test/driver/mock_identity_server.go @@ -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 +} diff --git a/test/e2e/storage/drivers/csi-test/driver/mock_node_server.go b/test/e2e/storage/drivers/csi-test/driver/mock_node_server.go new file mode 100644 index 00000000000..e67b14762b8 --- /dev/null +++ b/test/e2e/storage/drivers/csi-test/driver/mock_node_server.go @@ -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 +} diff --git a/test/integration/apiserver/oidc/oidc_test.go b/test/integration/apiserver/oidc/oidc_test.go index 493cf154e2a..6e5f959e7c3 100644 --- a/test/integration/apiserver/oidc/oidc_test.go +++ b/test/integration/apiserver/oidc/oidc_test.go @@ -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) { diff --git a/test/utils/oidc/handlers.mock.go b/test/utils/oidc/handlers.mock.go deleted file mode 100644 index d7c210f0455..00000000000 --- a/test/utils/oidc/handlers.mock.go +++ /dev/null @@ -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)) -} diff --git a/test/utils/oidc/handlers/.mockery.yaml b/test/utils/oidc/handlers/.mockery.yaml new file mode 100644 index 00000000000..8895054d2b7 --- /dev/null +++ b/test/utils/oidc/handlers/.mockery.yaml @@ -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: diff --git a/test/utils/oidc/handlers.go b/test/utils/oidc/handlers/handlers.go similarity index 88% rename from test/utils/oidc/handlers.go rename to test/utils/oidc/handlers/handlers.go index a25eadccf5d..1bd8e0f7d56 100644 --- a/test/utils/oidc/handlers.go +++ b/test/utils/oidc/handlers/handlers.go @@ -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" diff --git a/test/utils/oidc/handlers/mock_jwks_handler.go b/test/utils/oidc/handlers/mock_jwks_handler.go new file mode 100644 index 00000000000..dc7932d8ead --- /dev/null +++ b/test/utils/oidc/handlers/mock_jwks_handler.go @@ -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 +} diff --git a/test/utils/oidc/handlers/mock_token_handler.go b/test/utils/oidc/handlers/mock_token_handler.go new file mode 100644 index 00000000000..46bd7bac2fe --- /dev/null +++ b/test/utils/oidc/handlers/mock_token_handler.go @@ -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 +} diff --git a/test/utils/oidc/testserver.go b/test/utils/oidc/testserver.go index ef515232b4e..79ef873018a 100644 --- a/test/utils/oidc/testserver.go +++ b/test/utils/oidc/testserver.go @@ -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, diff --git a/vendor/github.com/stretchr/objx/.codeclimate.yml b/vendor/github.com/stretchr/objx/.codeclimate.yml new file mode 100644 index 00000000000..559fa399c13 --- /dev/null +++ b/vendor/github.com/stretchr/objx/.codeclimate.yml @@ -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" diff --git a/vendor/github.com/stretchr/objx/.gitignore b/vendor/github.com/stretchr/objx/.gitignore new file mode 100644 index 00000000000..ea58090bd21 --- /dev/null +++ b/vendor/github.com/stretchr/objx/.gitignore @@ -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 diff --git a/vendor/github.com/stretchr/objx/LICENSE b/vendor/github.com/stretchr/objx/LICENSE new file mode 100644 index 00000000000..44d4d9d5a7c --- /dev/null +++ b/vendor/github.com/stretchr/objx/LICENSE @@ -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. diff --git a/vendor/github.com/stretchr/objx/README.md b/vendor/github.com/stretchr/objx/README.md new file mode 100644 index 00000000000..246660b21a9 --- /dev/null +++ b/vendor/github.com/stretchr/objx/README.md @@ -0,0 +1,80 @@ +# Objx +[](https://travis-ci.org/stretchr/objx) +[](https://goreportcard.com/report/github.com/stretchr/objx) +[](https://codeclimate.com/github/stretchr/objx/maintainability) +[](https://codeclimate.com/github/stretchr/objx/test_coverage) +[](https://sourcegraph.com/github.com/stretchr/objx) +[](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! diff --git a/vendor/github.com/stretchr/objx/Taskfile.yml b/vendor/github.com/stretchr/objx/Taskfile.yml new file mode 100644 index 00000000000..7746f516da2 --- /dev/null +++ b/vendor/github.com/stretchr/objx/Taskfile.yml @@ -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 ./... diff --git a/vendor/github.com/stretchr/objx/accessors.go b/vendor/github.com/stretchr/objx/accessors.go new file mode 100644 index 00000000000..4c604558863 --- /dev/null +++ b/vendor/github.com/stretchr/objx/accessors.go @@ -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 +} diff --git a/vendor/github.com/stretchr/objx/conversions.go b/vendor/github.com/stretchr/objx/conversions.go new file mode 100644 index 00000000000..080aa46e472 --- /dev/null +++ b/vendor/github.com/stretchr/objx/conversions.go @@ -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 +} diff --git a/vendor/github.com/stretchr/objx/doc.go b/vendor/github.com/stretchr/objx/doc.go new file mode 100644 index 00000000000..6d6af1a83ab --- /dev/null +++ b/vendor/github.com/stretchr/objx/doc.go @@ -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 diff --git a/vendor/github.com/stretchr/objx/map.go b/vendor/github.com/stretchr/objx/map.go new file mode 100644 index 00000000000..a64712a08b5 --- /dev/null +++ b/vendor/github.com/stretchr/objx/map.go @@ -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 +} diff --git a/vendor/github.com/stretchr/objx/mutations.go b/vendor/github.com/stretchr/objx/mutations.go new file mode 100644 index 00000000000..c3400a3f709 --- /dev/null +++ b/vendor/github.com/stretchr/objx/mutations.go @@ -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 +} diff --git a/vendor/github.com/stretchr/objx/security.go b/vendor/github.com/stretchr/objx/security.go new file mode 100644 index 00000000000..692be8e2a9f --- /dev/null +++ b/vendor/github.com/stretchr/objx/security.go @@ -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[:]) +} diff --git a/vendor/github.com/stretchr/objx/tests.go b/vendor/github.com/stretchr/objx/tests.go new file mode 100644 index 00000000000..d9e0b479a4c --- /dev/null +++ b/vendor/github.com/stretchr/objx/tests.go @@ -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 +} diff --git a/vendor/github.com/stretchr/objx/type_specific.go b/vendor/github.com/stretchr/objx/type_specific.go new file mode 100644 index 00000000000..80f88d9fa29 --- /dev/null +++ b/vendor/github.com/stretchr/objx/type_specific.go @@ -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} +} diff --git a/vendor/github.com/stretchr/objx/type_specific_codegen.go b/vendor/github.com/stretchr/objx/type_specific_codegen.go new file mode 100644 index 00000000000..45850456e17 --- /dev/null +++ b/vendor/github.com/stretchr/objx/type_specific_codegen.go @@ -0,0 +1,2261 @@ +package objx + +/* + Inter (interface{} and []interface{}) +*/ + +// Inter gets the value as a interface{}, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Inter(optionalDefault ...interface{}) interface{} { + if s, ok := v.data.(interface{}); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustInter gets the value as a interface{}. +// +// Panics if the object is not a interface{}. +func (v *Value) MustInter() interface{} { + return v.data.(interface{}) +} + +// InterSlice gets the value as a []interface{}, returns the optionalDefault +// value or nil if the value is not a []interface{}. +func (v *Value) InterSlice(optionalDefault ...[]interface{}) []interface{} { + if s, ok := v.data.([]interface{}); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustInterSlice gets the value as a []interface{}. +// +// Panics if the object is not a []interface{}. +func (v *Value) MustInterSlice() []interface{} { + return v.data.([]interface{}) +} + +// IsInter gets whether the object contained is a interface{} or not. +func (v *Value) IsInter() bool { + _, ok := v.data.(interface{}) + return ok +} + +// IsInterSlice gets whether the object contained is a []interface{} or not. +func (v *Value) IsInterSlice() bool { + _, ok := v.data.([]interface{}) + return ok +} + +// EachInter calls the specified callback for each object +// in the []interface{}. +// +// Panics if the object is the wrong type. +func (v *Value) EachInter(callback func(int, interface{}) bool) *Value { + for index, val := range v.MustInterSlice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereInter uses the specified decider function to select items +// from the []interface{}. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereInter(decider func(int, interface{}) bool) *Value { + var selected []interface{} + v.EachInter(func(index int, val interface{}) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupInter 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][]interface{}. +func (v *Value) GroupInter(grouper func(int, interface{}) string) *Value { + groups := make(map[string][]interface{}) + v.EachInter(func(index int, val interface{}) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]interface{}, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceInter uses the specified function to replace each interface{}s +// by iterating each item. The data in the returned result will be a +// []interface{} containing the replaced items. +func (v *Value) ReplaceInter(replacer func(int, interface{}) interface{}) *Value { + arr := v.MustInterSlice() + replaced := make([]interface{}, len(arr)) + v.EachInter(func(index int, val interface{}) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectInter uses the specified collector function to collect a value +// for each of the interface{}s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectInter(collector func(int, interface{}) interface{}) *Value { + arr := v.MustInterSlice() + collected := make([]interface{}, len(arr)) + v.EachInter(func(index int, val interface{}) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Bool (bool and []bool) +*/ + +// Bool gets the value as a bool, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Bool(optionalDefault ...bool) bool { + if s, ok := v.data.(bool); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return false +} + +// MustBool gets the value as a bool. +// +// Panics if the object is not a bool. +func (v *Value) MustBool() bool { + return v.data.(bool) +} + +// BoolSlice gets the value as a []bool, returns the optionalDefault +// value or nil if the value is not a []bool. +func (v *Value) BoolSlice(optionalDefault ...[]bool) []bool { + if s, ok := v.data.([]bool); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustBoolSlice gets the value as a []bool. +// +// Panics if the object is not a []bool. +func (v *Value) MustBoolSlice() []bool { + return v.data.([]bool) +} + +// IsBool gets whether the object contained is a bool or not. +func (v *Value) IsBool() bool { + _, ok := v.data.(bool) + return ok +} + +// IsBoolSlice gets whether the object contained is a []bool or not. +func (v *Value) IsBoolSlice() bool { + _, ok := v.data.([]bool) + return ok +} + +// EachBool calls the specified callback for each object +// in the []bool. +// +// Panics if the object is the wrong type. +func (v *Value) EachBool(callback func(int, bool) bool) *Value { + for index, val := range v.MustBoolSlice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereBool uses the specified decider function to select items +// from the []bool. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereBool(decider func(int, bool) bool) *Value { + var selected []bool + v.EachBool(func(index int, val bool) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupBool 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][]bool. +func (v *Value) GroupBool(grouper func(int, bool) string) *Value { + groups := make(map[string][]bool) + v.EachBool(func(index int, val bool) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]bool, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceBool uses the specified function to replace each bools +// by iterating each item. The data in the returned result will be a +// []bool containing the replaced items. +func (v *Value) ReplaceBool(replacer func(int, bool) bool) *Value { + arr := v.MustBoolSlice() + replaced := make([]bool, len(arr)) + v.EachBool(func(index int, val bool) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectBool uses the specified collector function to collect a value +// for each of the bools in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectBool(collector func(int, bool) interface{}) *Value { + arr := v.MustBoolSlice() + collected := make([]interface{}, len(arr)) + v.EachBool(func(index int, val bool) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Str (string and []string) +*/ + +// Str gets the value as a string, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Str(optionalDefault ...string) string { + if s, ok := v.data.(string); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return "" +} + +// MustStr gets the value as a string. +// +// Panics if the object is not a string. +func (v *Value) MustStr() string { + return v.data.(string) +} + +// StrSlice gets the value as a []string, returns the optionalDefault +// value or nil if the value is not a []string. +func (v *Value) StrSlice(optionalDefault ...[]string) []string { + if s, ok := v.data.([]string); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustStrSlice gets the value as a []string. +// +// Panics if the object is not a []string. +func (v *Value) MustStrSlice() []string { + return v.data.([]string) +} + +// IsStr gets whether the object contained is a string or not. +func (v *Value) IsStr() bool { + _, ok := v.data.(string) + return ok +} + +// IsStrSlice gets whether the object contained is a []string or not. +func (v *Value) IsStrSlice() bool { + _, ok := v.data.([]string) + return ok +} + +// EachStr calls the specified callback for each object +// in the []string. +// +// Panics if the object is the wrong type. +func (v *Value) EachStr(callback func(int, string) bool) *Value { + for index, val := range v.MustStrSlice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereStr uses the specified decider function to select items +// from the []string. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereStr(decider func(int, string) bool) *Value { + var selected []string + v.EachStr(func(index int, val string) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupStr 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][]string. +func (v *Value) GroupStr(grouper func(int, string) string) *Value { + groups := make(map[string][]string) + v.EachStr(func(index int, val string) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]string, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceStr uses the specified function to replace each strings +// by iterating each item. The data in the returned result will be a +// []string containing the replaced items. +func (v *Value) ReplaceStr(replacer func(int, string) string) *Value { + arr := v.MustStrSlice() + replaced := make([]string, len(arr)) + v.EachStr(func(index int, val string) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectStr uses the specified collector function to collect a value +// for each of the strings in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectStr(collector func(int, string) interface{}) *Value { + arr := v.MustStrSlice() + collected := make([]interface{}, len(arr)) + v.EachStr(func(index int, val string) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Int (int and []int) +*/ + +// Int gets the value as a int, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Int(optionalDefault ...int) int { + if s, ok := v.data.(int); ok { + return s + } + if s, ok := v.data.(float64); ok { + if float64(int(s)) == s { + return int(s) + } + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustInt gets the value as a int. +// +// Panics if the object is not a int. +func (v *Value) MustInt() int { + if s, ok := v.data.(float64); ok { + if float64(int(s)) == s { + return int(s) + } + } + return v.data.(int) +} + +// IntSlice gets the value as a []int, returns the optionalDefault +// value or nil if the value is not a []int. +func (v *Value) IntSlice(optionalDefault ...[]int) []int { + if s, ok := v.data.([]int); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustIntSlice gets the value as a []int. +// +// Panics if the object is not a []int. +func (v *Value) MustIntSlice() []int { + return v.data.([]int) +} + +// IsInt gets whether the object contained is a int or not. +func (v *Value) IsInt() bool { + _, ok := v.data.(int) + return ok +} + +// IsIntSlice gets whether the object contained is a []int or not. +func (v *Value) IsIntSlice() bool { + _, ok := v.data.([]int) + return ok +} + +// EachInt calls the specified callback for each object +// in the []int. +// +// Panics if the object is the wrong type. +func (v *Value) EachInt(callback func(int, int) bool) *Value { + for index, val := range v.MustIntSlice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereInt uses the specified decider function to select items +// from the []int. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereInt(decider func(int, int) bool) *Value { + var selected []int + v.EachInt(func(index int, val int) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupInt 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][]int. +func (v *Value) GroupInt(grouper func(int, int) string) *Value { + groups := make(map[string][]int) + v.EachInt(func(index int, val int) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]int, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceInt uses the specified function to replace each ints +// by iterating each item. The data in the returned result will be a +// []int containing the replaced items. +func (v *Value) ReplaceInt(replacer func(int, int) int) *Value { + arr := v.MustIntSlice() + replaced := make([]int, len(arr)) + v.EachInt(func(index int, val int) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectInt uses the specified collector function to collect a value +// for each of the ints in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectInt(collector func(int, int) interface{}) *Value { + arr := v.MustIntSlice() + collected := make([]interface{}, len(arr)) + v.EachInt(func(index int, val int) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Int8 (int8 and []int8) +*/ + +// Int8 gets the value as a int8, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Int8(optionalDefault ...int8) int8 { + if s, ok := v.data.(int8); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustInt8 gets the value as a int8. +// +// Panics if the object is not a int8. +func (v *Value) MustInt8() int8 { + return v.data.(int8) +} + +// Int8Slice gets the value as a []int8, returns the optionalDefault +// value or nil if the value is not a []int8. +func (v *Value) Int8Slice(optionalDefault ...[]int8) []int8 { + if s, ok := v.data.([]int8); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustInt8Slice gets the value as a []int8. +// +// Panics if the object is not a []int8. +func (v *Value) MustInt8Slice() []int8 { + return v.data.([]int8) +} + +// IsInt8 gets whether the object contained is a int8 or not. +func (v *Value) IsInt8() bool { + _, ok := v.data.(int8) + return ok +} + +// IsInt8Slice gets whether the object contained is a []int8 or not. +func (v *Value) IsInt8Slice() bool { + _, ok := v.data.([]int8) + return ok +} + +// EachInt8 calls the specified callback for each object +// in the []int8. +// +// Panics if the object is the wrong type. +func (v *Value) EachInt8(callback func(int, int8) bool) *Value { + for index, val := range v.MustInt8Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereInt8 uses the specified decider function to select items +// from the []int8. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereInt8(decider func(int, int8) bool) *Value { + var selected []int8 + v.EachInt8(func(index int, val int8) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupInt8 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][]int8. +func (v *Value) GroupInt8(grouper func(int, int8) string) *Value { + groups := make(map[string][]int8) + v.EachInt8(func(index int, val int8) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]int8, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceInt8 uses the specified function to replace each int8s +// by iterating each item. The data in the returned result will be a +// []int8 containing the replaced items. +func (v *Value) ReplaceInt8(replacer func(int, int8) int8) *Value { + arr := v.MustInt8Slice() + replaced := make([]int8, len(arr)) + v.EachInt8(func(index int, val int8) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectInt8 uses the specified collector function to collect a value +// for each of the int8s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectInt8(collector func(int, int8) interface{}) *Value { + arr := v.MustInt8Slice() + collected := make([]interface{}, len(arr)) + v.EachInt8(func(index int, val int8) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Int16 (int16 and []int16) +*/ + +// Int16 gets the value as a int16, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Int16(optionalDefault ...int16) int16 { + if s, ok := v.data.(int16); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustInt16 gets the value as a int16. +// +// Panics if the object is not a int16. +func (v *Value) MustInt16() int16 { + return v.data.(int16) +} + +// Int16Slice gets the value as a []int16, returns the optionalDefault +// value or nil if the value is not a []int16. +func (v *Value) Int16Slice(optionalDefault ...[]int16) []int16 { + if s, ok := v.data.([]int16); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustInt16Slice gets the value as a []int16. +// +// Panics if the object is not a []int16. +func (v *Value) MustInt16Slice() []int16 { + return v.data.([]int16) +} + +// IsInt16 gets whether the object contained is a int16 or not. +func (v *Value) IsInt16() bool { + _, ok := v.data.(int16) + return ok +} + +// IsInt16Slice gets whether the object contained is a []int16 or not. +func (v *Value) IsInt16Slice() bool { + _, ok := v.data.([]int16) + return ok +} + +// EachInt16 calls the specified callback for each object +// in the []int16. +// +// Panics if the object is the wrong type. +func (v *Value) EachInt16(callback func(int, int16) bool) *Value { + for index, val := range v.MustInt16Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereInt16 uses the specified decider function to select items +// from the []int16. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereInt16(decider func(int, int16) bool) *Value { + var selected []int16 + v.EachInt16(func(index int, val int16) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupInt16 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][]int16. +func (v *Value) GroupInt16(grouper func(int, int16) string) *Value { + groups := make(map[string][]int16) + v.EachInt16(func(index int, val int16) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]int16, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceInt16 uses the specified function to replace each int16s +// by iterating each item. The data in the returned result will be a +// []int16 containing the replaced items. +func (v *Value) ReplaceInt16(replacer func(int, int16) int16) *Value { + arr := v.MustInt16Slice() + replaced := make([]int16, len(arr)) + v.EachInt16(func(index int, val int16) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectInt16 uses the specified collector function to collect a value +// for each of the int16s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectInt16(collector func(int, int16) interface{}) *Value { + arr := v.MustInt16Slice() + collected := make([]interface{}, len(arr)) + v.EachInt16(func(index int, val int16) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Int32 (int32 and []int32) +*/ + +// Int32 gets the value as a int32, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Int32(optionalDefault ...int32) int32 { + if s, ok := v.data.(int32); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustInt32 gets the value as a int32. +// +// Panics if the object is not a int32. +func (v *Value) MustInt32() int32 { + return v.data.(int32) +} + +// Int32Slice gets the value as a []int32, returns the optionalDefault +// value or nil if the value is not a []int32. +func (v *Value) Int32Slice(optionalDefault ...[]int32) []int32 { + if s, ok := v.data.([]int32); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustInt32Slice gets the value as a []int32. +// +// Panics if the object is not a []int32. +func (v *Value) MustInt32Slice() []int32 { + return v.data.([]int32) +} + +// IsInt32 gets whether the object contained is a int32 or not. +func (v *Value) IsInt32() bool { + _, ok := v.data.(int32) + return ok +} + +// IsInt32Slice gets whether the object contained is a []int32 or not. +func (v *Value) IsInt32Slice() bool { + _, ok := v.data.([]int32) + return ok +} + +// EachInt32 calls the specified callback for each object +// in the []int32. +// +// Panics if the object is the wrong type. +func (v *Value) EachInt32(callback func(int, int32) bool) *Value { + for index, val := range v.MustInt32Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereInt32 uses the specified decider function to select items +// from the []int32. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereInt32(decider func(int, int32) bool) *Value { + var selected []int32 + v.EachInt32(func(index int, val int32) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupInt32 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][]int32. +func (v *Value) GroupInt32(grouper func(int, int32) string) *Value { + groups := make(map[string][]int32) + v.EachInt32(func(index int, val int32) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]int32, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceInt32 uses the specified function to replace each int32s +// by iterating each item. The data in the returned result will be a +// []int32 containing the replaced items. +func (v *Value) ReplaceInt32(replacer func(int, int32) int32) *Value { + arr := v.MustInt32Slice() + replaced := make([]int32, len(arr)) + v.EachInt32(func(index int, val int32) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectInt32 uses the specified collector function to collect a value +// for each of the int32s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectInt32(collector func(int, int32) interface{}) *Value { + arr := v.MustInt32Slice() + collected := make([]interface{}, len(arr)) + v.EachInt32(func(index int, val int32) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Int64 (int64 and []int64) +*/ + +// Int64 gets the value as a int64, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Int64(optionalDefault ...int64) int64 { + if s, ok := v.data.(int64); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustInt64 gets the value as a int64. +// +// Panics if the object is not a int64. +func (v *Value) MustInt64() int64 { + return v.data.(int64) +} + +// Int64Slice gets the value as a []int64, returns the optionalDefault +// value or nil if the value is not a []int64. +func (v *Value) Int64Slice(optionalDefault ...[]int64) []int64 { + if s, ok := v.data.([]int64); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustInt64Slice gets the value as a []int64. +// +// Panics if the object is not a []int64. +func (v *Value) MustInt64Slice() []int64 { + return v.data.([]int64) +} + +// IsInt64 gets whether the object contained is a int64 or not. +func (v *Value) IsInt64() bool { + _, ok := v.data.(int64) + return ok +} + +// IsInt64Slice gets whether the object contained is a []int64 or not. +func (v *Value) IsInt64Slice() bool { + _, ok := v.data.([]int64) + return ok +} + +// EachInt64 calls the specified callback for each object +// in the []int64. +// +// Panics if the object is the wrong type. +func (v *Value) EachInt64(callback func(int, int64) bool) *Value { + for index, val := range v.MustInt64Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereInt64 uses the specified decider function to select items +// from the []int64. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereInt64(decider func(int, int64) bool) *Value { + var selected []int64 + v.EachInt64(func(index int, val int64) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupInt64 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][]int64. +func (v *Value) GroupInt64(grouper func(int, int64) string) *Value { + groups := make(map[string][]int64) + v.EachInt64(func(index int, val int64) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]int64, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceInt64 uses the specified function to replace each int64s +// by iterating each item. The data in the returned result will be a +// []int64 containing the replaced items. +func (v *Value) ReplaceInt64(replacer func(int, int64) int64) *Value { + arr := v.MustInt64Slice() + replaced := make([]int64, len(arr)) + v.EachInt64(func(index int, val int64) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectInt64 uses the specified collector function to collect a value +// for each of the int64s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectInt64(collector func(int, int64) interface{}) *Value { + arr := v.MustInt64Slice() + collected := make([]interface{}, len(arr)) + v.EachInt64(func(index int, val int64) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Uint (uint and []uint) +*/ + +// Uint gets the value as a uint, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Uint(optionalDefault ...uint) uint { + if s, ok := v.data.(uint); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustUint gets the value as a uint. +// +// Panics if the object is not a uint. +func (v *Value) MustUint() uint { + return v.data.(uint) +} + +// UintSlice gets the value as a []uint, returns the optionalDefault +// value or nil if the value is not a []uint. +func (v *Value) UintSlice(optionalDefault ...[]uint) []uint { + if s, ok := v.data.([]uint); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustUintSlice gets the value as a []uint. +// +// Panics if the object is not a []uint. +func (v *Value) MustUintSlice() []uint { + return v.data.([]uint) +} + +// IsUint gets whether the object contained is a uint or not. +func (v *Value) IsUint() bool { + _, ok := v.data.(uint) + return ok +} + +// IsUintSlice gets whether the object contained is a []uint or not. +func (v *Value) IsUintSlice() bool { + _, ok := v.data.([]uint) + return ok +} + +// EachUint calls the specified callback for each object +// in the []uint. +// +// Panics if the object is the wrong type. +func (v *Value) EachUint(callback func(int, uint) bool) *Value { + for index, val := range v.MustUintSlice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereUint uses the specified decider function to select items +// from the []uint. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereUint(decider func(int, uint) bool) *Value { + var selected []uint + v.EachUint(func(index int, val uint) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupUint 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][]uint. +func (v *Value) GroupUint(grouper func(int, uint) string) *Value { + groups := make(map[string][]uint) + v.EachUint(func(index int, val uint) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]uint, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceUint uses the specified function to replace each uints +// by iterating each item. The data in the returned result will be a +// []uint containing the replaced items. +func (v *Value) ReplaceUint(replacer func(int, uint) uint) *Value { + arr := v.MustUintSlice() + replaced := make([]uint, len(arr)) + v.EachUint(func(index int, val uint) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectUint uses the specified collector function to collect a value +// for each of the uints in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectUint(collector func(int, uint) interface{}) *Value { + arr := v.MustUintSlice() + collected := make([]interface{}, len(arr)) + v.EachUint(func(index int, val uint) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Uint8 (uint8 and []uint8) +*/ + +// Uint8 gets the value as a uint8, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Uint8(optionalDefault ...uint8) uint8 { + if s, ok := v.data.(uint8); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustUint8 gets the value as a uint8. +// +// Panics if the object is not a uint8. +func (v *Value) MustUint8() uint8 { + return v.data.(uint8) +} + +// Uint8Slice gets the value as a []uint8, returns the optionalDefault +// value or nil if the value is not a []uint8. +func (v *Value) Uint8Slice(optionalDefault ...[]uint8) []uint8 { + if s, ok := v.data.([]uint8); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustUint8Slice gets the value as a []uint8. +// +// Panics if the object is not a []uint8. +func (v *Value) MustUint8Slice() []uint8 { + return v.data.([]uint8) +} + +// IsUint8 gets whether the object contained is a uint8 or not. +func (v *Value) IsUint8() bool { + _, ok := v.data.(uint8) + return ok +} + +// IsUint8Slice gets whether the object contained is a []uint8 or not. +func (v *Value) IsUint8Slice() bool { + _, ok := v.data.([]uint8) + return ok +} + +// EachUint8 calls the specified callback for each object +// in the []uint8. +// +// Panics if the object is the wrong type. +func (v *Value) EachUint8(callback func(int, uint8) bool) *Value { + for index, val := range v.MustUint8Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereUint8 uses the specified decider function to select items +// from the []uint8. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereUint8(decider func(int, uint8) bool) *Value { + var selected []uint8 + v.EachUint8(func(index int, val uint8) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupUint8 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][]uint8. +func (v *Value) GroupUint8(grouper func(int, uint8) string) *Value { + groups := make(map[string][]uint8) + v.EachUint8(func(index int, val uint8) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]uint8, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceUint8 uses the specified function to replace each uint8s +// by iterating each item. The data in the returned result will be a +// []uint8 containing the replaced items. +func (v *Value) ReplaceUint8(replacer func(int, uint8) uint8) *Value { + arr := v.MustUint8Slice() + replaced := make([]uint8, len(arr)) + v.EachUint8(func(index int, val uint8) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectUint8 uses the specified collector function to collect a value +// for each of the uint8s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectUint8(collector func(int, uint8) interface{}) *Value { + arr := v.MustUint8Slice() + collected := make([]interface{}, len(arr)) + v.EachUint8(func(index int, val uint8) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Uint16 (uint16 and []uint16) +*/ + +// Uint16 gets the value as a uint16, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Uint16(optionalDefault ...uint16) uint16 { + if s, ok := v.data.(uint16); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustUint16 gets the value as a uint16. +// +// Panics if the object is not a uint16. +func (v *Value) MustUint16() uint16 { + return v.data.(uint16) +} + +// Uint16Slice gets the value as a []uint16, returns the optionalDefault +// value or nil if the value is not a []uint16. +func (v *Value) Uint16Slice(optionalDefault ...[]uint16) []uint16 { + if s, ok := v.data.([]uint16); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustUint16Slice gets the value as a []uint16. +// +// Panics if the object is not a []uint16. +func (v *Value) MustUint16Slice() []uint16 { + return v.data.([]uint16) +} + +// IsUint16 gets whether the object contained is a uint16 or not. +func (v *Value) IsUint16() bool { + _, ok := v.data.(uint16) + return ok +} + +// IsUint16Slice gets whether the object contained is a []uint16 or not. +func (v *Value) IsUint16Slice() bool { + _, ok := v.data.([]uint16) + return ok +} + +// EachUint16 calls the specified callback for each object +// in the []uint16. +// +// Panics if the object is the wrong type. +func (v *Value) EachUint16(callback func(int, uint16) bool) *Value { + for index, val := range v.MustUint16Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereUint16 uses the specified decider function to select items +// from the []uint16. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereUint16(decider func(int, uint16) bool) *Value { + var selected []uint16 + v.EachUint16(func(index int, val uint16) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupUint16 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][]uint16. +func (v *Value) GroupUint16(grouper func(int, uint16) string) *Value { + groups := make(map[string][]uint16) + v.EachUint16(func(index int, val uint16) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]uint16, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceUint16 uses the specified function to replace each uint16s +// by iterating each item. The data in the returned result will be a +// []uint16 containing the replaced items. +func (v *Value) ReplaceUint16(replacer func(int, uint16) uint16) *Value { + arr := v.MustUint16Slice() + replaced := make([]uint16, len(arr)) + v.EachUint16(func(index int, val uint16) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectUint16 uses the specified collector function to collect a value +// for each of the uint16s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectUint16(collector func(int, uint16) interface{}) *Value { + arr := v.MustUint16Slice() + collected := make([]interface{}, len(arr)) + v.EachUint16(func(index int, val uint16) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Uint32 (uint32 and []uint32) +*/ + +// Uint32 gets the value as a uint32, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Uint32(optionalDefault ...uint32) uint32 { + if s, ok := v.data.(uint32); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustUint32 gets the value as a uint32. +// +// Panics if the object is not a uint32. +func (v *Value) MustUint32() uint32 { + return v.data.(uint32) +} + +// Uint32Slice gets the value as a []uint32, returns the optionalDefault +// value or nil if the value is not a []uint32. +func (v *Value) Uint32Slice(optionalDefault ...[]uint32) []uint32 { + if s, ok := v.data.([]uint32); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustUint32Slice gets the value as a []uint32. +// +// Panics if the object is not a []uint32. +func (v *Value) MustUint32Slice() []uint32 { + return v.data.([]uint32) +} + +// IsUint32 gets whether the object contained is a uint32 or not. +func (v *Value) IsUint32() bool { + _, ok := v.data.(uint32) + return ok +} + +// IsUint32Slice gets whether the object contained is a []uint32 or not. +func (v *Value) IsUint32Slice() bool { + _, ok := v.data.([]uint32) + return ok +} + +// EachUint32 calls the specified callback for each object +// in the []uint32. +// +// Panics if the object is the wrong type. +func (v *Value) EachUint32(callback func(int, uint32) bool) *Value { + for index, val := range v.MustUint32Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereUint32 uses the specified decider function to select items +// from the []uint32. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereUint32(decider func(int, uint32) bool) *Value { + var selected []uint32 + v.EachUint32(func(index int, val uint32) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupUint32 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][]uint32. +func (v *Value) GroupUint32(grouper func(int, uint32) string) *Value { + groups := make(map[string][]uint32) + v.EachUint32(func(index int, val uint32) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]uint32, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceUint32 uses the specified function to replace each uint32s +// by iterating each item. The data in the returned result will be a +// []uint32 containing the replaced items. +func (v *Value) ReplaceUint32(replacer func(int, uint32) uint32) *Value { + arr := v.MustUint32Slice() + replaced := make([]uint32, len(arr)) + v.EachUint32(func(index int, val uint32) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectUint32 uses the specified collector function to collect a value +// for each of the uint32s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectUint32(collector func(int, uint32) interface{}) *Value { + arr := v.MustUint32Slice() + collected := make([]interface{}, len(arr)) + v.EachUint32(func(index int, val uint32) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Uint64 (uint64 and []uint64) +*/ + +// Uint64 gets the value as a uint64, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Uint64(optionalDefault ...uint64) uint64 { + if s, ok := v.data.(uint64); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustUint64 gets the value as a uint64. +// +// Panics if the object is not a uint64. +func (v *Value) MustUint64() uint64 { + return v.data.(uint64) +} + +// Uint64Slice gets the value as a []uint64, returns the optionalDefault +// value or nil if the value is not a []uint64. +func (v *Value) Uint64Slice(optionalDefault ...[]uint64) []uint64 { + if s, ok := v.data.([]uint64); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustUint64Slice gets the value as a []uint64. +// +// Panics if the object is not a []uint64. +func (v *Value) MustUint64Slice() []uint64 { + return v.data.([]uint64) +} + +// IsUint64 gets whether the object contained is a uint64 or not. +func (v *Value) IsUint64() bool { + _, ok := v.data.(uint64) + return ok +} + +// IsUint64Slice gets whether the object contained is a []uint64 or not. +func (v *Value) IsUint64Slice() bool { + _, ok := v.data.([]uint64) + return ok +} + +// EachUint64 calls the specified callback for each object +// in the []uint64. +// +// Panics if the object is the wrong type. +func (v *Value) EachUint64(callback func(int, uint64) bool) *Value { + for index, val := range v.MustUint64Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereUint64 uses the specified decider function to select items +// from the []uint64. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereUint64(decider func(int, uint64) bool) *Value { + var selected []uint64 + v.EachUint64(func(index int, val uint64) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupUint64 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][]uint64. +func (v *Value) GroupUint64(grouper func(int, uint64) string) *Value { + groups := make(map[string][]uint64) + v.EachUint64(func(index int, val uint64) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]uint64, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceUint64 uses the specified function to replace each uint64s +// by iterating each item. The data in the returned result will be a +// []uint64 containing the replaced items. +func (v *Value) ReplaceUint64(replacer func(int, uint64) uint64) *Value { + arr := v.MustUint64Slice() + replaced := make([]uint64, len(arr)) + v.EachUint64(func(index int, val uint64) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectUint64 uses the specified collector function to collect a value +// for each of the uint64s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectUint64(collector func(int, uint64) interface{}) *Value { + arr := v.MustUint64Slice() + collected := make([]interface{}, len(arr)) + v.EachUint64(func(index int, val uint64) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Uintptr (uintptr and []uintptr) +*/ + +// Uintptr gets the value as a uintptr, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Uintptr(optionalDefault ...uintptr) uintptr { + if s, ok := v.data.(uintptr); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustUintptr gets the value as a uintptr. +// +// Panics if the object is not a uintptr. +func (v *Value) MustUintptr() uintptr { + return v.data.(uintptr) +} + +// UintptrSlice gets the value as a []uintptr, returns the optionalDefault +// value or nil if the value is not a []uintptr. +func (v *Value) UintptrSlice(optionalDefault ...[]uintptr) []uintptr { + if s, ok := v.data.([]uintptr); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustUintptrSlice gets the value as a []uintptr. +// +// Panics if the object is not a []uintptr. +func (v *Value) MustUintptrSlice() []uintptr { + return v.data.([]uintptr) +} + +// IsUintptr gets whether the object contained is a uintptr or not. +func (v *Value) IsUintptr() bool { + _, ok := v.data.(uintptr) + return ok +} + +// IsUintptrSlice gets whether the object contained is a []uintptr or not. +func (v *Value) IsUintptrSlice() bool { + _, ok := v.data.([]uintptr) + return ok +} + +// EachUintptr calls the specified callback for each object +// in the []uintptr. +// +// Panics if the object is the wrong type. +func (v *Value) EachUintptr(callback func(int, uintptr) bool) *Value { + for index, val := range v.MustUintptrSlice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereUintptr uses the specified decider function to select items +// from the []uintptr. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereUintptr(decider func(int, uintptr) bool) *Value { + var selected []uintptr + v.EachUintptr(func(index int, val uintptr) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupUintptr 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][]uintptr. +func (v *Value) GroupUintptr(grouper func(int, uintptr) string) *Value { + groups := make(map[string][]uintptr) + v.EachUintptr(func(index int, val uintptr) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]uintptr, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceUintptr uses the specified function to replace each uintptrs +// by iterating each item. The data in the returned result will be a +// []uintptr containing the replaced items. +func (v *Value) ReplaceUintptr(replacer func(int, uintptr) uintptr) *Value { + arr := v.MustUintptrSlice() + replaced := make([]uintptr, len(arr)) + v.EachUintptr(func(index int, val uintptr) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectUintptr uses the specified collector function to collect a value +// for each of the uintptrs in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectUintptr(collector func(int, uintptr) interface{}) *Value { + arr := v.MustUintptrSlice() + collected := make([]interface{}, len(arr)) + v.EachUintptr(func(index int, val uintptr) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Float32 (float32 and []float32) +*/ + +// Float32 gets the value as a float32, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Float32(optionalDefault ...float32) float32 { + if s, ok := v.data.(float32); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustFloat32 gets the value as a float32. +// +// Panics if the object is not a float32. +func (v *Value) MustFloat32() float32 { + return v.data.(float32) +} + +// Float32Slice gets the value as a []float32, returns the optionalDefault +// value or nil if the value is not a []float32. +func (v *Value) Float32Slice(optionalDefault ...[]float32) []float32 { + if s, ok := v.data.([]float32); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustFloat32Slice gets the value as a []float32. +// +// Panics if the object is not a []float32. +func (v *Value) MustFloat32Slice() []float32 { + return v.data.([]float32) +} + +// IsFloat32 gets whether the object contained is a float32 or not. +func (v *Value) IsFloat32() bool { + _, ok := v.data.(float32) + return ok +} + +// IsFloat32Slice gets whether the object contained is a []float32 or not. +func (v *Value) IsFloat32Slice() bool { + _, ok := v.data.([]float32) + return ok +} + +// EachFloat32 calls the specified callback for each object +// in the []float32. +// +// Panics if the object is the wrong type. +func (v *Value) EachFloat32(callback func(int, float32) bool) *Value { + for index, val := range v.MustFloat32Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereFloat32 uses the specified decider function to select items +// from the []float32. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereFloat32(decider func(int, float32) bool) *Value { + var selected []float32 + v.EachFloat32(func(index int, val float32) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupFloat32 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][]float32. +func (v *Value) GroupFloat32(grouper func(int, float32) string) *Value { + groups := make(map[string][]float32) + v.EachFloat32(func(index int, val float32) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]float32, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceFloat32 uses the specified function to replace each float32s +// by iterating each item. The data in the returned result will be a +// []float32 containing the replaced items. +func (v *Value) ReplaceFloat32(replacer func(int, float32) float32) *Value { + arr := v.MustFloat32Slice() + replaced := make([]float32, len(arr)) + v.EachFloat32(func(index int, val float32) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectFloat32 uses the specified collector function to collect a value +// for each of the float32s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectFloat32(collector func(int, float32) interface{}) *Value { + arr := v.MustFloat32Slice() + collected := make([]interface{}, len(arr)) + v.EachFloat32(func(index int, val float32) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Float64 (float64 and []float64) +*/ + +// Float64 gets the value as a float64, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Float64(optionalDefault ...float64) float64 { + if s, ok := v.data.(float64); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustFloat64 gets the value as a float64. +// +// Panics if the object is not a float64. +func (v *Value) MustFloat64() float64 { + return v.data.(float64) +} + +// Float64Slice gets the value as a []float64, returns the optionalDefault +// value or nil if the value is not a []float64. +func (v *Value) Float64Slice(optionalDefault ...[]float64) []float64 { + if s, ok := v.data.([]float64); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustFloat64Slice gets the value as a []float64. +// +// Panics if the object is not a []float64. +func (v *Value) MustFloat64Slice() []float64 { + return v.data.([]float64) +} + +// IsFloat64 gets whether the object contained is a float64 or not. +func (v *Value) IsFloat64() bool { + _, ok := v.data.(float64) + return ok +} + +// IsFloat64Slice gets whether the object contained is a []float64 or not. +func (v *Value) IsFloat64Slice() bool { + _, ok := v.data.([]float64) + return ok +} + +// EachFloat64 calls the specified callback for each object +// in the []float64. +// +// Panics if the object is the wrong type. +func (v *Value) EachFloat64(callback func(int, float64) bool) *Value { + for index, val := range v.MustFloat64Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereFloat64 uses the specified decider function to select items +// from the []float64. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereFloat64(decider func(int, float64) bool) *Value { + var selected []float64 + v.EachFloat64(func(index int, val float64) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupFloat64 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][]float64. +func (v *Value) GroupFloat64(grouper func(int, float64) string) *Value { + groups := make(map[string][]float64) + v.EachFloat64(func(index int, val float64) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]float64, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceFloat64 uses the specified function to replace each float64s +// by iterating each item. The data in the returned result will be a +// []float64 containing the replaced items. +func (v *Value) ReplaceFloat64(replacer func(int, float64) float64) *Value { + arr := v.MustFloat64Slice() + replaced := make([]float64, len(arr)) + v.EachFloat64(func(index int, val float64) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectFloat64 uses the specified collector function to collect a value +// for each of the float64s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectFloat64(collector func(int, float64) interface{}) *Value { + arr := v.MustFloat64Slice() + collected := make([]interface{}, len(arr)) + v.EachFloat64(func(index int, val float64) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Complex64 (complex64 and []complex64) +*/ + +// Complex64 gets the value as a complex64, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Complex64(optionalDefault ...complex64) complex64 { + if s, ok := v.data.(complex64); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustComplex64 gets the value as a complex64. +// +// Panics if the object is not a complex64. +func (v *Value) MustComplex64() complex64 { + return v.data.(complex64) +} + +// Complex64Slice gets the value as a []complex64, returns the optionalDefault +// value or nil if the value is not a []complex64. +func (v *Value) Complex64Slice(optionalDefault ...[]complex64) []complex64 { + if s, ok := v.data.([]complex64); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustComplex64Slice gets the value as a []complex64. +// +// Panics if the object is not a []complex64. +func (v *Value) MustComplex64Slice() []complex64 { + return v.data.([]complex64) +} + +// IsComplex64 gets whether the object contained is a complex64 or not. +func (v *Value) IsComplex64() bool { + _, ok := v.data.(complex64) + return ok +} + +// IsComplex64Slice gets whether the object contained is a []complex64 or not. +func (v *Value) IsComplex64Slice() bool { + _, ok := v.data.([]complex64) + return ok +} + +// EachComplex64 calls the specified callback for each object +// in the []complex64. +// +// Panics if the object is the wrong type. +func (v *Value) EachComplex64(callback func(int, complex64) bool) *Value { + for index, val := range v.MustComplex64Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereComplex64 uses the specified decider function to select items +// from the []complex64. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereComplex64(decider func(int, complex64) bool) *Value { + var selected []complex64 + v.EachComplex64(func(index int, val complex64) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupComplex64 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][]complex64. +func (v *Value) GroupComplex64(grouper func(int, complex64) string) *Value { + groups := make(map[string][]complex64) + v.EachComplex64(func(index int, val complex64) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]complex64, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceComplex64 uses the specified function to replace each complex64s +// by iterating each item. The data in the returned result will be a +// []complex64 containing the replaced items. +func (v *Value) ReplaceComplex64(replacer func(int, complex64) complex64) *Value { + arr := v.MustComplex64Slice() + replaced := make([]complex64, len(arr)) + v.EachComplex64(func(index int, val complex64) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectComplex64 uses the specified collector function to collect a value +// for each of the complex64s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectComplex64(collector func(int, complex64) interface{}) *Value { + arr := v.MustComplex64Slice() + collected := make([]interface{}, len(arr)) + v.EachComplex64(func(index int, val complex64) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} + +/* + Complex128 (complex128 and []complex128) +*/ + +// Complex128 gets the value as a complex128, returns the optionalDefault +// value or a system default object if the value is the wrong type. +func (v *Value) Complex128(optionalDefault ...complex128) complex128 { + if s, ok := v.data.(complex128); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return 0 +} + +// MustComplex128 gets the value as a complex128. +// +// Panics if the object is not a complex128. +func (v *Value) MustComplex128() complex128 { + return v.data.(complex128) +} + +// Complex128Slice gets the value as a []complex128, returns the optionalDefault +// value or nil if the value is not a []complex128. +func (v *Value) Complex128Slice(optionalDefault ...[]complex128) []complex128 { + if s, ok := v.data.([]complex128); ok { + return s + } + if len(optionalDefault) == 1 { + return optionalDefault[0] + } + return nil +} + +// MustComplex128Slice gets the value as a []complex128. +// +// Panics if the object is not a []complex128. +func (v *Value) MustComplex128Slice() []complex128 { + return v.data.([]complex128) +} + +// IsComplex128 gets whether the object contained is a complex128 or not. +func (v *Value) IsComplex128() bool { + _, ok := v.data.(complex128) + return ok +} + +// IsComplex128Slice gets whether the object contained is a []complex128 or not. +func (v *Value) IsComplex128Slice() bool { + _, ok := v.data.([]complex128) + return ok +} + +// EachComplex128 calls the specified callback for each object +// in the []complex128. +// +// Panics if the object is the wrong type. +func (v *Value) EachComplex128(callback func(int, complex128) bool) *Value { + for index, val := range v.MustComplex128Slice() { + carryon := callback(index, val) + if !carryon { + break + } + } + return v +} + +// WhereComplex128 uses the specified decider function to select items +// from the []complex128. The object contained in the result will contain +// only the selected items. +func (v *Value) WhereComplex128(decider func(int, complex128) bool) *Value { + var selected []complex128 + v.EachComplex128(func(index int, val complex128) bool { + shouldSelect := decider(index, val) + if !shouldSelect { + selected = append(selected, val) + } + return true + }) + return &Value{data: selected} +} + +// GroupComplex128 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][]complex128. +func (v *Value) GroupComplex128(grouper func(int, complex128) string) *Value { + groups := make(map[string][]complex128) + v.EachComplex128(func(index int, val complex128) bool { + group := grouper(index, val) + if _, ok := groups[group]; !ok { + groups[group] = make([]complex128, 0) + } + groups[group] = append(groups[group], val) + return true + }) + return &Value{data: groups} +} + +// ReplaceComplex128 uses the specified function to replace each complex128s +// by iterating each item. The data in the returned result will be a +// []complex128 containing the replaced items. +func (v *Value) ReplaceComplex128(replacer func(int, complex128) complex128) *Value { + arr := v.MustComplex128Slice() + replaced := make([]complex128, len(arr)) + v.EachComplex128(func(index int, val complex128) bool { + replaced[index] = replacer(index, val) + return true + }) + return &Value{data: replaced} +} + +// CollectComplex128 uses the specified collector function to collect a value +// for each of the complex128s in the slice. The data returned will be a +// []interface{}. +func (v *Value) CollectComplex128(collector func(int, complex128) interface{}) *Value { + arr := v.MustComplex128Slice() + collected := make([]interface{}, len(arr)) + v.EachComplex128(func(index int, val complex128) bool { + collected[index] = collector(index, val) + return true + }) + return &Value{data: collected} +} diff --git a/vendor/github.com/stretchr/objx/value.go b/vendor/github.com/stretchr/objx/value.go new file mode 100644 index 00000000000..4e5f9b77e69 --- /dev/null +++ b/vendor/github.com/stretchr/objx/value.go @@ -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{} +} diff --git a/vendor/github.com/stretchr/testify/mock/doc.go b/vendor/github.com/stretchr/testify/mock/doc.go new file mode 100644 index 00000000000..d6b3c844cc8 --- /dev/null +++ b/vendor/github.com/stretchr/testify/mock/doc.go @@ -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 diff --git a/vendor/github.com/stretchr/testify/mock/mock.go b/vendor/github.com/stretchr/testify/mock/mock.go new file mode 100644 index 00000000000..f4b42e44ffe --- /dev/null +++ b/vendor/github.com/stretchr/testify/mock/mock.go @@ -0,0 +1,1226 @@ +package mock + +import ( + "errors" + "fmt" + "path" + "reflect" + "regexp" + "runtime" + "strings" + "sync" + "time" + + "github.com/davecgh/go-spew/spew" + "github.com/pmezard/go-difflib/difflib" + "github.com/stretchr/objx" + + "github.com/stretchr/testify/assert" +) + +// TestingT is an interface wrapper around *testing.T +type TestingT interface { + Logf(format string, args ...interface{}) + Errorf(format string, args ...interface{}) + FailNow() +} + +/* + Call +*/ + +// Call represents a method call and is used for setting expectations, +// as well as recording activity. +type Call struct { + Parent *Mock + + // The name of the method that was or will be called. + Method string + + // Holds the arguments of the method. + Arguments Arguments + + // Holds the arguments that should be returned when + // this method is called. + ReturnArguments Arguments + + // Holds the caller info for the On() call + callerInfo []string + + // The number of times to return the return arguments when setting + // expectations. 0 means to always return the value. + Repeatability int + + // Amount of times this call has been called + totalCalls int + + // Call to this method can be optional + optional bool + + // Holds a channel that will be used to block the Return until it either + // receives a message or is closed. nil means it returns immediately. + WaitFor <-chan time.Time + + waitTime time.Duration + + // Holds a handler used to manipulate arguments content that are passed by + // reference. It's useful when mocking methods such as unmarshalers or + // decoders. + RunFn func(Arguments) + + // PanicMsg holds msg to be used to mock panic on the function call + // if the PanicMsg is set to a non nil string the function call will panic + // irrespective of other settings + PanicMsg *string + + // Calls which must be satisfied before this call can be + requires []*Call +} + +func newCall(parent *Mock, methodName string, callerInfo []string, methodArguments ...interface{}) *Call { + return &Call{ + Parent: parent, + Method: methodName, + Arguments: methodArguments, + ReturnArguments: make([]interface{}, 0), + callerInfo: callerInfo, + Repeatability: 0, + WaitFor: nil, + RunFn: nil, + PanicMsg: nil, + } +} + +func (c *Call) lock() { + c.Parent.mutex.Lock() +} + +func (c *Call) unlock() { + c.Parent.mutex.Unlock() +} + +// Return specifies the return arguments for the expectation. +// +// Mock.On("DoSomething").Return(errors.New("failed")) +func (c *Call) Return(returnArguments ...interface{}) *Call { + c.lock() + defer c.unlock() + + c.ReturnArguments = returnArguments + + return c +} + +// Panic specifies if the functon call should fail and the panic message +// +// Mock.On("DoSomething").Panic("test panic") +func (c *Call) Panic(msg string) *Call { + c.lock() + defer c.unlock() + + c.PanicMsg = &msg + + return c +} + +// Once indicates that that the mock should only return the value once. +// +// Mock.On("MyMethod", arg1, arg2).Return(returnArg1, returnArg2).Once() +func (c *Call) Once() *Call { + return c.Times(1) +} + +// Twice indicates that that the mock should only return the value twice. +// +// Mock.On("MyMethod", arg1, arg2).Return(returnArg1, returnArg2).Twice() +func (c *Call) Twice() *Call { + return c.Times(2) +} + +// Times indicates that that the mock should only return the indicated number +// of times. +// +// Mock.On("MyMethod", arg1, arg2).Return(returnArg1, returnArg2).Times(5) +func (c *Call) Times(i int) *Call { + c.lock() + defer c.unlock() + c.Repeatability = i + return c +} + +// WaitUntil sets the channel that will block the mock's return until its closed +// or a message is received. +// +// Mock.On("MyMethod", arg1, arg2).WaitUntil(time.After(time.Second)) +func (c *Call) WaitUntil(w <-chan time.Time) *Call { + c.lock() + defer c.unlock() + c.WaitFor = w + return c +} + +// After sets how long to block until the call returns +// +// Mock.On("MyMethod", arg1, arg2).After(time.Second) +func (c *Call) After(d time.Duration) *Call { + c.lock() + defer c.unlock() + c.waitTime = d + return c +} + +// Run sets a handler to be called before returning. It can be used when +// mocking a method (such as an unmarshaler) that takes a pointer to a struct and +// sets properties in such struct +// +// Mock.On("Unmarshal", AnythingOfType("*map[string]interface{}")).Return().Run(func(args Arguments) { +// arg := args.Get(0).(*map[string]interface{}) +// arg["foo"] = "bar" +// }) +func (c *Call) Run(fn func(args Arguments)) *Call { + c.lock() + defer c.unlock() + c.RunFn = fn + return c +} + +// Maybe allows the method call to be optional. Not calling an optional method +// will not cause an error while asserting expectations +func (c *Call) Maybe() *Call { + c.lock() + defer c.unlock() + c.optional = true + return c +} + +// On chains a new expectation description onto the mocked interface. This +// allows syntax like. +// +// Mock. +// On("MyMethod", 1).Return(nil). +// On("MyOtherMethod", 'a', 'b', 'c').Return(errors.New("Some Error")) +// +//go:noinline +func (c *Call) On(methodName string, arguments ...interface{}) *Call { + return c.Parent.On(methodName, arguments...) +} + +// Unset removes a mock handler from being called. +// +// test.On("func", mock.Anything).Unset() +func (c *Call) Unset() *Call { + var unlockOnce sync.Once + + for _, arg := range c.Arguments { + if v := reflect.ValueOf(arg); v.Kind() == reflect.Func { + panic(fmt.Sprintf("cannot use Func in expectations. Use mock.AnythingOfType(\"%T\")", arg)) + } + } + + c.lock() + defer unlockOnce.Do(c.unlock) + + foundMatchingCall := false + + // in-place filter slice for calls to be removed - iterate from 0'th to last skipping unnecessary ones + var index int // write index + for _, call := range c.Parent.ExpectedCalls { + if call.Method == c.Method { + _, diffCount := call.Arguments.Diff(c.Arguments) + if diffCount == 0 { + foundMatchingCall = true + // Remove from ExpectedCalls - just skip it + continue + } + } + c.Parent.ExpectedCalls[index] = call + index++ + } + // trim slice up to last copied index + c.Parent.ExpectedCalls = c.Parent.ExpectedCalls[:index] + + if !foundMatchingCall { + unlockOnce.Do(c.unlock) + c.Parent.fail("\n\nmock: Could not find expected call\n-----------------------------\n\n%s\n\n", + callString(c.Method, c.Arguments, true), + ) + } + + return c +} + +// NotBefore indicates that the mock should only be called after the referenced +// calls have been called as expected. The referenced calls may be from the +// same mock instance and/or other mock instances. +// +// Mock.On("Do").Return(nil).Notbefore( +// Mock.On("Init").Return(nil) +// ) +func (c *Call) NotBefore(calls ...*Call) *Call { + c.lock() + defer c.unlock() + + for _, call := range calls { + if call.Parent == nil { + panic("not before calls must be created with Mock.On()") + } + } + + c.requires = append(c.requires, calls...) + return c +} + +// Mock is the workhorse used to track activity on another object. +// For an example of its usage, refer to the "Example Usage" section at the top +// of this document. +type Mock struct { + // Represents the calls that are expected of + // an object. + ExpectedCalls []*Call + + // Holds the calls that were made to this mocked object. + Calls []Call + + // test is An optional variable that holds the test struct, to be used when an + // invalid mock call was made. + test TestingT + + // TestData holds any data that might be useful for testing. Testify ignores + // this data completely allowing you to do whatever you like with it. + testData objx.Map + + mutex sync.Mutex +} + +// String provides a %v format string for Mock. +// Note: this is used implicitly by Arguments.Diff if a Mock is passed. +// It exists because go's default %v formatting traverses the struct +// without acquiring the mutex, which is detected by go test -race. +func (m *Mock) String() string { + return fmt.Sprintf("%[1]T<%[1]p>", m) +} + +// TestData holds any data that might be useful for testing. Testify ignores +// this data completely allowing you to do whatever you like with it. +func (m *Mock) TestData() objx.Map { + if m.testData == nil { + m.testData = make(objx.Map) + } + + return m.testData +} + +/* + Setting expectations +*/ + +// Test sets the test struct variable of the mock object +func (m *Mock) Test(t TestingT) { + m.mutex.Lock() + defer m.mutex.Unlock() + m.test = t +} + +// fail fails the current test with the given formatted format and args. +// In case that a test was defined, it uses the test APIs for failing a test, +// otherwise it uses panic. +func (m *Mock) fail(format string, args ...interface{}) { + m.mutex.Lock() + defer m.mutex.Unlock() + + if m.test == nil { + panic(fmt.Sprintf(format, args...)) + } + m.test.Errorf(format, args...) + m.test.FailNow() +} + +// On starts a description of an expectation of the specified method +// being called. +// +// Mock.On("MyMethod", arg1, arg2) +func (m *Mock) On(methodName string, arguments ...interface{}) *Call { + for _, arg := range arguments { + if v := reflect.ValueOf(arg); v.Kind() == reflect.Func { + panic(fmt.Sprintf("cannot use Func in expectations. Use mock.AnythingOfType(\"%T\")", arg)) + } + } + + m.mutex.Lock() + defer m.mutex.Unlock() + c := newCall(m, methodName, assert.CallerInfo(), arguments...) + m.ExpectedCalls = append(m.ExpectedCalls, c) + return c +} + +// /* +// Recording and responding to activity +// */ + +func (m *Mock) findExpectedCall(method string, arguments ...interface{}) (int, *Call) { + var expectedCall *Call + + for i, call := range m.ExpectedCalls { + if call.Method == method { + _, diffCount := call.Arguments.Diff(arguments) + if diffCount == 0 { + expectedCall = call + if call.Repeatability > -1 { + return i, call + } + } + } + } + + return -1, expectedCall +} + +type matchCandidate struct { + call *Call + mismatch string + diffCount int +} + +func (c matchCandidate) isBetterMatchThan(other matchCandidate) bool { + if c.call == nil { + return false + } + if other.call == nil { + return true + } + + if c.diffCount > other.diffCount { + return false + } + if c.diffCount < other.diffCount { + return true + } + + if c.call.Repeatability > 0 && other.call.Repeatability <= 0 { + return true + } + return false +} + +func (m *Mock) findClosestCall(method string, arguments ...interface{}) (*Call, string) { + var bestMatch matchCandidate + + for _, call := range m.expectedCalls() { + if call.Method == method { + + errInfo, tempDiffCount := call.Arguments.Diff(arguments) + tempCandidate := matchCandidate{ + call: call, + mismatch: errInfo, + diffCount: tempDiffCount, + } + if tempCandidate.isBetterMatchThan(bestMatch) { + bestMatch = tempCandidate + } + } + } + + return bestMatch.call, bestMatch.mismatch +} + +func callString(method string, arguments Arguments, includeArgumentValues bool) string { + var argValsString string + if includeArgumentValues { + var argVals []string + for argIndex, arg := range arguments { + if _, ok := arg.(*FunctionalOptionsArgument); ok { + argVals = append(argVals, fmt.Sprintf("%d: %s", argIndex, arg)) + continue + } + argVals = append(argVals, fmt.Sprintf("%d: %#v", argIndex, arg)) + } + argValsString = fmt.Sprintf("\n\t\t%s", strings.Join(argVals, "\n\t\t")) + } + + return fmt.Sprintf("%s(%s)%s", method, arguments.String(), argValsString) +} + +// Called tells the mock object that a method has been called, and gets an array +// of arguments to return. Panics if the call is unexpected (i.e. not preceded by +// appropriate .On .Return() calls) +// If Call.WaitFor is set, blocks until the channel is closed or receives a message. +func (m *Mock) Called(arguments ...interface{}) Arguments { + // get the calling function's name + pc, _, _, ok := runtime.Caller(1) + if !ok { + panic("Couldn't get the caller information") + } + functionPath := runtime.FuncForPC(pc).Name() + // Next four lines are required to use GCCGO function naming conventions. + // For Ex: github_com_docker_libkv_store_mock.WatchTree.pN39_github_com_docker_libkv_store_mock.Mock + // uses interface information unlike golang github.com/docker/libkv/store/mock.(*Mock).WatchTree + // With GCCGO we need to remove interface information starting from pN