Skip to content

Commit c1314c3

Browse files
committed
feat: Allow for case-insensitve matching of products
1 parent e25a6bc commit c1314c3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/product_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ func Test_GetProductById(t *testing.T) {
2424
}
2525
}
2626

27+
// Test case-insensitve match
28+
product = GetProductById("oPeNtOfU")
29+
if product == nil {
30+
t.Errorf("Terraform product returned nil")
31+
} else {
32+
if expected := "opentofu"; product.GetId() != expected {
33+
t.Errorf("Product ID does not match expected Id. Expected: %q, actual: %q", expected, product.GetId())
34+
}
35+
}
36+
2737
product = GetProductById("doesnotexist")
2838
if product != nil {
2939
t.Errorf("Unknown product returned non-nil response")

lib/products.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ var products = []Product{
149149

150150
func GetProductById(id string) Product {
151151
for _, product := range products {
152-
if product.GetId() == id {
152+
if strings.EqualFold(product.GetId(), id) {
153153
return product
154154
}
155155
}

0 commit comments

Comments
 (0)