Git Product home page Git Product logo

kube-utils's Introduction

kube-utils

This repository offers utility functions for easy integrating go applications in kubernetes

Works for both client side and in-cluster testing.

Lets say you'd like to spin up your test environment, run integration tests and cleanup everything, this is all you have to do:

func TestMinioTemplate(t *testing.T) {

	g := Goblin(t)
	RegisterFailHandler(func(m string, _ ...int) { g.Fail(m) })

	podName := "minio-simple-test"
	endpoint := "localhost:9000"
	accessKey := "AKIAIOSFODNN7EXAMPLE"
	secretKey := "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"

	l := New()

	g.Describe("minio", func() {

		g.After(func() {
			// tear down
			l.Cleanup()
		})

		g.It("should be ready to connect", func() {

			// request whatever we need
			l.CreateAndForwardMinio(config.NAMESPACE, podName, accessKey, secretKey)

			minioClient, err := minio.New(endpoint, accessKey, secretKey, false)
			if err != nil {
				t.Fatal(err)
			}

			_, err = minioClient.ListBuckets()
			if err != nil {
				t.Fatal(err)
			}
		})
	})
}

Your environment might be a bit more complex. Working with multiple pods is as easy as:

func TestCreateAndForwardPods(t *testing.T) {
	g := Goblin(t)
	RegisterFailHandler(func(m string, _ ...int) { g.Fail(m) })

	g.Describe("CreateAndForwardPods", func() {

		l := New()

		g.After(func() {
			l.Cleanup()
		})

		minioPodName := "minio-multitest"
		endpoint := "localhost:9000"
		accessKey := "AKIAIOSFODNN7EXAMPLE"
		secretKey := "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"

		postgresPodName := "postgres-multitest"
		dsn := "postgresql://postgres@localhost:15432/postgres?sslmode=disable"

		g.It("should provide minio + postgres", func() {
			l.CreateAndForwardPods(config.NAMESPACE,
				podtemplates.Minio(minioPodName, accessKey, secretKey),
				podtemplates.Postgresql(postgresPodName),
			)

			minioClient, err := minio.New(endpoint, accessKey, secretKey, false)
			if err != nil {
				t.Fatal(err)
			}

			_, err = minioClient.ListBuckets()
			if err != nil {
				t.Fatal(err)
			}

			db, err := sql.Open("postgres", dsn)
			if err != nil {
				t.Fatal(err)
			}

			defer db.Close()

			Expect(db.Ping()).To(BeNil())
		})
	})
}

Running tests

go test ./pkg/... -namespace=default

Contributions

Feel free to submit additions (e.g. more pod templates) via pull requests. Don't forget to add tests.

kube-utils's People

Contributors

jensneuse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

alexanderj1988

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.