@@ -211,3 +211,83 @@ func testDataURI(t *testing.T, sha256sum string) string {
211211 require .NoError (t , err )
212212 return fmt .Sprintf ("file://%s" , filepath .ToSlash (absPath ))
213213}
214+
215+ func TestGetBundleInfoFromNameValid (t * testing.T ) {
216+ valid := [][]string {
217+ // crc_preset_driver_version_arch_customSuffix.crcbundle
218+ {"crc_libvirt_4.16.7_amd64.crcbundle" , preset .OpenShift .String (), "libvirt" , "4.16.7" , "amd64" , "" },
219+ {"crc_libvirt_4.16.7_amd64_232.crcbundle" , preset .OpenShift .String (), "libvirt" , "4.16.7" , "amd64" , "232" },
220+ {"crc_microshift_libvirt_4.16.7_amd64.crcbundle" , preset .Microshift .String (), "libvirt" , "4.16.7" , "amd64" , "" },
221+ {"crc_microshift_libvirt_4.16.7_amd64_2345.crcbundle" , preset .Microshift .String (), "libvirt" , "4.16.7" , "amd64" , "2345" },
222+ {"crc_okd_vfkit_4.16.7_amd64.crcbundle" , preset .OKD .String (), "vfkit" , "4.16.7" , "amd64" , "" },
223+ {"crc_okd_vfkit_4.16.7_amd64_2342465234654.crcbundle" , preset .OKD .String (), "vfkit" , "4.16.7" , "amd64" , "2342465234654" },
224+ {"crc_hyperv_4.18.0_arm64.crcbundle" , preset .OpenShift .String (), "hyperv" , "4.18.0" , "arm64" , "" },
225+
226+ {"crc_hyperv_4.18_x86.crcbundle" , preset .OpenShift .String (), "hyperv" , "4.18" , "x86" , "" },
227+ {"crc_microshift_hyperv_4.18_x86.crcbundle" , preset .Microshift .String (), "hyperv" , "4.18" , "x86" , "" },
228+ {"crc_microshift_hyperv_4.18_x86_1233.crcbundle" , preset .Microshift .String (), "hyperv" , "4.18" , "x86" , "1233" },
229+ {"crc_hyperv_4.18_x86_4566.crcbundle" , preset .OpenShift .String (), "hyperv" , "4.18" , "x86" , "4566" },
230+ {"crc_ABCdrv_4.18.0_x86_4566.crcbundle" , preset .OpenShift .String (), "ABCdrv" , "4.18.0" , "x86" , "4566" },
231+ {"crc_ABCdrv_4.18.1.2_x86_4566.crcbundle" , preset .OpenShift .String (), "ABCdrv" , "4.18.1.2" , "x86" , "4566" },
232+ {"crc_hyperv_4.18_x86.crcbundle" , preset .OpenShift .String (), "hyperv" , "4.18" , "x86" , "" },
233+ {"crc_ABCdrv_4.18.0_x86.crcbundle" , preset .OpenShift .String (), "ABCdrv" , "4.18.0" , "x86" , "" },
234+ {"crc_ABCdrv_4.18.1.2_x86.crcbundle" , preset .OpenShift .String (), "ABCdrv" , "4.18.1.2" , "x86" , "" },
235+ {"crc_hyperv_4.18_64bit.crcbundle" , preset .OpenShift .String (), "hyperv" , "4.18" , "64bit" , "" },
236+ {"crc_hyperv_4.1_64bit.crcbundle" , preset .OpenShift .String (), "hyperv" , "4.1" , "64bit" , "" },
237+
238+ {"crc_openshift_libvirt_4.16.7_amd64.crcbundle" , preset .OpenShift .String (), "libvirt" , "4.16.7" , "amd64" , "" },
239+ {"crc_openshift_libvirt_4.16.7_amd64_1.crcbundle" , preset .OpenShift .String (), "libvirt" , "4.16.7" , "amd64" , "1" },
240+ {"crc_openshift_libvirt_00.00.00.00_amd64.crcbundle" , preset .OpenShift .String (), "libvirt" , "00.00.00.00" , "amd64" , "" },
241+ {"crc_openshift_libvirt_00.00.00.00_amd64_100.crcbundle" , preset .OpenShift .String (), "libvirt" , "00.00.00.00" , "amd64" , "100" },
242+ {"crc_libvirt_4.16.7_intel.crcbundle" , preset .OpenShift .String (), "libvirt" , "4.16.7" , "intel" , "" },
243+ {"crc_libvirt_4.16.7_intel_23.crcbundle" , preset .OpenShift .String (), "libvirt" , "4.16.7" , "intel" , "23" },
244+ {"crc_libvirt_4.16.7_64.crcbundle" , preset .OpenShift .String (), "libvirt" , "4.16.7" , "64" , "" },
245+ {"crc_libvirt_4.16.7_64_132.crcbundle" , preset .OpenShift .String (), "libvirt" , "4.16.7" , "64" , "132" },
246+ {"crc_microshift_libvirt_4.16.7_64.crcbundle" , preset .Microshift .String (), "libvirt" , "4.16.7" , "64" , "" },
247+ {"crc_microshift_libvirt_4.16.7_64_123.crcbundle" , preset .Microshift .String (), "libvirt" , "4.16.7" , "64" , "123" },
248+ {"crc_libvirt_4_amd64.crcbundle" , preset .OpenShift .String (), "libvirt" , "4" , "amd64" , "" },
249+ {"crc_libvirt_4_amd64_0123.crcbundle" , preset .OpenShift .String (), "libvirt" , "4" , "amd64" , "0123" },
250+ {"crc_okd_libvirt_4_amd64.crcbundle" , preset .OKD .String (), "libvirt" , "4" , "amd64" , "" },
251+ {"crc_okd_libvirt_4_amd64_0123.crcbundle" , preset .OKD .String (), "libvirt" , "4" , "amd64" , "0123" },
252+ }
253+
254+ for _ , parts := range valid {
255+ bundleInfo , err := GetBundleInfoFromName (parts [0 ])
256+ assert .NoError (t , err )
257+ assert .Equal (t , bundleInfo .Preset .String (), parts [1 ])
258+ assert .Equal (t , bundleInfo .Driver , parts [2 ])
259+ assert .Equal (t , bundleInfo .Version , parts [3 ])
260+ assert .Equal (t , bundleInfo .Arch , parts [4 ])
261+ assert .Equal (t , bundleInfo .CustomBundleSuffix , parts [5 ])
262+ }
263+ }
264+
265+ func TestGetBundleInfoFromNameInvalid (t * testing.T ) {
266+ // missing version
267+ _ , err := GetBundleInfoFromName ("crc_libvirt_amd64.crcbundle" )
268+ assert .Error (t , err )
269+
270+ // missing crc prefix
271+ _ , err = GetBundleInfoFromName ("libvirt_4.16.0_amd64.crcbundle" )
272+ assert .Error (t , err )
273+
274+ // missing arch
275+ _ , err = GetBundleInfoFromName ("crc_microshift_libvirt_4.7.0.crcbundle" )
276+ assert .Error (t , err )
277+
278+ // non numeric suffix
279+ _ , err = GetBundleInfoFromName ("crc_microshift_libvirt_4.7.0_x86_custom.crcbundle" )
280+ assert .Error (t , err )
281+
282+ // missing driver
283+ _ , err = GetBundleInfoFromName ("crc_4.16.2_amd64_123.crcbundle" )
284+ assert .Error (t , err )
285+
286+ // missing driver and version
287+ _ , err = GetBundleInfoFromName ("crc_amd64_123.crcbundle" )
288+ assert .Error (t , err )
289+
290+ // unknown preset
291+ _ , err = GetBundleInfoFromName ("crc_nanoshift_libvirt_4.16.7_amd64_232.crcbundle" )
292+ assert .Error (t , err )
293+ }
0 commit comments