@@ -10,6 +10,7 @@ import (
10
10
"github.com/stretchr/testify/require"
11
11
12
12
"github.com/coder/code-marketplace/cli"
13
+ "github.com/coder/code-marketplace/storage"
13
14
"github.com/coder/code-marketplace/testutil"
14
15
)
15
16
@@ -36,8 +37,11 @@ func TestRemove(t *testing.T) {
36
37
all bool
37
38
// error is the expected error.
38
39
error string
39
- // extension is the extension to remove. testutil.Extensions[0] will be
40
- // added with versions a, b, and c before each test.
40
+ // expected contains the versions should have been deleted. It is ignored
41
+ // in the case of an expected error.
42
+ expected []storage.Version
43
+ // extension is the extension to remove. Every version of
44
+ // testutil.Extensions[0] will be added before each test.
41
45
extension testutil.Extension
42
46
// name is the name of the test.
43
47
name string
@@ -47,12 +51,41 @@ func TestRemove(t *testing.T) {
47
51
{
48
52
name : "RemoveOne" ,
49
53
extension : testutil .Extensions [0 ],
54
+ version : "2.0.0" ,
55
+ expected : []storage.Version {
56
+ {Version : "2.0.0" },
57
+ },
58
+ },
59
+ {
60
+ name : "RemovePlatforms" ,
61
+ extension : testutil .Extensions [0 ],
50
62
version : testutil .Extensions [0 ].LatestVersion ,
63
+ expected : []storage.Version {
64
+ {Version : "3.0.0" },
65
+ {Version : "3.0.0" , TargetPlatform : storage .PlatformAlpineX64 },
66
+ {Version : "3.0.0" , TargetPlatform : storage .PlatformDarwinX64 },
67
+ {Version : "3.0.0" , TargetPlatform : storage .PlatformLinuxArm64 },
68
+ {Version : "3.0.0" , TargetPlatform : storage .PlatformLinuxX64 },
69
+ {Version : "3.0.0" , TargetPlatform : storage .PlatformWin32X64 },
70
+ },
51
71
},
52
72
{
53
73
name : "All" ,
54
74
extension : testutil .Extensions [0 ],
55
75
all : true ,
76
+ expected : []storage.Version {
77
+ {Version : "1.0.0" },
78
+ {Version : "1.0.0" , TargetPlatform : storage .PlatformWin32X64 },
79
+ {Version : "1.5.2" },
80
+ {Version : "2.0.0" },
81
+ {Version : "2.2.2" },
82
+ {Version : "3.0.0" },
83
+ {Version : "3.0.0" , TargetPlatform : storage .PlatformAlpineX64 },
84
+ {Version : "3.0.0" , TargetPlatform : storage .PlatformDarwinX64 },
85
+ {Version : "3.0.0" , TargetPlatform : storage .PlatformLinuxArm64 },
86
+ {Version : "3.0.0" , TargetPlatform : storage .PlatformLinuxX64 },
87
+ {Version : "3.0.0" , TargetPlatform : storage .PlatformWin32X64 },
88
+ },
56
89
},
57
90
{
58
91
name : "MissingTarget" ,
@@ -61,7 +94,7 @@ func TestRemove(t *testing.T) {
61
94
},
62
95
{
63
96
name : "MissingTargetNoVersions" ,
64
- error : "has no versions " ,
97
+ error : "target a specific version or pass --all " ,
65
98
extension : testutil .Extensions [1 ],
66
99
},
67
100
{
@@ -85,10 +118,19 @@ func TestRemove(t *testing.T) {
85
118
},
86
119
{
87
120
name : "AllNoVersions" ,
88
- error : "has no versions " ,
121
+ error : "does not exist " ,
89
122
extension : testutil .Extensions [1 ],
90
123
all : true ,
91
124
},
125
+ {
126
+ // Cannot target specific platforms at the moment. If we wanted this
127
+ // we would likely need to use a `--platform` flag since we already use @
128
+ // to delineate the version.
129
+ name : "NoPlatformTarget" ,
130
+ error : "does not exist" ,
131
+ extension : testutil .Extensions [0 ],
132
+ version : "1.0.0@win32-x64" ,
133
+ },
92
134
}
93
135
94
136
for _ , test := range tests {
@@ -99,7 +141,7 @@ func TestRemove(t *testing.T) {
99
141
extdir := t .TempDir ()
100
142
ext := testutil .Extensions [0 ]
101
143
for _ , version := range ext .Versions {
102
- manifestPath := filepath .Join (extdir , ext .Publisher , ext .Name , version , "extension.vsixmanifest" )
144
+ manifestPath := filepath .Join (extdir , ext .Publisher , ext .Name , version . String () , "extension.vsixmanifest" )
103
145
err := os .MkdirAll (filepath .Dir (manifestPath ), 0o755 )
104
146
require .NoError (t , err )
105
147
err = os .WriteFile (manifestPath , testutil .ConvertExtensionToManifestBytes (t , ext , version ), 0o644 )
@@ -128,13 +170,9 @@ func TestRemove(t *testing.T) {
128
170
require .Regexp (t , test .error , err .Error ())
129
171
} else {
130
172
require .NoError (t , err )
131
- if test .all {
132
- require .Contains (t , output , fmt .Sprintf ("Removed %d versions" , len (test .extension .Versions )))
133
- for _ , version := range test .extension .Versions {
134
- require .Contains (t , output , fmt .Sprintf (" - %s" , version ))
135
- }
136
- } else {
137
- require .Contains (t , output , fmt .Sprintf ("Removed %s" , test .version ))
173
+ require .Contains (t , output , fmt .Sprintf ("Removed %d version" , len (test .expected )))
174
+ for _ , version := range test .expected {
175
+ require .Contains (t , output , fmt .Sprintf (" - %s\n " , version ))
138
176
}
139
177
}
140
178
})
0 commit comments