From 8c3b4f8e7709b97f155077eb6bcbbd7133772f4e Mon Sep 17 00:00:00 2001 From: Tomas Doran Date: Tue, 29 Mar 2022 04:25:51 -0700 Subject: [PATCH 1/2] Stop tracking the local path to the logo in state. Fixes #1036 by not tracking the logo path in the state and just tracking the hash. --- okta/app.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/okta/app.go b/okta/app.go index 56a323ae6..a16e72147 100644 --- a/okta/app.go +++ b/okta/app.go @@ -93,9 +93,9 @@ var ( StateFunc: func(val interface{}) string { logoPath := val.(string) if logoPath == "" { - return logoPath + return "" } - return fmt.Sprintf("%s (%s)", logoPath, computeFileHash(logoPath)) + return computeFileHash(logoPath) }, }, "logo_url": { From 679d3410e3b2a1906d95a406dd644ccf9c3d5890 Mon Sep 17 00:00:00 2001 From: Mike Mondragon Date: Tue, 29 Mar 2022 16:58:14 -0700 Subject: [PATCH 2/2] Unit test for logo state function. --- okta/app.go | 16 +++++++++------- okta/app_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/okta/app.go b/okta/app.go index a16e72147..6d72c661a 100644 --- a/okta/app.go +++ b/okta/app.go @@ -90,13 +90,7 @@ var ( DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { return new == "" }, - StateFunc: func(val interface{}) string { - logoPath := val.(string) - if logoPath == "" { - return "" - } - return computeFileHash(logoPath) - }, + StateFunc: logoStateFunc, }, "logo_url": { Type: schema.TypeString, @@ -731,3 +725,11 @@ func computeFileHash(filename string) string { _ = file.Close() return hex.EncodeToString(h.Sum(nil)) } + +func logoStateFunc(val interface{}) string { + logoPath := val.(string) + if logoPath == "" { + return "" + } + return computeFileHash(logoPath) +} diff --git a/okta/app_test.go b/okta/app_test.go index 83921281a..68f5b0e3c 100644 --- a/okta/app_test.go +++ b/okta/app_test.go @@ -4,8 +4,35 @@ import ( "context" "fmt" "strings" + "testing" ) +func TestLogoStateFunc(t *testing.T) { + cases := []struct { + input interface{} + expected string + }{ + { + input: "../examples/okta_app_basic_auth/terraform_icon.png", + expected: "188b6050b43d2fbc9be327e39bf5f7849b120bb4529bcd22cde78b02ccce6777", // compare to `shasum -a 256 filepath` + }, + { + input: "invalid/file/path", + expected: "", + }, + { + input: "", + expected: "", + }, + } + for _, c := range cases { + result := logoStateFunc(c.input) + if result != c.expected { + t.Errorf("Error matching logo, expected %q, got %q, for file %q", c.expected, result, c.input) + } + } +} + func deleteTestApps(client *testClient) error { appList, err := listApps(context.Background(), client.oktaClient, &appFilters{LabelPrefix: testResourcePrefix}, defaultPaginationLimit) if err != nil {