@@ -18,42 +18,66 @@ import (
18
18
// and needs to be fixed immediately (as it will break downstreams that depend
19
19
// on us for a "sane default" and do compliance testing -- such as umoci).
20
20
func TestGenerateValid (t * testing.T ) {
21
- bundle , err := ioutil . TempDir ( "" , "TestGenerateValid_bundle" )
22
- if err != nil {
23
- t . Fatal ( err )
21
+ plat := "linux"
22
+ if runtime . GOOS == "windows" {
23
+ plat = "windows"
24
24
}
25
- defer os .RemoveAll (bundle )
26
25
27
- // Create our toy bundle.
28
- rootfsPath := filepath .Join (bundle , "rootfs" )
29
- if err := os .Mkdir (rootfsPath , 0755 ); err != nil {
30
- t .Fatal (err )
31
- }
32
- configPath := filepath .Join (bundle , "config.json" )
33
- g , err := generate .New ("linux" )
34
- if err != nil {
35
- t .Fatal (err )
36
- }
37
- if err := (& g ).SaveToFile (configPath , generate.ExportOptions {Seccomp : false }); err != nil {
38
- t .Fatal (err )
39
- }
26
+ isolations := []string {"process" , "hyperv" }
27
+ for _ , isolation := range isolations {
28
+ if plat == "linux" && isolation == "hyperv" {
29
+ // Combination doesn't make sense.
30
+ continue
31
+ }
40
32
41
- // Validate the bundle.
42
- v , err := validate .NewValidatorFromPath (bundle , true , runtime .GOOS )
43
- if err != nil {
44
- t .Errorf ("unexpected NewValidatorFromPath error: %+v" , err )
45
- }
46
- if err := v .CheckAll (); err != nil {
47
- levelErrors , err := specerror .SplitLevel (err , rfc2119 .Must )
33
+ bundle , err := ioutil .TempDir ("" , "TestGenerateValid_bundle" )
34
+ if err != nil {
35
+ t .Fatal (err )
36
+ }
37
+ defer os .RemoveAll (bundle )
38
+
39
+ // Create our toy bundle.
40
+ rootfsPath := filepath .Join (bundle , "rootfs" )
41
+ if err := os .Mkdir (rootfsPath , 0755 ); err != nil {
42
+ t .Fatal (err )
43
+ }
44
+ configPath := filepath .Join (bundle , "config.json" )
45
+ g , err := generate .New (plat )
48
46
if err != nil {
49
- t .Errorf ("unexpected non-multierror: %+v" , err )
50
- return
47
+ t .Fatal (err )
48
+ }
49
+ if runtime .GOOS == "windows" {
50
+ g .AddWindowsLayerFolders ("C:\\ fakelayer" )
51
+ g .AddWindowsLayerFolders ("C:\\ fakescratch" )
52
+ if isolation == "process" {
53
+ // Add the Rootfs section (note: fake volume guid)
54
+ g .SetRootPath ("\\ \\ ?\\ Volume{ec84d99e-3f02-11e7-ac6c-00155d7682cf}\\ " )
55
+ } else {
56
+ // Add the Hyper-V section
57
+ g .SetWindowsHypervUntilityVMPath ("" )
58
+ }
59
+ }
60
+ if err := (& g ).SaveToFile (configPath , generate.ExportOptions {Seccomp : false }); err != nil {
61
+ t .Fatal (err )
51
62
}
52
- for _ , e := range levelErrors .Warnings {
53
- t .Logf ("unexpected warning: %v" , e )
63
+
64
+ // Validate the bundle.
65
+ v , err := validate .NewValidatorFromPath (bundle , true , runtime .GOOS )
66
+ if err != nil {
67
+ t .Errorf ("unexpected NewValidatorFromPath error: %+v" , err )
54
68
}
55
- if err := levelErrors .Error ; err != nil {
56
- t .Errorf ("unexpected MUST error(s): %+v" , err )
69
+ if err := v .CheckAll (); err != nil {
70
+ levelErrors , err := specerror .SplitLevel (err , rfc2119 .Must )
71
+ if err != nil {
72
+ t .Errorf ("unexpected non-multierror: %+v" , err )
73
+ return
74
+ }
75
+ for _ , e := range levelErrors .Warnings {
76
+ t .Logf ("unexpected warning: %v" , e )
77
+ }
78
+ if err := levelErrors .Error ; err != nil {
79
+ t .Errorf ("unexpected MUST error(s): %+v" , err )
80
+ }
57
81
}
58
82
}
59
83
}
0 commit comments