@@ -32,75 +32,79 @@ import (
3232func TestSystemPrune (t * testing.T ) {
3333 nerdtest .Setup ()
3434
35- testGroup := & test.Group {
36- {
37- Description : "volume prune all success" ,
38- // Private because of prune evidently
39- Require : nerdtest .Private ,
40- Setup : func (data test.Data , helpers test.Helpers ) {
41- helpers .Ensure ("network" , "create" , data .Identifier ())
42- helpers .Ensure ("volume" , "create" , data .Identifier ())
43- anonIdentifier := helpers .Capture ("volume" , "create" )
44- helpers .Ensure ("run" , "-v" , fmt .Sprintf ("%s:/volume" , data .Identifier ()),
45- "--net" , data .Identifier (), "--name" , data .Identifier (), testutil .CommonImage )
35+ testCase := & test.Case {
36+ Description : "TestSystemPrune" ,
37+ NoParallel : true ,
38+ SubTests : []* test.Case {
39+ {
40+ Description : "volume prune all success" ,
41+ // Private because of prune evidently
42+ Require : nerdtest .Private ,
43+ Setup : func (data test.Data , helpers test.Helpers ) {
44+ helpers .Ensure ("network" , "create" , data .Identifier ())
45+ helpers .Ensure ("volume" , "create" , data .Identifier ())
46+ anonIdentifier := helpers .Capture ("volume" , "create" )
47+ helpers .Ensure ("run" , "-v" , fmt .Sprintf ("%s:/volume" , data .Identifier ()),
48+ "--net" , data .Identifier (), "--name" , data .Identifier (), testutil .CommonImage )
4649
47- data .Set ("anonIdentifier" , anonIdentifier )
50+ data .Set ("anonIdentifier" , anonIdentifier )
51+ },
52+ Cleanup : func (data test.Data , helpers test.Helpers ) {
53+ helpers .Anyhow ("network" , "rm" , data .Identifier ())
54+ helpers .Anyhow ("volume" , "rm" , data .Identifier ())
55+ helpers .Anyhow ("volume" , "rm" , data .Get ("anonIdentifier" ))
56+ helpers .Anyhow ("rm" , "-f" , data .Identifier ())
57+ },
58+ Command : test .RunCommand ("system" , "prune" , "-f" , "--volumes" , "--all" ),
59+ Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
60+ return & test.Expected {
61+ ExitCode : 0 ,
62+ Output : func (stdout string , info string , t * testing.T ) {
63+ volumes := helpers .Capture ("volume" , "ls" )
64+ networks := helpers .Capture ("network" , "ls" )
65+ images := helpers .Capture ("images" )
66+ containers := helpers .Capture ("ps" , "-a" )
67+ assert .Assert (t , strings .Contains (volumes , data .Identifier ()), volumes )
68+ assert .Assert (t , ! strings .Contains (volumes , data .Get ("anonIdentifier" )), volumes )
69+ assert .Assert (t , ! strings .Contains (containers , data .Identifier ()), containers )
70+ assert .Assert (t , ! strings .Contains (networks , data .Identifier ()), networks )
71+ assert .Assert (t , ! strings .Contains (images , testutil .CommonImage ), images )
72+ },
73+ }
74+ },
4875 },
49- Cleanup : func (data test.Data , helpers test.Helpers ) {
50- helpers .Anyhow ("network" , "rm" , data .Identifier ())
51- helpers .Anyhow ("volume" , "rm" , data .Identifier ())
52- helpers .Anyhow ("volume" , "rm" , data .Get ("anonIdentifier" ))
53- helpers .Anyhow ("rm" , "-f" , data .Identifier ())
54- },
55- Command : test .RunCommand ("system" , "prune" , "-f" , "--volumes" , "--all" ),
56- Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
57- return & test.Expected {
58- ExitCode : 0 ,
59- Output : func (stdout string , info string , t * testing.T ) {
60- volumes := helpers .Capture ("volume" , "ls" )
61- networks := helpers .Capture ("network" , "ls" )
62- images := helpers .Capture ("images" )
63- containers := helpers .Capture ("ps" , "-a" )
64- assert .Assert (t , strings .Contains (volumes , data .Identifier ()), volumes )
65- assert .Assert (t , ! strings .Contains (volumes , data .Get ("anonIdentifier" )), volumes )
66- assert .Assert (t , ! strings .Contains (containers , data .Identifier ()), containers )
67- assert .Assert (t , ! strings .Contains (networks , data .Identifier ()), networks )
68- assert .Assert (t , ! strings .Contains (images , testutil .CommonImage ), images )
69- },
70- }
71- },
72- },
73- {
74- Description : "buildkit" ,
75- // FIXME: using a dedicated namespace does not work with rootful (because of buildkitd)
76- NoParallel : true ,
77- // buildkitd is not available with docker
78- Require : test .Require (nerdtest .Build , test .Not (nerdtest .Docker )),
79- // FIXME: this test will happily say "green" even if the command actually fails to do its duty
80- // if there is nothing in the build cache.
81- // Ensure with setup here that we DO build something first
82- Setup : func (data test.Data , helpers test.Helpers ) {
83- helpers .Ensure ("system" , "prune" , "-f" , "--volumes" , "--all" )
84- },
85- Command : func (data test.Data , helpers test.Helpers ) test.Command {
86- buildctlBinary , err := buildkitutil .BuildctlBinary ()
87- if err != nil {
88- t .Fatal (err )
89- }
76+ {
77+ Description : "buildkit" ,
78+ // FIXME: using a dedicated namespace does not work with rootful (because of buildkitd)
79+ NoParallel : true ,
80+ // buildkitd is not available with docker
81+ Require : test .Require (nerdtest .Build , test .Not (nerdtest .Docker )),
82+ // FIXME: this test will happily say "green" even if the command actually fails to do its duty
83+ // if there is nothing in the build cache.
84+ // Ensure with setup here that we DO build something first
85+ Setup : func (data test.Data , helpers test.Helpers ) {
86+ helpers .Ensure ("system" , "prune" , "-f" , "--volumes" , "--all" )
87+ },
88+ Command : func (data test.Data , helpers test.Helpers ) test.Command {
89+ buildctlBinary , err := buildkitutil .BuildctlBinary ()
90+ if err != nil {
91+ t .Fatal (err )
92+ }
9093
91- host , err := buildkitutil .GetBuildkitHost (testutil .Namespace )
92- if err != nil {
93- t .Fatal (err )
94- }
94+ host , err := buildkitutil .GetBuildkitHost (testutil .Namespace )
95+ if err != nil {
96+ t .Fatal (err )
97+ }
9598
96- buildctlArgs := buildkitutil .BuildctlBaseArgs (host )
97- buildctlArgs = append (buildctlArgs , "du" )
99+ buildctlArgs := buildkitutil .BuildctlBaseArgs (host )
100+ buildctlArgs = append (buildctlArgs , "du" )
98101
99- return helpers .CustomCommand (buildctlBinary , buildctlArgs ... )
102+ return helpers .CustomCommand (buildctlBinary , buildctlArgs ... )
103+ },
104+ Expected : test .Expects (0 , nil , test .Contains ("Total:\t \t 0B" )),
100105 },
101- Expected : test .Expects (0 , nil , test .Contains ("Total:\t \t 0B" )),
102106 },
103107 }
104108
105- testGroup .Run (t )
109+ testCase .Run (t )
106110}
0 commit comments