GithubHelp home page GithubHelp logo

diazjf / fakeclient Goto Github PK

View Code? Open in Web Editor NEW
15.0 4.0 1.0 17 KB

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

Home Page: https://sched.co/MPgE

License: Apache License 2.0

Go 100.00%

fakeclient's Introduction

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 ./...

fakeclient's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.