50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package kubernetes
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestDeployment(t *testing.T) {
|
|
namespace := "default"
|
|
name := "fx-hello-world"
|
|
image := "metrue/kube-hello"
|
|
selector := map[string]string{
|
|
"app": "fx-app",
|
|
}
|
|
|
|
kubeconfig := os.Getenv("KUBECONFIG")
|
|
if kubeconfig == "" {
|
|
t.Skip("skip test since no KUBECONFIG given in environment variable")
|
|
}
|
|
|
|
k8s, err := Create()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := k8s.GetDeployment(namespace, name); err == nil {
|
|
t.Fatalf("should get not found error")
|
|
}
|
|
|
|
replicas := int32(2)
|
|
deployment, err := k8s.CreateDeployment(namespace, name, image, replicas, selector)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if deployment == nil {
|
|
t.Fatalf("deploymetn should not be %v", nil)
|
|
}
|
|
|
|
if deployment.Name != name {
|
|
t.Fatalf("should get %s but got %s", name, deployment.Name)
|
|
}
|
|
|
|
if *deployment.Spec.Replicas != replicas {
|
|
t.Fatalf("should get %v but got %v", replicas, deployment.Spec.Replicas)
|
|
}
|
|
|
|
if err := k8s.DeleteDeployment(namespace, name); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|