Skip to content

Commit

Permalink
fix: Allow for case-insensitve matching of products
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewJohn committed Jun 8, 2024
1 parent e25a6bc commit 7d2a673
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ func Test_GetProductById(t *testing.T) {
}
}

// Test case-insensitve match
product = GetProductById("oPeNtOfU")
if product == nil {
t.Errorf("Terraform product returned nil")
} else {
if expected := "opentofu"; product.GetId() != expected {
t.Errorf("Product ID does not match expected Id. Expected: %q, actual: %q", expected, product.GetId())
}
}

product = GetProductById("doesnotexist")
if product != nil {
t.Errorf("Unknown product returned non-nil response")
Expand Down
2 changes: 1 addition & 1 deletion lib/products.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ var products = []Product{

func GetProductById(id string) Product {
for _, product := range products {
if product.GetId() == id {
if strings.EqualFold(product.GetId(), id) {
return product
}
}
Expand Down

0 comments on commit 7d2a673

Please sign in to comment.