Skip to content

Commit

Permalink
Merge pull request #1039 from okta/bobtfish_1037_file_md5
Browse files Browse the repository at this point in the history
Application schema logo state function
  • Loading branch information
monde committed Mar 30, 2022
2 parents ac62cff + 679d341 commit e118891
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
16 changes: 9 additions & 7 deletions okta/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 logoPath
}
return fmt.Sprintf("%s (%s)", logoPath, computeFileHash(logoPath))
},
StateFunc: logoStateFunc,
},
"logo_url": {
Type: schema.TypeString,
Expand Down Expand Up @@ -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)
}
27 changes: 27 additions & 0 deletions okta/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e118891

Please sign in to comment.