@@ -3,59 +3,24 @@ package image
33import  (
44	"bufio" 
55	"bytes" 
6- 	"fmt" 
76	"testing" 
87	"time" 
98
10- 	"github.com/docker/app/internal/relocated" 
11- 
12- 	"gotest.tools/assert" 
9+ 	"github.com/docker/app/internal/store" 
10+ 	"gotest.tools/fs" 
1311
1412	"github.com/deislabs/cnab-go/bundle" 
15- 	"github.com/docker/app/internal/store " 
13+ 	"github.com/docker/app/internal/relocated " 
1614	"github.com/docker/cli/cli/command" 
1715	"github.com/docker/distribution/reference" 
16+ 	"gotest.tools/assert" 
1817)
1918
20- type  bundleStoreStubForListCmd  struct  {
21- 	refMap  map [reference.Reference ]* relocated.Bundle 
22- 	// in order to keep the reference in the same order between tests 
23- 	refList  []reference.Reference 
24- }
25- 
26- func  (b  * bundleStoreStubForListCmd ) Store (ref  reference.Reference , bndl  * relocated.Bundle ) (reference.Digested , error ) {
27- 	b .refMap [ref ] =  bndl 
28- 	b .refList  =  append (b .refList , ref )
29- 	return  store .FromBundle (bndl )
30- }
31- 
32- func  (b  * bundleStoreStubForListCmd ) Read (ref  reference.Reference ) (* relocated.Bundle , error ) {
33- 	bndl , ok  :=  b .refMap [ref ]
34- 	if  ok  {
35- 		return  bndl , nil 
36- 	}
37- 	return  nil , fmt .Errorf ("Bundle not found" )
38- }
39- 
40- func  (b  * bundleStoreStubForListCmd ) List () ([]reference.Reference , error ) {
41- 	return  b .refList , nil 
42- }
43- 
44- func  (b  * bundleStoreStubForListCmd ) Remove (ref  reference.Reference , force  bool ) error  {
45- 	return  nil 
46- }
47- 
48- func  (b  * bundleStoreStubForListCmd ) LookUp (refOrID  string ) (reference.Reference , error ) {
49- 	return  nil , nil 
50- }
51- 
5219func  TestListCmd (t  * testing.T ) {
53- 	ref , err  :=  store .FromString ("a855ac937f2ed375ba4396bbc49c4093e124da933acd2713fb9bc17d7562a087" )
54- 	assert .NilError (t , err )
55- 	refs  :=  []reference.Reference {
20+ 	refs  :=  []reference.Named {
5621		parseReference (t , "foo/bar@sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865" ),
5722		parseReference (t , "foo/bar:1.0" ),
58- 		ref ,
23+ 		nil ,
5924	}
6025	bundles  :=  []relocated.Bundle {
6126		{
@@ -85,36 +50,36 @@ func TestListCmd(t *testing.T) {
8550		{
8651			name : "TestList" ,
8752			expectedOutput : `REPOSITORY          TAG                 APP IMAGE ID        APP NAME            CREATED              
88- foo/bar              <none>              3f825b2d0657         Digested  App        N/A                 
53+ <none>                <none>              ad2828ea5653         Quiet  App            N/A                 
8954foo/bar             1.0                 9aae408ee04f        Foo App             N/A                  
90- <none>                <none>              a855ac937f2e         Quiet  App            N/A                 
55+ foo/bar              <none>              3f825b2d0657         Digested  App        N/A                 
9156` ,
9257			options : imageListOption {format : "table" },
9358		},
9459		{
9560			name : "TestTemplate" ,
9661			expectedOutput : `APP IMAGE ID        DIGEST 
97- 3f825b2d0657         sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865 
62+ ad2828ea5653         <none> 
98639aae408ee04f        <none> 
99- a855ac937f2e         sha256:a855ac937f2ed375ba4396bbc49c4093e124da933acd2713fb9bc17d7562a087 
64+ 3f825b2d0657         sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865 
10065` ,
10166			options : imageListOption {format : "table {{.ID}}" , digests : true },
10267		},
10368		{
10469			name : "TestListWithDigests" ,
10570			//nolint:lll 
10671			expectedOutput : `REPOSITORY          TAG                 DIGEST                                                                    APP IMAGE ID        APP NAME                                CREATED              
107- foo/bar              <none>              sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865    3f825b2d0657         Digested  App                            N/A                 
72+ <none>                <none>              <none>                                                                     ad2828ea5653        Quiet  App                                N/A                 
10873foo/bar             1.0                 <none>                                                                    9aae408ee04f        Foo App                                 N/A                  
109- <none>                <none>              sha256:a855ac937f2ed375ba4396bbc49c4093e124da933acd2713fb9bc17d7562a087    a855ac937f2e         Quiet  App                                N/A                 
74+ foo/bar              <none>              sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865    3f825b2d0657         Digested  App                            N/A                 
11075` ,
11176			options : imageListOption {format : "table" , digests : true },
11277		},
11378		{
11479			name : "TestListWithQuiet" ,
115- 			expectedOutput : `3f825b2d0657  
80+ 			expectedOutput : `ad2828ea5653  
116819aae408ee04f 
117- a855ac937f2e 
82+ 3f825b2d0657 
11883` ,
11984			options : imageListOption {format : "table" , quiet : true },
12085		},
@@ -143,27 +108,26 @@ func TestSortImages(t *testing.T) {
143108	assert .Equal (t , "3" , images [4 ].ID )
144109}
145110
146- func  parseReference (t  * testing.T , s  string ) reference.Reference  {
147- 	ref , err  :=  reference .Parse (s )
111+ func  parseReference (t  * testing.T , s  string ) reference.Named  {
112+ 	ref , err  :=  reference .ParseNormalizedNamed (s )
148113	assert .NilError (t , err )
149114	return  ref 
150115}
151116
152- func  testRunList (t  * testing.T , refs  []reference.Reference , bundles  []relocated.Bundle , options  imageListOption , expectedOutput  string ) {
117+ func  testRunList (t  * testing.T , refs  []reference.Named , bundles  []relocated.Bundle , options  imageListOption , expectedOutput  string ) {
153118	var  buf  bytes.Buffer 
154119	w  :=  bufio .NewWriter (& buf )
155120	dockerCli , err  :=  command .NewDockerCli (command .WithOutputStream (w ))
156121	assert .NilError (t , err )
157- 	bundleStore  :=  & bundleStoreStubForListCmd {
158- 		refMap :  make (map [reference.Reference ]* relocated.Bundle ),
159- 		refList : []reference.Reference {},
160- 	}
122+ 	bundleStore , err  :=  store .NewBundleStore (fs .NewDir (t , "store" ).Path ())
123+ 	assert .NilError (t , err )
161124	for  i , ref  :=  range  refs  {
162- 		_ , err  =  bundleStore .Store (ref ,  & bundles [i ])
125+ 		_ , err  =  bundleStore .Store (& bundles [i ],  ref )
163126		assert .NilError (t , err )
164127	}
165128	err  =  runList (dockerCli , options , bundleStore )
166129	assert .NilError (t , err )
167130	w .Flush ()
168- 	assert .Equal (t , buf .String (), expectedOutput )
131+ 	actualOutput  :=  buf .String ()
132+ 	assert .Equal (t , actualOutput , expectedOutput )
169133}
0 commit comments