github.com/lalkh/containerd@v1.4.3/oci/spec_opts_windows_test.go (about) 1 // +build windows 2 3 /* 4 Copyright The containerd Authors. 5 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17 */ 18 19 package oci 20 21 import ( 22 "context" 23 "testing" 24 25 "github.com/containerd/containerd/containers" 26 "github.com/containerd/containerd/namespaces" 27 ) 28 29 func TestWithCPUCount(t *testing.T) { 30 var ( 31 ctx = namespaces.WithNamespace(context.Background(), "testing") 32 c = containers.Container{ID: t.Name()} 33 cpu = uint64(8) 34 o = WithWindowsCPUCount(cpu) 35 ) 36 // Test with all three supported scenarios 37 platforms := []string{"", "linux/amd64", "windows/amd64"} 38 for _, p := range platforms { 39 var spec *Spec 40 var err error 41 if p == "" { 42 t.Log("Testing GenerateSpec default platform") 43 spec, err = GenerateSpec(ctx, nil, &c, o) 44 } else { 45 t.Logf("Testing GenerateSpecWithPlatform with platform: '%s'", p) 46 spec, err = GenerateSpecWithPlatform(ctx, nil, p, &c, o) 47 } 48 if err != nil { 49 t.Fatalf("failed to generate spec with: %v", err) 50 } 51 if *spec.Windows.Resources.CPU.Count != cpu { 52 t.Fatalf("spec.Windows.Resources.CPU.Count expected: %v, got: %v", cpu, *spec.Windows.Resources.CPU.Count) 53 } 54 if spec.Linux != nil && spec.Linux.Resources != nil && spec.Linux.Resources.CPU != nil { 55 t.Fatalf("spec.Linux.Resources.CPU section should not be set on GOOS=windows") 56 } 57 } 58 } 59 60 func TestWithWindowsIgnoreFlushesDuringBoot(t *testing.T) { 61 var ( 62 ctx = namespaces.WithNamespace(context.Background(), "testing") 63 c = containers.Container{ID: t.Name()} 64 o = WithWindowsIgnoreFlushesDuringBoot() 65 ) 66 // Test with all supported scenarios 67 platforms := []string{"", "windows/amd64"} 68 for _, p := range platforms { 69 var spec *Spec 70 var err error 71 if p == "" { 72 t.Log("Testing GenerateSpec default platform") 73 spec, err = GenerateSpec(ctx, nil, &c, o) 74 } else { 75 t.Logf("Testing GenerateSpecWithPlatform with platform: '%s'", p) 76 spec, err = GenerateSpecWithPlatform(ctx, nil, p, &c, o) 77 } 78 if err != nil { 79 t.Fatalf("failed to generate spec with: %v", err) 80 } 81 if spec.Windows.IgnoreFlushesDuringBoot != true { 82 t.Fatalf("spec.Windows.IgnoreFlushesDuringBoot expected: true") 83 } 84 } 85 } 86 87 func TestWithWindowNetworksAllowUnqualifiedDNSQuery(t *testing.T) { 88 var ( 89 ctx = namespaces.WithNamespace(context.Background(), "testing") 90 c = containers.Container{ID: t.Name()} 91 o = WithWindowNetworksAllowUnqualifiedDNSQuery() 92 ) 93 // Test with all supported scenarios 94 platforms := []string{"", "windows/amd64"} 95 for _, p := range platforms { 96 var spec *Spec 97 var err error 98 if p == "" { 99 t.Log("Testing GenerateSpec default platform") 100 spec, err = GenerateSpec(ctx, nil, &c, o) 101 } else { 102 t.Logf("Testing GenerateSpecWithPlatform with platform: '%s'", p) 103 spec, err = GenerateSpecWithPlatform(ctx, nil, p, &c, o) 104 } 105 if err != nil { 106 t.Fatalf("failed to generate spec with: %v", err) 107 } 108 if spec.Windows.Network.AllowUnqualifiedDNSQuery != true { 109 t.Fatalf("spec.Windows.Network.AllowUnqualifiedDNSQuery expected: true") 110 } 111 } 112 }