Skip to content

Commit

Permalink
simplified driver subproducts (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Proud <laidbackware.git@gmail.com>
  • Loading branch information
laidbackware and Matt Proud authored Dec 7, 2023
1 parent e98924b commit 713cae3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
6 changes: 3 additions & 3 deletions sdk/eula_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestFetchEulaLink(t *testing.T) {
require.Nil(t, err)

var eulaUrl string
eulaUrl, err = authenticatedClient.FetchEulaUrl("VMTOOLS1126", "1073")
eulaUrl, err = authenticatedClient.FetchEulaUrl("VMTOOLS1235", "1259")
assert.Nil(t, err)
assert.NotEmpty(t, eulaUrl, "Expected eulaUrl not be empty")
}
Expand All @@ -25,7 +25,7 @@ func TestFetchEulaLinkInvalidCode(t *testing.T) {
assert.Nil(t, err)

var eulaUrl string
eulaUrl, err = authenticatedClient.FetchEulaUrl("VMTOOLS1130", "9999")
eulaUrl, err = authenticatedClient.FetchEulaUrl("VMTOOLS1235", "9999")
assert.NotNil(t, err)
assert.ErrorIs(t, err, ErrorDlgDetailsInputs)
assert.Empty(t, eulaUrl, "Expected eulaUrl be empty")
Expand All @@ -35,6 +35,6 @@ func TestAcceptEula(t *testing.T) {
err = ensureLogin(t)
require.Nil(t, err)

err = authenticatedClient.AcceptEula("VMTOOLS1126", "1073")
err = authenticatedClient.AcceptEula("VMTOOLS1235", "1259")
assert.Nil(t, err)
}
20 changes: 15 additions & 5 deletions sdk/subproduct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,33 @@ func TestModifyHorizonClientCode(t *testing.T) {
func TestGetProductName(t *testing.T) {
reEndVersion := regexp.MustCompile(`[0-9]+.*`)
productName := "VMware vSphere Hypervisor (ESXi) 8.0U2"
productName = getProductName(productName, "vmware_vsphere", "", reEndVersion)
productName = getProductName(productName, "vmware_vsphere", "PRODUCT_BINARY", reEndVersion)
assert.Equal(t, "VMware vSphere Hypervisor (ESXi)", productName)

// Ensure drivers are unmodified
productName = "VMware ESXi 8.0 native ixgben ENS 1.18.2.0 NIC Driver for Intel Ethernet Controllers 82599, x520, x540, x550, and x552 family"
productName = getProductName(productName, "vmware_vsphere", "Driver CDs", reEndVersion)
assert.Equal(t, productName, "Driver - native ixgben ENS")
productName = getProductName(productName, "vmware_vsphere", "DRIVERS_TOOLS", reEndVersion)
assert.Equal(t, productName, "VMware ESXi 8.0 native ixgben ENS 1.18.2.0 NIC Driver for Intel Ethernet Controllers 82599, x520, x540, x550, and x552 family")

// Ensure drivers are unmodified
productName = "HPE Custom Image for ESXi 7.0 U3 Install CD"
productName = getProductName(productName, "vmware_vsphere", "ADDONS", reEndVersion)
assert.Equal(t, productName, "HPE Custom Image for ESXi 7.0 U3 Install CD")
}

func TestGetProductCode(t *testing.T) {
reEndVersion := regexp.MustCompile(`[0-9]+.*`)
productCode := "ESXI80U2"
productCode = getProductCode(productCode, "vmware_vsphere", "", reEndVersion)
productCode = getProductCode(productCode, "vmware_vsphere", "PRODUCT_BINARY", reEndVersion)
assert.Equal(t, "esxi", productCode)

// Ensure drivers are unmodified
productCode = "DT-ESXI80-INTEL-I40EN-2650-1OEM"
productCode = getProductCode(productCode, "vmware_vsphere", "Driver CDs", reEndVersion)
productCode = getProductCode(productCode, "vmware_vsphere", "DRIVERS_TOOLS", reEndVersion)
assert.Equal(t, "dt-esxi80-intel-i40en-2650-1oem", productCode)

// Ensure custom isos are unmodified
productCode = "OEM-ESXI70U3-HPE"
productCode = getProductCode(productCode, "vmware_vsphere", "ADDONS", reEndVersion)
assert.Equal(t, "oem-esxi70u3-hpe", productCode)
}
28 changes: 12 additions & 16 deletions sdk/subproducts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package sdk

import (
"errors"
"fmt"
"regexp"
"sort"
"strings"
Expand Down Expand Up @@ -62,8 +61,8 @@ func (c *Client) GetSubProductsMap(slug, dlgType string) (subProductMap map[stri
// Regex captures numbers and all text after
reEndVersion := regexp.MustCompile(`[0-9]+.*`)

productName := getProductName(dlgList.Name, slug, dlgEdition.Name, reEndVersion)
productCode := getProductCode(strings.ToLower(dlgList.Code), slug, dlgEdition.Name, reEndVersion)
productName := getProductName(dlgList.Name, slug, dlgType, reEndVersion)
productCode := getProductCode(strings.ToLower(dlgList.Code), slug, dlgType, reEndVersion)

// Initalize the struct for a product code for the first time
if _, ok := subProductMap[productCode]; !ok {
Expand All @@ -85,16 +84,16 @@ func (c *Client) GetSubProductsMap(slug, dlgType string) (subProductMap map[stri
return
}

func getProductCode(productCode, slug, dlgEditionName string, reEndVersion *regexp.Regexp) (string) {
func getProductCode(productCode, slug, dlgType string, reEndVersion *regexp.Regexp) (string) {
productCode = strings.ToLower(productCode)
if dlgType != "PRODUCT_BINARY" {
return productCode
}
reMidVersion := regexp.MustCompile(`(-|_)([0-9.]+)(-|_)`)
// Horizon clients don't follow a common pattern for API naming. This block aligns the pattern
if strings.HasPrefix(productCode, "cart") {
return modifyHorizonClientCode(productCode)
}
if slug == "vmware_vsphere" && dlgEditionName == "Driver CDs" {
return productCode
}
}
// Horizon clients don't follow a common pattern for API naming. This block aligns the pattern
// Check if product code has text after the version section
if ok := reMidVersion.MatchString(productCode); ok{
// replace version with + to allow for string to be split when searching
Expand All @@ -110,22 +109,19 @@ func getProductCode(productCode, slug, dlgEditionName string, reEndVersion *rege
return productCode
}

func getProductName(productName, slug, dlgEditionName string, reEndVersion *regexp.Regexp) (string) {
func getProductName(productName, slug, dlgType string, reEndVersion *regexp.Regexp) (string) {
if dlgType != "PRODUCT_BINARY" {
return productName
}
// Special case for Horizon due to inconsistent naming
if slug == "vmware_horizon" {
reNumbers := regexp.MustCompile(`[0-9.,]+`)
reSpace := regexp.MustCompile(`\s+`)
productName := strings.TrimSpace(reNumbers.ReplaceAllString(productName, ""))
return reSpace.ReplaceAllString(productName, " ")
// Special case for ESXi drivers to make human readable
} else if slug == "vmware_vsphere" && dlgEditionName == "Driver CDs" {
stripEsx := regexp.MustCompile(`VMware ESXi [0-9]+.[0-9]+ `)
productName = fmt.Sprintf("Driver - %s", stripEsx.ReplaceAllString(productName, ""))
return strings.TrimSpace(reEndVersion.ReplaceAllString(productName, ""))
} else {
return strings.TrimSpace(reEndVersion.ReplaceAllString(productName, ""))
}

}

func modifyHorizonClientCode(productCode string) (string) {
Expand Down

0 comments on commit 713cae3

Please sign in to comment.