...
1 package oci
2
3 import (
4 "testing"
5
6 "github.com/Microsoft/hcsshim/pkg/annotations"
7 )
8
9 func Test_GetSandboxTypeAndID_TypeContainer_NoID_Failure(t *testing.T) {
10 a := map[string]string{
11 annotations.KubernetesContainerType: "container",
12 }
13 ct, id, err := GetSandboxTypeAndID(a)
14 if err == nil {
15 t.Fatal("should have failed with error")
16 }
17 if ct != KubernetesContainerTypeNone {
18 t.Fatal("should of returned KubernetesContainerTypeNone")
19 }
20 if id != "" {
21 t.Fatal("should of returned empty id")
22 }
23 }
24
25 func Test_GetSandboxTypeAndID_TypeSandbox_NoID_Failure(t *testing.T) {
26 a := map[string]string{
27 annotations.KubernetesContainerType: "sandbox",
28 }
29 ct, id, err := GetSandboxTypeAndID(a)
30 if err == nil {
31 t.Fatal("should have failed with error")
32 }
33 if ct != KubernetesContainerTypeNone {
34 t.Fatal("should of returned KubernetesContainerTypeNone")
35 }
36 if id != "" {
37 t.Fatal("should of returned empty id")
38 }
39 }
40
41 func Test_GetSandboxTypeAndID_NoType_ValidID_Failure(t *testing.T) {
42 a := map[string]string{
43 annotations.KubernetesSandboxID: t.Name(),
44 }
45 ct, id, err := GetSandboxTypeAndID(a)
46 if err == nil {
47 t.Fatal("should have failed with error")
48 }
49 if ct != KubernetesContainerTypeNone {
50 t.Fatal("should of returned KubernetesContainerTypeNone")
51 }
52 if id != "" {
53 t.Fatal("should of returned empty id")
54 }
55 }
56
57 func Test_GetSandboxTypeAndID_NoAnnotations_Success(t *testing.T) {
58 ct, id, err := GetSandboxTypeAndID(nil)
59 if err != nil {
60 t.Fatalf("should not of failed with error: %v", err)
61 }
62 if ct != KubernetesContainerTypeNone {
63 t.Fatal("should of returned KubernetesContainerTypeNone")
64 }
65 if id != "" {
66 t.Fatal("should of returned empty id")
67 }
68 }
69
70 func Test_GetSandboxTypeAndID_TypeContainer_ValidID_Success(t *testing.T) {
71 a := map[string]string{
72 annotations.KubernetesContainerType: "container",
73 annotations.KubernetesSandboxID: t.Name(),
74 }
75 ct, id, err := GetSandboxTypeAndID(a)
76 if err != nil {
77 t.Fatalf("should not of failed with error: %v", err)
78 }
79 if ct != KubernetesContainerTypeContainer {
80 t.Fatal("should of returned KubernetesContainerTypeContainer")
81 }
82 if id != t.Name() {
83 t.Fatalf("should of returned valid id got: %s", id)
84 }
85 }
86
87 func Test_GetSandboxTypeAndID_TypeSandbox_ValidID_Success(t *testing.T) {
88 a := map[string]string{
89 annotations.KubernetesContainerType: "sandbox",
90 annotations.KubernetesSandboxID: t.Name(),
91 }
92 ct, id, err := GetSandboxTypeAndID(a)
93 if err != nil {
94 t.Fatalf("should not of failed with error: %v", err)
95 }
96 if ct != KubernetesContainerTypeSandbox {
97 t.Fatal("should of returned KubernetesContainerTypeSandbox")
98 }
99 if id != t.Name() {
100 t.Fatalf("should of returned valid id got: %s", id)
101 }
102 }
103
View as plain text