mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
add methods to apimachinery to easy unit testing
This commit is contained in:
parent
4bec356e01
commit
1f703d33f5
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package testing
|
package apitesting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -84,3 +84,33 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InstallOrDieFunc mirrors install functions that require success
|
||||||
|
type InstallOrDieFunc func(scheme *runtime.Scheme)
|
||||||
|
|
||||||
|
// SchemeForInstallOrDie builds a simple test scheme and codecfactory pair for easy unit testing from higher level install methods
|
||||||
|
func SchemeForInstallOrDie(installFns ...InstallOrDieFunc) (*runtime.Scheme, runtimeserializer.CodecFactory) {
|
||||||
|
scheme := runtime.NewScheme()
|
||||||
|
codecFactory := runtimeserializer.NewCodecFactory(scheme)
|
||||||
|
for _, installFn := range installFns {
|
||||||
|
installFn(scheme)
|
||||||
|
}
|
||||||
|
|
||||||
|
return scheme, codecFactory
|
||||||
|
}
|
||||||
|
|
||||||
|
// InstallFunc mirrors install functions that can return an error
|
||||||
|
type InstallFunc func(scheme *runtime.Scheme) error
|
||||||
|
|
||||||
|
// SchemeForOrDie builds a simple test scheme and codecfactory pair for easy unit testing from the bare registration methods.
|
||||||
|
func SchemeForOrDie(installFns ...InstallFunc) (*runtime.Scheme, runtimeserializer.CodecFactory) {
|
||||||
|
scheme := runtime.NewScheme()
|
||||||
|
codecFactory := runtimeserializer.NewCodecFactory(scheme)
|
||||||
|
for _, installFn := range installFns {
|
||||||
|
if err := installFn(scheme); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return scheme, codecFactory
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user