Skip to content

Commit

Permalink
linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed Dec 8, 2024
1 parent 6dc3d2e commit 92155c2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ func NewApiClient(client http.HttpClientInterface, defaultOrganizationId string)
cachedOrganizationId: "",
defaultOrganizationId: defaultOrganizationId,
}

apiClient.memoizedGetTeams = memoize(apiClient.GetTeams)

return apiClient
}
5 changes: 2 additions & 3 deletions client/configuration_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package client_test

import (
"encoding/json"
"strings"
"testing"

. "github.com/env0/terraform-provider-env0/client"
Expand Down Expand Up @@ -309,7 +308,7 @@ func TestConfigurationVariableMarshelling(t *testing.T) {

b, err := json.Marshal(&variable)
if assert.NoError(t, err) {
assert.False(t, strings.Contains(string(b), str))
assert.NotContains(t, string(b), str)
}

type ConfigurationVariableDummy ConfigurationVariable
Expand All @@ -318,7 +317,7 @@ func TestConfigurationVariableMarshelling(t *testing.T) {

b, err = json.Marshal(&dummy)
if assert.NoError(t, err) {
assert.True(t, strings.Contains(string(b), str))
assert.Contains(t, string(b), str)
}

var variable2 ConfigurationVariable
Expand Down
4 changes: 4 additions & 0 deletions client/memoize.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ type memoizedResult[V any] struct {

func memoize[K comparable, V any](f func(K) (V, error)) func(K) (V, error) {
cache := make(map[K]memoizedResult[V])

return func(key K) (V, error) {
if res, ok := cache[key]; ok {
return res.value, res.err
}

value, err := f(key)

cache[key] = memoizedResult[V]{value: value, err: err}

return value, err
}
}

0 comments on commit 92155c2

Please sign in to comment.