55 "net/http"
66 "net/http/httptest"
77 "strings"
8+ "sync/atomic"
89 "testing"
910 "time"
1011
@@ -27,9 +28,9 @@ func TestInventory_localModeEnumeratesLocalOnly(t *testing.T) {
2728 }))
2829 t .Cleanup (local .Close )
2930
30- var cloudHits int
31+ var cloudHits atomic. Int32
3132 cloud := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
32- cloudHits ++
33+ cloudHits . Add ( 1 )
3334 _ , _ = w .Write ([]byte (`{"models":[{"name":"deepseek-v3.2"}]}` ))
3435 }))
3536 t .Cleanup (cloud .Close )
@@ -51,8 +52,8 @@ func TestInventory_localModeEnumeratesLocalOnly(t *testing.T) {
5152 if err != nil {
5253 t .Fatal (err )
5354 }
54- if cloudHits != 0 {
55- t .Fatalf ("cloud discovery invoked %d times" , cloudHits )
55+ if cloudHits . Load () != 0 {
56+ t .Fatalf ("cloud discovery invoked %d times" , cloudHits . Load () )
5657 }
5758 if len (snap .Models ) != 2 {
5859 t .Fatalf ("models = %+v" , snap .Models )
@@ -81,9 +82,9 @@ func TestInventory_localIgnoresCloudToggle(t *testing.T) {
8182 }))
8283 t .Cleanup (local .Close )
8384
84- var cloudHits int
85+ var cloudHits atomic. Int32
8586 cloud := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
86- cloudHits ++
87+ cloudHits . Add ( 1 )
8788 _ , _ = w .Write ([]byte (`{"models":[{"name":"deepseek-v3.2"}]}` ))
8889 }))
8990 t .Cleanup (cloud .Close )
@@ -107,8 +108,8 @@ func TestInventory_localIgnoresCloudToggle(t *testing.T) {
107108 if err != nil {
108109 t .Fatal (err )
109110 }
110- if cloudHits != 0 {
111- t .Fatalf ("cloud discovery invoked %d times" , cloudHits )
111+ if cloudHits . Load () != 0 {
112+ t .Fatalf ("cloud discovery invoked %d times" , cloudHits . Load () )
112113 }
113114 if len (snap .Models ) != 1 || snap .Models [0 ].NativeID != "llama3:latest" {
114115 t .Fatalf ("models = %+v" , snap .Models )
@@ -121,10 +122,10 @@ func TestInventory_localIgnoresCloudToggle(t *testing.T) {
121122func TestInventory_cloudModeEnumeratesCloudOnly (t * testing.T ) {
122123 t .Parallel ()
123124
124- var localHits int
125+ var localHits atomic. Int32
125126 local := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
126127 if r .URL .Path == "/v1/models" {
127- localHits ++
128+ localHits . Add ( 1 )
128129 }
129130 http .NotFound (w , r )
130131 }))
@@ -152,8 +153,8 @@ func TestInventory_cloudModeEnumeratesCloudOnly(t *testing.T) {
152153 if err != nil {
153154 t .Fatal (err )
154155 }
155- if localHits != 0 {
156- t .Fatalf ("local discovery invoked %d times" , localHits )
156+ if localHits . Load () != 0 {
157+ t .Fatalf ("local discovery invoked %d times" , localHits . Load () )
157158 }
158159 if len (snap .Models ) != 2 {
159160 t .Fatalf ("models = %+v" , snap .Models )
@@ -176,10 +177,10 @@ func TestInventory_cloudModeEnumeratesCloudOnly(t *testing.T) {
176177func TestInventory_cloudIgnoresLocalToggle (t * testing.T ) {
177178 t .Parallel ()
178179
179- var localHits int
180+ var localHits atomic. Int32
180181 local := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
181182 if r .URL .Path == "/v1/models" {
182- localHits ++
183+ localHits . Add ( 1 )
183184 }
184185 http .NotFound (w , r )
185186 }))
@@ -209,8 +210,8 @@ func TestInventory_cloudIgnoresLocalToggle(t *testing.T) {
209210 if err != nil {
210211 t .Fatal (err )
211212 }
212- if localHits != 0 {
213- t .Fatalf ("local discovery invoked %d times" , localHits )
213+ if localHits . Load () != 0 {
214+ t .Fatalf ("local discovery invoked %d times" , localHits . Load () )
214215 }
215216 if len (snap .Models ) != 1 || snap .Models [0 ].NativeID != "deepseek-v3.2" {
216217 t .Fatalf ("models = %+v" , snap .Models )
0 commit comments