Skip to content

Commit

Permalink
Unit tests for pkg/client
Browse files Browse the repository at this point in the history
  • Loading branch information
bpineau committed Apr 11, 2018
1 parent b361419 commit 49b3e86
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dockers:
- image: bpineau/katafygio
goos: linux
goarch: amd64
dockerfile: Dockerfile.goreleaser
dockerfile: assets/Dockerfile.goreleaser
tag_templates:
- '{{ .Tag }}'
- latest
Expand Down
13 changes: 13 additions & 0 deletions assets/.kube/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
clusters:
- cluster:
server: http://127.0.0.1:8080
name: test-fake-server
contexts:
- context:
cluster: test-fake-server
user: ""
name: test-fake-server
current-context: test-fake-server
kind: Config
preferences: {}
File renamed without changes.
38 changes: 38 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package client

import (
"fmt"
"os"
"testing"
)

const nonExistentPath = "\\/hopefully/non/existent/path"

func TestClientSet(t *testing.T) {
here, _ := os.Getwd()
_ = os.Setenv("HOME", here+"/../../assets")
cs, err := NewClientSet("", "")
if err != nil {
t.Fatal(err)
}
if fmt.Sprintf("%T", cs) != "*kubernetes.Clientset" {
t.Errorf("NewClientSet() didn't return a *kubernetes.Clientset: %T", cs)
}

cs, _ = NewClientSet("http://127.0.0.1", "/dev/null")
if fmt.Sprintf("%T", cs) != "*kubernetes.Clientset" {
t.Errorf("NewClientSet(server) didn't return a *kubernetes.Clientset: %T", cs)
}

_, err = NewClientSet("http://127.0.0.1", nonExistentPath)
if err == nil {
t.Fatal("NewClientSet() should fail on non existent kubeconfig path")
}

_ = os.Unsetenv("KUBERNETES_SERVICE_HOST")
_ = os.Setenv("HOME", nonExistentPath)
_, err = NewClientSet("", "")
if err == nil {
t.Fatal("NewClientSet() should fail to load InClusterConfig without kube address env")
}
}

0 comments on commit 49b3e86

Please sign in to comment.