Skip to content

Fake it Until You Make it: Unit Tests with Go-Client Fake Client

License

Notifications You must be signed in to change notification settings

diazjf/fakeclient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubernetes FakeClient Example

This repository houses an example of how to use Go-Client, and more specifically, how to write unit-tests for functions which use the Kubernetes Go-Client.

This repository is meant to go along with the Fake it Until You Make it: Unit Tests with Go-Client Fake Client Presentation for KubeCon Europe 2019.

You can also follow along with the recorded session on youtube.

Pre-Requisites

In order to run this application, you must first install a couple of dependancies.

You can install dep and the just run the following command:

dep ensure

Note: These dependancies were generated for Kubernetes version 1.14. The code may only work with that Kubernetes version.

Setting Up Minikube and Secrets

You can install minikube and then run:

minikube start

This will generate a config in $HOME/.kube/config.

Now we can generate a few secrets to test it out:

kubectl create secret generic my-login-information --from-literal=username=us3r1 --from-literal=password=p4ssw0rd2

kubectl create secret generic my-api-key --from-literal=apikey=ABCDEFGHIJKLMNOP

Usage

Once the dependancies have been installed, and minikube has been setup, you can simply run:

go run internal/main.go

If you want to use another Kubernetes Cluster, then you can pass the -kubeconfig flag:

go run internal/main.go -kubeconfig <path-to-kubeconfig>

This will output something similar to the following:

....

my-api-key
{
  "apikey": "ABCDEFGHIJKLMNOP"
}

my-login-information
{
  "password": "p4ssw0rd1",
  "username": "admin"
}

Note: You may need additional setup depending on your cloud provider. For example extra authentication to the clusters.

Unit Tests

You can run the Unit-Tests by running:

go test ./...

About

Fake it Until You Make it: Unit Tests with Go-Client Fake Client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages