@@ -166,25 +166,25 @@ func TestWithEnv(t *testing.T) {
166166 Env : []string {"DEFAULT=test" },
167167 }
168168
169- WithEnv ([]string {"env=1" })(nil , nil , nil , & s )
169+ WithEnv ([]string {"env=1" })(context . Background () , nil , nil , & s )
170170
171171 if len (s .Process .Env ) != 2 {
172172 t .Fatal ("didn't append" )
173173 }
174174
175- WithEnv ([]string {"env2=1" })(nil , nil , nil , & s )
175+ WithEnv ([]string {"env2=1" })(context . Background () , nil , nil , & s )
176176
177177 if len (s .Process .Env ) != 3 {
178178 t .Fatal ("didn't append" )
179179 }
180180
181- WithEnv ([]string {"env2=2" })(nil , nil , nil , & s )
181+ WithEnv ([]string {"env2=2" })(context . Background () , nil , nil , & s )
182182
183183 if s .Process .Env [2 ] != "env2=2" {
184184 t .Fatal ("couldn't update" )
185185 }
186186
187- WithEnv ([]string {"env2" })(nil , nil , nil , & s )
187+ WithEnv ([]string {"env2" })(context . Background () , nil , nil , & s )
188188
189189 if len (s .Process .Env ) != 2 {
190190 t .Fatal ("couldn't unset" )
@@ -428,7 +428,7 @@ func TestAddCaps(t *testing.T) {
428428
429429 var s specs.Spec
430430
431- if err := WithAddedCapabilities ([]string {"CAP_CHOWN" })(nil , nil , nil , & s ); err != nil {
431+ if err := WithAddedCapabilities ([]string {"CAP_CHOWN" })(context . Background () , nil , nil , & s ); err != nil {
432432 t .Fatal (err )
433433 }
434434 for i , cl := range [][]string {
@@ -448,10 +448,10 @@ func TestDropCaps(t *testing.T) {
448448
449449 var s specs.Spec
450450
451- if err := WithAllCapabilities (nil , nil , nil , & s ); err != nil {
451+ if err := WithAllCapabilities (context . Background () , nil , nil , & s ); err != nil {
452452 t .Fatal (err )
453453 }
454- if err := WithDroppedCapabilities ([]string {"CAP_CHOWN" })(nil , nil , nil , & s ); err != nil {
454+ if err := WithDroppedCapabilities ([]string {"CAP_CHOWN" })(context . Background () , nil , nil , & s ); err != nil {
455455 t .Fatal (err )
456456 }
457457
@@ -465,4 +465,44 @@ func TestDropCaps(t *testing.T) {
465465 t .Errorf ("cap list %d contains dropped cap" , i )
466466 }
467467 }
468+
469+ // Add all capabilities back and drop a different cap.
470+ if err := WithAllCapabilities (context .Background (), nil , nil , & s ); err != nil {
471+ t .Fatal (err )
472+ }
473+ if err := WithDroppedCapabilities ([]string {"CAP_FOWNER" })(context .Background (), nil , nil , & s ); err != nil {
474+ t .Fatal (err )
475+ }
476+
477+ for i , cl := range [][]string {
478+ s .Process .Capabilities .Bounding ,
479+ s .Process .Capabilities .Effective ,
480+ s .Process .Capabilities .Permitted ,
481+ s .Process .Capabilities .Inheritable ,
482+ } {
483+ if capsContain (cl , "CAP_FOWNER" ) {
484+ t .Errorf ("cap list %d contains dropped cap" , i )
485+ }
486+ if ! capsContain (cl , "CAP_CHOWN" ) {
487+ t .Errorf ("cap list %d doesn't contain non-dropped cap" , i )
488+ }
489+ }
490+
491+ // Drop all duplicated caps.
492+ if err := WithCapabilities ([]string {"CAP_CHOWN" , "CAP_CHOWN" })(context .Background (), nil , nil , & s ); err != nil {
493+ t .Fatal (err )
494+ }
495+ if err := WithDroppedCapabilities ([]string {"CAP_CHOWN" })(context .Background (), nil , nil , & s ); err != nil {
496+ t .Fatal (err )
497+ }
498+ for i , cl := range [][]string {
499+ s .Process .Capabilities .Bounding ,
500+ s .Process .Capabilities .Effective ,
501+ s .Process .Capabilities .Permitted ,
502+ s .Process .Capabilities .Inheritable ,
503+ } {
504+ if len (cl ) != 0 {
505+ t .Errorf ("cap list %d is not empty" , i )
506+ }
507+ }
468508}
0 commit comments