From c1314c3a5d4a5335adbfa5c673ce3314a17aea44 Mon Sep 17 00:00:00 2001 From: Matthew John Date: Sat, 8 Jun 2024 09:45:50 +0100 Subject: [PATCH] feat: Allow for case-insensitve matching of products --- lib/product_test.go | 10 ++++++++++ lib/products.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/product_test.go b/lib/product_test.go index 7aa78953..9c82c38c 100644 --- a/lib/product_test.go +++ b/lib/product_test.go @@ -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") diff --git a/lib/products.go b/lib/products.go index ced128fe..abced830 100644 --- a/lib/products.go +++ b/lib/products.go @@ -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 } }