2222 runtimeCommand = "runc"
2323)
2424
25+ // build test environment before running container
26+ type preFunc func (string ) error
27+
2528func init () {
2629 runtimeInEnv := os .Getenv ("RUNTIME" )
2730 if runtimeInEnv != "" {
@@ -54,11 +57,18 @@ func getDefaultGenerator() *generate.Generator {
5457 return & g
5558}
5659
57- func runtimeInsideValidate (g * generate.Generator ) error {
60+ func runtimeInsideValidate (g * generate.Generator , f preFunc ) error {
5861 bundleDir , err := prepareBundle ()
5962 if err != nil {
6063 return err
6164 }
65+
66+ if f != nil {
67+ if err := f (bundleDir ); err != nil {
68+ return err
69+ }
70+ }
71+
6272 r , err := NewRuntime (runtimeCommand , bundleDir )
6373 if err != nil {
6474 os .RemoveAll (bundleDir )
@@ -85,15 +95,15 @@ func runtimeInsideValidate(g *generate.Generator) error {
8595func TestValidateBasic (t * testing.T ) {
8696 g := getDefaultGenerator ()
8797
88- assert .Nil (t , runtimeInsideValidate (g ))
98+ assert .Nil (t , runtimeInsideValidate (g , nil ))
8999}
90100
91101// Test whether rootfs Readonly can be applied as false
92102func TestValidateRootFSReadWrite (t * testing.T ) {
93103 g := getDefaultGenerator ()
94104 g .SetRootReadonly (false )
95105
96- assert .Nil (t , runtimeInsideValidate (g ))
106+ assert .Nil (t , runtimeInsideValidate (g , nil ))
97107}
98108
99109// Test whether rootfs Readonly can be applied as true
@@ -105,15 +115,15 @@ func TestValidateRootFSReadonly(t *testing.T) {
105115 g := getDefaultGenerator ()
106116 g .SetRootReadonly (true )
107117
108- assert .Nil (t , runtimeInsideValidate (g ))
118+ assert .Nil (t , runtimeInsideValidate (g , nil ))
109119}
110120
111121// Test whether hostname can be applied or not
112122func TestValidateHostname (t * testing.T ) {
113123 g := getDefaultGenerator ()
114124 g .SetHostname ("hostname-specific" )
115125
116- assert .Nil (t , runtimeInsideValidate (g ))
126+ assert .Nil (t , runtimeInsideValidate (g , nil ))
117127}
118128
119129func TestValidateRootfsPropagationPrivate (t * testing.T ) {
@@ -129,15 +139,15 @@ func TestValidateRootfsPropagationShared(t *testing.T) {
129139 g .SetupPrivileged (true )
130140 g .SetLinuxRootPropagation ("shared" )
131141
132- assert .Nil (t , runtimeInsideValidate (g ))
142+ assert .Nil (t , runtimeInsideValidate (g , nil ))
133143}
134144
135145func TestValidateRootfsPropagationUnbindable (t * testing.T ) {
136146 g := getDefaultGenerator ()
137147 g .SetupPrivileged (true )
138148 g .SetLinuxRootPropagation ("unbindable" )
139149
140- assert .Nil (t , runtimeInsideValidate (g ))
150+ assert .Nil (t , runtimeInsideValidate (g , nil ))
141151}
142152
143153// Test whether mounts are correctly mounted
@@ -151,15 +161,15 @@ func TestValidateRlimits(t *testing.T) {
151161 g := getDefaultGenerator ()
152162 g .AddProcessRlimits ("RLIMIT_NOFILE" , 1024 , 1024 )
153163
154- assert .Nil (t , runtimeInsideValidate (g ))
164+ assert .Nil (t , runtimeInsideValidate (g , nil ))
155165}
156166
157167// Test whether sysctls can be applied or not
158168func TestValidateSysctls (t * testing.T ) {
159169 g := getDefaultGenerator ()
160170 g .AddLinuxSysctl ("net.ipv4.ip_forward" , "1" )
161171
162- assert .Nil (t , runtimeInsideValidate (g ))
172+ assert .Nil (t , runtimeInsideValidate (g , nil ))
163173}
164174
165175// Test Create operation
0 commit comments