This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-mongodb-adapter.git


The following commit(s) were added to refs/heads/master by this push:
     new 67c1019  test: count g rules in TestSavePolicyAtomic assertion
67c1019 is described below

commit 67c101979371cff80af2ce7f3094a6c5b0f2dc29
Author: Yang Luo <[email protected]>
AuthorDate: Wed Aug 5 23:41:35 2026 +0800

    test: count g rules in TestSavePolicyAtomic assertion
---
 adapter_test.go | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/adapter_test.go b/adapter_test.go
index f9c9965..046ae12 100644
--- a/adapter_test.go
+++ b/adapter_test.go
@@ -717,6 +717,14 @@ func TestSavePolicyAtomic(t *testing.T) {
 
        adapter := a.(*adapter)
 
+       ctx, cancel := context.WithTimeout(context.TODO(), adapter.timeout)
+       defer cancel()
+
+       before, err := adapter.collection.CountDocuments(ctx, bson.D{})
+       if err != nil {
+               panic(err)
+       }
+
        // Two identical rules violate the unique index, so the insert fails 
after
        // the delete has already run inside the same transaction.
        duplicate := savePolicyLine("p", []string{"alice", "data1", "read"})
@@ -726,15 +734,12 @@ func TestSavePolicyAtomic(t *testing.T) {
                t.Fatal("Expected the save to fail on the unique index, but it 
succeeded")
        }
 
-       ctx, cancel := context.WithTimeout(context.TODO(), adapter.timeout)
-       defer cancel()
-
-       count, err := adapter.collection.CountDocuments(ctx, bson.D{})
+       after, err := adapter.collection.CountDocuments(ctx, bson.D{})
        if err != nil {
                panic(err)
        }
-       if count != 4 {
-               t.Errorf("Expected the 4 stored rules to survive a failed save; 
got %d rule(s)", count)
+       if after != before {
+               t.Errorf("Expected the %d stored rules to survive a failed 
save; got %d rule(s)", before, after)
        }
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to