The Phi
Published in

The Phi

Mocking the Kubernetes client in Go for Unit Testing

Yes, we can mimic K8s Client!

Photo by Frank Eiffert on Unsplash
  • contains the clients for groups.
  • is the struct used to implement the Kubernetes interface calledInterface.
  • NewForConfig() is the constructor of the Kubernetes Interface interface that returns the Clientset object.
  • build the clientset
  • load the Client struct
  • define a pod resource object
  • invoke the CreatePod call upon the client object
go test
I0520 00:02:03.789351 23893 pod.go:23] Pod test-pod is succesfully created
PASS
ok github.com/kubernetes-sdk-for-go-101 0.681s

--

--

The publication, ‘The Phi’ is a platform for sharing experience based knowledge in software development, trading, life, business, marketing, etc. Basically, anything that is fundamental to life to achieve inspiration, excellence and success.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store