diff --git a/twingate/internal/client/cache.go b/twingate/internal/client/cache.go index 83533626..34a57cda 100644 --- a/twingate/internal/client/cache.go +++ b/twingate/internal/client/cache.go @@ -105,7 +105,7 @@ func (c *clientCache) run() { //nolint } func (c *clientCache) fetchResources(resourcesToRequest map[string]bool) { - if len(resourcesToRequest) >= minBulkSize { + if len(resourcesToRequest) >= minBulkSize && c.client != nil { resources, err := c.client.ReadFullResources(context.Background()) if err == nil { c.setResources(resources) @@ -119,6 +119,16 @@ func (c *clientCache) fetchResources(resourcesToRequest map[string]bool) { } func (c *clientCache) getResource(resourceID string) (*model.Resource, bool) { + c.lock.RLock() + + if c.client == nil { + c.lock.RUnlock() + + return nil, false + } + + c.lock.RUnlock() + c.lock.RLock() res, exists := c.resources[resourceID] c.lock.RUnlock() diff --git a/twingate/internal/client/client.go b/twingate/internal/client/client.go index c3e28b4d..edac3261 100644 --- a/twingate/internal/client/client.go +++ b/twingate/internal/client/client.go @@ -163,7 +163,9 @@ func NewClient(url string, apiToken string, network string, httpTimeout time.Dur log.Printf("[INFO] Using Server URL %s", sURL.newGraphqlServerURL()) - cache.client = &client + if version != "test" { + cache.client = &client + } return &client }