@@ -169,3 +169,70 @@ func TestProviderURLParseNoConfig(t *testing.T) {
169169 })
170170 }
171171}
172+
173+ func TestValidPackageSuffix (t * testing.T ) {
174+ type args struct {
175+ packageURL string
176+ }
177+ tests := []struct {
178+ name string
179+ args args
180+ want bool
181+ }{
182+ {
183+ name : "empty version, repo as default name" ,
184+ args : args {
185+ "https://github.com/orgtest/repotest/releases/latest/download/repotest-%s-%s.%s" ,
186+ },
187+ want : true ,
188+ },
189+ {
190+ name : "empty version, repo as default name" ,
191+ args : args {
192+ "https://github.com/orgtest/repotest/releases/latest/download/hello-%s-%s.%s" ,
193+ },
194+ want : true ,
195+ },
196+ {
197+ name : "semver version, specific app name" ,
198+ args : args {
199+ "https://github.com/orgtest/repotest/releases/download/v1.0/hello-%s-%s.%s" ,
200+ },
201+ want : true ,
202+ },
203+ {
204+ name : "specific version with a slash, specific app name" ,
205+ args : args {
206+ "https://github.com/orgtest/repotest/releases/download/hello/v1.0/hello-%s-%s.%s" ,
207+ },
208+ want : true ,
209+ },
210+ {
211+ name : "url of download without an compress extension" ,
212+ args : args {
213+ "https://github.com/orgtest/repotest/releases/download/hello/v1.0/hello-%s-%s.%s.abcdef" ,
214+ },
215+ want : false ,
216+ },
217+ }
218+
219+ is := & Installer {
220+ Package : & HDConfig {FormatOverrides : PackagingFormat {
221+ Windows : "zip" ,
222+ Linux : "tar.gz" ,
223+ }},
224+ OS : runtime .GOOS ,
225+ Arch : runtime .GOARCH ,
226+ }
227+
228+ for _ , tt := range tests {
229+ t .Run (tt .name , func (t * testing.T ) {
230+ packageURL := fmt .Sprintf (
231+ tt .args .packageURL ,
232+ is .OS , is .Arch , getPackagingFormat (is ))
233+ if got := hasPackageSuffix (packageURL ); got != tt .want {
234+ t .Errorf ("hasPackageSuffix() = %v, want %v" , got , tt .want )
235+ }
236+ })
237+ }
238+ }
0 commit comments