@@ -3,59 +3,24 @@ package image
3
3
import (
4
4
"bufio"
5
5
"bytes"
6
- "fmt"
7
6
"testing"
8
7
"time"
9
8
10
- "github.com/docker/app/internal/relocated"
11
-
12
- "gotest.tools/assert"
9
+ "github.com/docker/app/internal/store"
10
+ "gotest.tools/fs"
13
11
14
12
"github.com/deislabs/cnab-go/bundle"
15
- "github.com/docker/app/internal/store "
13
+ "github.com/docker/app/internal/relocated "
16
14
"github.com/docker/cli/cli/command"
17
15
"github.com/docker/distribution/reference"
16
+ "gotest.tools/assert"
18
17
)
19
18
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
-
52
19
func TestListCmd (t * testing.T ) {
53
- ref , err := store .FromString ("a855ac937f2ed375ba4396bbc49c4093e124da933acd2713fb9bc17d7562a087" )
54
- assert .NilError (t , err )
55
- refs := []reference.Reference {
20
+ refs := []reference.Named {
56
21
parseReference (t , "foo/bar@sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865" ),
57
22
parseReference (t , "foo/bar:1.0" ),
58
- ref ,
23
+ nil ,
59
24
}
60
25
bundles := []relocated.Bundle {
61
26
{
@@ -85,36 +50,36 @@ func TestListCmd(t *testing.T) {
85
50
{
86
51
name : "TestList" ,
87
52
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
89
54
foo/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
91
56
` ,
92
57
options : imageListOption {format : "table" },
93
58
},
94
59
{
95
60
name : "TestTemplate" ,
96
61
expectedOutput : `APP IMAGE ID DIGEST
97
- 3f825b2d0657 sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865
62
+ ad2828ea5653 <none>
98
63
9aae408ee04f <none>
99
- a855ac937f2e sha256:a855ac937f2ed375ba4396bbc49c4093e124da933acd2713fb9bc17d7562a087
64
+ 3f825b2d0657 sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865
100
65
` ,
101
66
options : imageListOption {format : "table {{.ID}}" , digests : true },
102
67
},
103
68
{
104
69
name : "TestListWithDigests" ,
105
70
//nolint:lll
106
71
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
108
73
foo/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
110
75
` ,
111
76
options : imageListOption {format : "table" , digests : true },
112
77
},
113
78
{
114
79
name : "TestListWithQuiet" ,
115
- expectedOutput : `3f825b2d0657
80
+ expectedOutput : `ad2828ea5653
116
81
9aae408ee04f
117
- a855ac937f2e
82
+ 3f825b2d0657
118
83
` ,
119
84
options : imageListOption {format : "table" , quiet : true },
120
85
},
@@ -143,27 +108,26 @@ func TestSortImages(t *testing.T) {
143
108
assert .Equal (t , "3" , images [4 ].ID )
144
109
}
145
110
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 )
148
113
assert .NilError (t , err )
149
114
return ref
150
115
}
151
116
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 ) {
153
118
var buf bytes.Buffer
154
119
w := bufio .NewWriter (& buf )
155
120
dockerCli , err := command .NewDockerCli (command .WithOutputStream (w ))
156
121
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 )
161
124
for i , ref := range refs {
162
- _ , err = bundleStore .Store (ref , & bundles [i ])
125
+ _ , err = bundleStore .Store (& bundles [i ], ref )
163
126
assert .NilError (t , err )
164
127
}
165
128
err = runList (dockerCli , options , bundleStore )
166
129
assert .NilError (t , err )
167
130
w .Flush ()
168
- assert .Equal (t , buf .String (), expectedOutput )
131
+ actualOutput := buf .String ()
132
+ assert .Equal (t , actualOutput , expectedOutput )
169
133
}
0 commit comments