github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/kube/name_test.go (about) 1 // +build unit 2 3 package kube_test 4 5 import ( 6 "testing" 7 8 "github.com/olli-ai/jx/v2/pkg/kube" 9 "github.com/stretchr/testify/assert" 10 corev1 "k8s.io/api/core/v1" 11 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 12 ) 13 14 func TestGetName(t *testing.T) { 15 t.Parallel() 16 r := &metav1.ObjectMeta{ 17 Name: "default-staging-my-spring-boot-demo2-my-spring-boot-demo2-fxfgz", 18 Namespace: "default-staging", 19 Labels: map[string]string{ 20 "app": "default-staging-my-spring-boot-demo2-my-spring-boot-demo2", 21 }, 22 } 23 assert.Equal(t, "my-spring-boot-demo2", kube.GetName(r), "Get name on first pod") 24 } 25 26 func TestGetPodVersion(t *testing.T) { 27 t.Parallel() 28 r := &corev1.Pod{ 29 ObjectMeta: metav1.ObjectMeta{ 30 Name: "default-staging-my-spring-boot-demo2-my-spring-boot-demo2-fxfgz", 31 Namespace: "default-staging", 32 Labels: map[string]string{ 33 "app": "default-staging-my-spring-boot-demo2-my-spring-boot-demo2", 34 }, 35 }, 36 Spec: corev1.PodSpec{ 37 Containers: []corev1.Container{ 38 { 39 Image: "randomthing", 40 }, 41 { 42 Image: "foo/my-spring-boot-demo2:1.2.3", 43 }, 44 }, 45 }, 46 } 47 assert.Equal(t, "1.2.3", kube.GetPodVersion(r, ""), "Get version of the pod") 48 }