Skip to content

Commit 9fc93d6

Browse files
Copilothsluoyz
andcommitted
Add Casbin v3 interface tests and update README
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
1 parent aa14a2c commit 9fc93d6

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Based on [Xorm Drivers Support](https://gitea.com/xorm/xorm#drivers-support), Th
2727
package main
2828

2929
import (
30-
"github.com/casbin/casbin/v2"
30+
"github.com/casbin/casbin/v3"
3131
_ "github.com/go-sql-driver/mysql"
3232

3333
"github.com/casbin/xorm-adapter/v3"
@@ -67,7 +67,7 @@ func main() {
6767
package main
6868

6969
import (
70-
"github.com/casbin/casbin/v2"
70+
"github.com/casbin/casbin/v3"
7171
_ "github.com/lib/pq"
7272

7373
"github.com/casbin/xorm-adapter/v3"

interface_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2017 The casbin Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package xormadapter
16+
17+
import (
18+
"testing"
19+
20+
"github.com/casbin/casbin/v3/persist"
21+
)
22+
23+
// TestAdapterInterface verifies that Adapter implements persist.Adapter interface for Casbin v3
24+
func TestAdapterInterface(t *testing.T) {
25+
var _ persist.Adapter = (*Adapter)(nil)
26+
}
27+
28+
// TestCasbinV3Compatibility verifies that the adapter type is compatible with Casbin v3
29+
func TestCasbinV3Compatibility(t *testing.T) {
30+
// Create a dummy adapter (won't connect to DB in this test)
31+
a := &Adapter{
32+
driverName: "mysql",
33+
dataSourceName: "root:@tcp(127.0.0.1:3306)/",
34+
dbSpecified: false,
35+
tableName: "casbin_rule",
36+
}
37+
38+
// This verifies the adapter implements persist.Adapter interface correctly
39+
// If LoadPolicy method was missing, this would fail to compile
40+
var adapter persist.Adapter = a
41+
42+
// Verify the type assertion works
43+
if adapter == nil {
44+
t.Fatal("Adapter should not be nil")
45+
}
46+
47+
t.Log("Successfully verified Adapter implements persist.Adapter for Casbin v3")
48+
}

0 commit comments

Comments
 (0)