diff --git a/testing/mockeryutils/Makefile b/testing/mockeryutils/Makefile new file mode 100644 index 00000000..4d044960 --- /dev/null +++ b/testing/mockeryutils/Makefile @@ -0,0 +1,25 @@ +# Copyright 2024 The Nephio 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. + +.PHONY: all +all: fmt test + +# This includes the following targets: +# test, unit, unit-clean, +# gosec, lint, +# fmt, vet, +include ../../default-go.mk + +# This includes the 'help' target that prints out all targets with their descriptions organized by categories +include ../../default-help.mk diff --git a/testing/mockeryutils/go.mod b/testing/mockeryutils/go.mod new file mode 100644 index 00000000..8725128a --- /dev/null +++ b/testing/mockeryutils/go.mod @@ -0,0 +1,12 @@ +module github.com/nephio-project/nephio/testing/mockeryutils + +go 1.20 + +require github.com/stretchr/testify v1.8.4 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/objx v0.5.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/testing/mockeryutils/go.sum b/testing/mockeryutils/go.sum new file mode 100644 index 00000000..673e9186 --- /dev/null +++ b/testing/mockeryutils/go.sum @@ -0,0 +1,18 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +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.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/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= diff --git a/testing/mockeryutils/mockeryutils-types.go b/testing/mockeryutils/mockeryutils-types.go new file mode 100644 index 00000000..9a7713bb --- /dev/null +++ b/testing/mockeryutils/mockeryutils-types.go @@ -0,0 +1,23 @@ +/* +Copyright 2024 The Nephio 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. +*/ + +package mockeryutils + +type MockHelper struct { + MethodName string // This field maps to the "Method" field at https://godoc.org/github.com/stretchr/testify/mock#Call + ArgType []string + RetArgList []interface{} +} diff --git a/testing/mockeryutils/mockeryutils.go b/testing/mockeryutils/mockeryutils.go new file mode 100644 index 00000000..735491bc --- /dev/null +++ b/testing/mockeryutils/mockeryutils.go @@ -0,0 +1,37 @@ +/* +Copyright 2024 The Nephio 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. +*/ + +package mockeryutils + +import ( + "github.com/stretchr/testify/mock" +) + +func InitMocks(mocked *mock.Mock, mocks []MockHelper) { + if mocked == nil { + panic("\"mocked\" may not be nil") + } + + for counter := range mocks { + call := mocked.On(mocks[counter].MethodName) + for _, arg := range mocks[counter].ArgType { + call.Arguments = append(call.Arguments, mock.AnythingOfType(arg)) + } + for _, ret := range mocks[counter].RetArgList { + call.ReturnArguments = append(call.ReturnArguments, ret) + } + } +}