Skip to content

Commit 98b2001

Browse files
committed
Fixed sweeperNetboxClients uninitialized and store cache sweeperNetboxClients region.
Signed-off-by: Lorenzo Buitizon <[email protected]>
1 parent 02003bc commit 98b2001

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

netbox/netbox_sweeper_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ import (
1414
var sweeperNetboxClients map[string]interface{}
1515

1616
func TestMain(m *testing.M) {
17+
// Initialize the client cache
18+
sweeperNetboxClients = make(map[string]interface{})
1719
resource.TestMain(m)
1820
}
1921

2022
// sharedClientForRegion returns a common provider client configured for the specified region
2123
func sharedClientForRegion(region string) (interface{}, error) {
24+
// Initialize map if it's nil (defensive programming)
25+
if sweeperNetboxClients == nil {
26+
sweeperNetboxClients = make(map[string]interface{})
27+
}
28+
2229
if client, ok := sweeperNetboxClients[region]; ok {
2330
return client, nil
2431
}
@@ -29,6 +36,9 @@ func sharedClientForRegion(region string) (interface{}, error) {
2936
transport.DefaultAuthentication = httptransport.APIKeyAuth("Authorization", "header", "Token "+apiToken)
3037
c := client.New(transport, nil)
3138

39+
// Store the client in the cache for future use
40+
sweeperNetboxClients[region] = c
41+
3242
return c, nil
3343
}
3444

0 commit comments

Comments
 (0)