github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/container-utils/oci-annotations/resolver_containerd_test.go (about) 1 // Copyright 2022 The Inspektor Gadget authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package ociannotations 16 17 import "testing" 18 19 func Test_containerdResolver(t *testing.T) { 20 annotations := map[string]string{ 21 containerdPodNameAnnotation: "test-pod-name", 22 containerdPodNamespaceAnnotation: "test-pod-namespace", 23 containerdPodUIDAnnotation: "test-pod-uid", 24 containerdContainerNameAnnotation: "test-container-name", 25 containerdContainerTypeAnnotation: "test-container-type", 26 containerdContainerImageName: "test-container-image-name", 27 } 28 29 resolver := containerdResolver{} 30 assert := func(got string, want string) { 31 if got != want { 32 t.Fatalf("Assertion failed got=%s, want=%s", got, want) 33 } 34 } 35 36 t.Logf("Test resolving annotations for %s", resolver.Runtime()) 37 assert(resolver.PodName(annotations), "test-pod-name") 38 assert(resolver.PodNamespace(annotations), "test-pod-namespace") 39 assert(resolver.PodUID(annotations), "test-pod-uid") 40 assert(resolver.ContainerName(annotations), "test-container-name") 41 assert(resolver.ContainerType(annotations), "test-container-type") 42 assert(resolver.ContainerImageName(annotations), "test-container-image-name") 43 }