github.com/kotalco/kotal@v0.3.0/controllers/shared/labels_test.go (about) 1 package shared 2 3 import ( 4 "testing" 5 6 ethereumv1alpha1 "github.com/kotalco/kotal/apis/ethereum/v1alpha1" 7 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 8 "k8s.io/client-go/kubernetes/scheme" 9 ) 10 11 func TestUpdateLabels(t *testing.T) { 12 13 if err := ethereumv1alpha1.AddToScheme(scheme.Scheme); err != nil { 14 t.Error(err) 15 } 16 17 ethereumNode := ethereumv1alpha1.Node{ 18 TypeMeta: metav1.TypeMeta{ 19 Kind: "Node", 20 APIVersion: "ethereum/v1alpha1", 21 }, 22 ObjectMeta: metav1.ObjectMeta{ 23 Name: "my-node", 24 Namespace: "default", 25 }, 26 Spec: ethereumv1alpha1.NodeSpec{ 27 Client: ethereumv1alpha1.BesuClient, 28 Network: ethereumv1alpha1.GoerliNetwork, 29 }, 30 } 31 32 UpdateLabels(ðereumNode, string(ethereumNode.Spec.Client), ethereumv1alpha1.GoerliNetwork) 33 34 labels := map[string]string{ 35 "app.kubernetes.io/name": string(ethereumNode.Spec.Client), 36 "app.kubernetes.io/instance": ethereumNode.Name, 37 "app.kubernetes.io/component": "ethereum-node", 38 "app.kubernetes.io/managed-by": "kotal-operator", 39 "app.kubernetes.io/created-by": "ethereum-node-controller", 40 "kotal.io/protocol": "ethereum", 41 "kotal.io/network": ethereumv1alpha1.GoerliNetwork, 42 } 43 44 for k, v := range labels { 45 if ethereumNode.Labels[k] != v { 46 t.Errorf("Expecting label with key %s to have value %s, but got %s", k, v, ethereumNode.Labels[k]) 47 } 48 } 49 50 }