Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jensneuse/kube-utils
This repository offers utility functions for easy integrating go applications in kubernetes
https://github.com/jensneuse/kube-utils
go golang integration integration-test integration-testing integration-tests integration-tool kubernetes kubernetes-deployment
Last synced: about 1 month ago
JSON representation
This repository offers utility functions for easy integrating go applications in kubernetes
- Host: GitHub
- URL: https://github.com/jensneuse/kube-utils
- Owner: jensneuse
- License: mit
- Created: 2018-05-03T08:39:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-07T05:09:33.000Z (over 6 years ago)
- Last Synced: 2024-11-23T00:42:03.476Z (about 2 months ago)
- Topics: go, golang, integration, integration-test, integration-testing, integration-tests, integration-tool, kubernetes, kubernetes-deployment
- Language: Go
- Homepage:
- Size: 5.22 MB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kube-utils
This repository offers utility functions for easy integrating go applications in kubernetesWorks 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:
```go
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:
````go
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
````bash
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.