Skip to content

Commit 2124185

Browse files
committed
test(integration): compare members across calls, not the whole x
The example rego intentionally returns different shapes for `x` in the two states: bucket_watched=false → x = nats.kv.get_data(bucket, "members") (just the members map) bucket_watched=true → x = data.nats.kv[bucket] (the entire bucket: members + metadata + permissions) The original assertion `x1 == x2` assumed otherwise and was always wrong; before the deadlock fix the second call deadlocked instead of returning, so we never got to compare. Now that calls return correctly in both states, compare the members submap explicitly: x_unwatched vs x_watched["members"]
1 parent d68e179 commit 2124185

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

cmd/opa-nats/main_test.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,18 @@ func TestIntegration(t *testing.T) {
173173

174174
t.Logf("Subsequent call - bucket_watched: true, x: %+v", resultData2["x"])
175175

176-
// x should be the same once the watcher is registered
177-
assert.Equal(t, x1, resultData2["x"], "x should be the same in both calls")
176+
// The two calls intentionally return different shapes for `x`:
177+
// bucket_watched=false → x = nats.kv.get_data(bucket, "members") (members map only)
178+
// bucket_watched=true → x = data.nats.kv[bucket] (entire bucket)
179+
// What we verify is that the members data the unwatched path returns
180+
// matches the members data the watched path stores under the bucket.
181+
x1Members, ok1 := x1.(map[string]interface{})
182+
require.True(t, ok1, "x1 should be a map (members)")
183+
x2Bucket, ok2 := resultData2["x"].(map[string]interface{})
184+
require.True(t, ok2, "x2 should be a map (bucket)")
185+
x2Members, ok2m := x2Bucket["members"].(map[string]interface{})
186+
require.True(t, ok2m, "x2 should contain members map")
187+
assert.Equal(t, x1Members, x2Members, "members data should match between unwatched and watched calls")
178188

179189
t.Log("Bucket watching behavior verified: bucket_watched flips to true once the async watcher registration completes")
180190
})
@@ -223,15 +233,24 @@ func TestIntegration(t *testing.T) {
223233
assert.True(t, results[1]["bucket_watched"].(bool), "Post-registration call should have bucket_watched: true")
224234
assert.True(t, results[2]["bucket_watched"].(bool), "Subsequent call should have bucket_watched: true")
225235

226-
// All x values should be the same
227-
x0 := results[0]["x"]
228-
x1 := results[1]["x"]
229-
x2 := results[2]["x"]
236+
// As in the previous subtest, the bucket_watched=false branch returns
237+
// only the `members` submap, while the bucket_watched=true branch
238+
// returns the entire bucket. Compare the members slice from each
239+
// representation rather than the raw `x` values.
240+
x0Members, ok0 := results[0]["x"].(map[string]interface{})
241+
require.True(t, ok0, "x[0] should be a members map")
242+
x1Bucket, ok1 := results[1]["x"].(map[string]interface{})
243+
require.True(t, ok1, "x[1] should be a bucket map")
244+
x2Bucket, ok2 := results[2]["x"].(map[string]interface{})
245+
require.True(t, ok2, "x[2] should be a bucket map")
230246

231-
assert.Equal(t, x0, x1, "x should be same between first and second call")
232-
assert.Equal(t, x1, x2, "x should be same between second and third call")
247+
x1Members, _ := x1Bucket["members"].(map[string]interface{})
248+
x2Members, _ := x2Bucket["members"].(map[string]interface{})
233249

234-
t.Logf("✅ Data consistency verified: x remains %+v across all calls", x0)
250+
assert.Equal(t, x0Members, x1Members, "members data should match between unwatched and post-watcher calls")
251+
assert.Equal(t, x1Members, x2Members, "members data should be stable across consecutive watched calls")
252+
253+
t.Logf("Data consistency verified: members data is stable across watched/unwatched and consecutive calls")
235254
})
236255
}
237256

0 commit comments

Comments
 (0)