...
1 package oci
2
3 import (
4 "context"
5 "errors"
6 "fmt"
7 "testing"
8
9 "github.com/Microsoft/hcsshim/pkg/annotations"
10 "github.com/opencontainers/runtime-spec/specs-go"
11 "github.com/sirupsen/logrus"
12 )
13
14 func Test_ProccessAnnotations_Expansion(t *testing.T) {
15
16 defer func(l logrus.Level) {
17 logrus.SetLevel(l)
18 }(logrus.GetLevel())
19 logrus.SetLevel(logrus.ErrorLevel)
20 ctx := context.Background()
21
22 tests := []struct {
23 name string
24 spec specs.Spec
25 }{
26 {
27 name: "lcow",
28 spec: specs.Spec{
29 Linux: &specs.Linux{},
30 },
31 },
32 {
33 name: "wcow-hypervisor",
34 spec: specs.Spec{
35 Windows: &specs.Windows{
36 HyperV: &specs.WindowsHyperV{},
37 },
38 },
39 },
40 {
41 name: "wcow-process",
42 spec: specs.Spec{
43 Windows: &specs.Windows{},
44 },
45 },
46 }
47
48 for _, tt := range tests {
49
50 for _, v := range []string{"true", "false"} {
51 t.Run(tt.name+"_disable_unsafe_"+v, func(subtest *testing.T) {
52 tt.spec.Annotations = map[string]string{
53 annotations.DisableUnsafeOperations: v,
54 }
55
56 err := ProcessAnnotations(ctx, &tt.spec)
57 if err != nil {
58 subtest.Fatalf("could not update spec from options: %v", err)
59 }
60
61 for _, k := range annotations.AnnotationExpansions[annotations.DisableUnsafeOperations] {
62 if vv := tt.spec.Annotations[k]; vv != v {
63 subtest.Fatalf("annotation %q was incorrectly expanded to %q, expected %q", k, vv, v)
64 }
65 }
66 })
67 }
68
69
70 t.Run(tt.name+"_disable_unsafe_error", func(subtest *testing.T) {
71 tt.spec.Annotations = map[string]string{
72 annotations.DisableUnsafeOperations: "true",
73 annotations.DisableWritableFileShares: "false",
74 }
75
76 errExp := fmt.Sprintf("could not expand %q into %q",
77 annotations.DisableUnsafeOperations,
78 annotations.DisableWritableFileShares)
79
80 err := ProcessAnnotations(ctx, &tt.spec)
81 if !errors.Is(err, ErrAnnotationExpansionConflict) {
82 t.Fatalf("UpdateSpecFromOptions should have failed with %q, actual was %v", errExp, err)
83 }
84 })
85 }
86 }
87
View as plain text