diff --git a/README.md b/README.md index 14f9510..54758dd 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Based on [Xorm Drivers Support](https://gitea.com/xorm/xorm#drivers-support), Th package main import ( - "github.com/casbin/casbin/v2" + "github.com/casbin/casbin/v3" _ "github.com/go-sql-driver/mysql" "github.com/casbin/xorm-adapter/v3" @@ -67,7 +67,7 @@ func main() { package main import ( - "github.com/casbin/casbin/v2" + "github.com/casbin/casbin/v3" _ "github.com/lib/pq" "github.com/casbin/xorm-adapter/v3" diff --git a/adapter.go b/adapter.go index ac96060..266c76b 100644 --- a/adapter.go +++ b/adapter.go @@ -21,8 +21,8 @@ import ( "runtime" "strings" - "github.com/casbin/casbin/v2/model" - "github.com/casbin/casbin/v2/persist" + "github.com/casbin/casbin/v3/model" + "github.com/casbin/casbin/v3/persist" "github.com/lib/pq" "xorm.io/xorm" ) diff --git a/adapter_test.go b/adapter_test.go index 05cd3dd..b13a614 100644 --- a/adapter_test.go +++ b/adapter_test.go @@ -19,15 +19,18 @@ import ( "strings" "testing" - "github.com/casbin/casbin/v2" - "github.com/casbin/casbin/v2/util" + "github.com/casbin/casbin/v3" + "github.com/casbin/casbin/v3/util" _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" ) func testGetPolicy(t *testing.T, e *casbin.Enforcer, res [][]string) { t.Helper() - myRes := e.GetPolicy() + myRes, err := e.GetPolicy() + if err != nil { + t.Fatalf("GetPolicy failed: %v", err) + } log.Print("Policy: ", myRes) m := make(map[string]bool, len(res)) @@ -311,7 +314,10 @@ func testUpdateFilteredPolicies(t *testing.T, a *Adapter) { } func testGetPolicyWithoutOrder(t *testing.T, e *casbin.Enforcer, res [][]string) { - myRes := e.GetPolicy() + myRes, err := e.GetPolicy() + if err != nil { + t.Fatalf("GetPolicy failed: %v", err) + } log.Print("Policy: ", myRes) if !arrayEqualsWithoutOrder(myRes, res) { diff --git a/go.mod b/go.mod index dc20432..cad2b47 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/casbin/xorm-adapter/v3 go 1.12 require ( - github.com/casbin/casbin/v2 v2.77.2 + github.com/casbin/casbin/v3 v3.0.0 github.com/go-sql-driver/mysql v1.6.0 github.com/lib/pq v1.10.2 xorm.io/xorm v1.3.2 diff --git a/go.sum b/go.sum index e15529d..2120084 100644 --- a/go.sum +++ b/go.sum @@ -4,7 +4,6 @@ gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGq gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU= gitee.com/travelliu/dm v1.8.11192/go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= @@ -28,9 +27,13 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I= +github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= -github.com/casbin/casbin/v2 v2.77.2 h1:yQinn/w9x8AswiwqwtrXz93VU48R1aYTXdHEx4RI3jM= -github.com/casbin/casbin/v2 v2.77.2/go.mod h1:mzGx0hYW9/ksOSpw3wNjk3NRAroq5VMFYUQ6G43iGPk= +github.com/casbin/casbin/v3 v3.0.0 h1:PGm0wWf6kGKJgGvRzWFjgQ8T2fCvtGXG4XbMx8aYThY= +github.com/casbin/casbin/v3 v3.0.0/go.mod h1:WNfIA7yAqwlSfatqceIddznwH0tzcXAXuGdARtorJKM= +github.com/casbin/govaluate v1.3.0 h1:VA0eSY0M2lA86dYd5kPPuNZMUD9QkWnOCnavGrw9myc= +github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -110,8 +113,9 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= @@ -347,12 +351,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= -github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= -github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= -github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= -github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= diff --git a/interface_test.go b/interface_test.go new file mode 100644 index 0000000..7e565b5 --- /dev/null +++ b/interface_test.go @@ -0,0 +1,48 @@ +// Copyright 2017 The casbin Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package xormadapter + +import ( + "testing" + + "github.com/casbin/casbin/v3/persist" +) + +// TestAdapterInterface verifies that Adapter implements persist.Adapter interface for Casbin v3 +func TestAdapterInterface(t *testing.T) { + var _ persist.Adapter = (*Adapter)(nil) +} + +// TestCasbinV3Compatibility verifies that the adapter type is compatible with Casbin v3 +func TestCasbinV3Compatibility(t *testing.T) { + // Create a dummy adapter (won't connect to DB in this test) + a := &Adapter{ + driverName: "mysql", + dataSourceName: "root:@tcp(127.0.0.1:3306)/", + dbSpecified: false, + tableName: "casbin_rule", + } + + // This verifies the adapter implements persist.Adapter interface correctly + // If LoadPolicy method was missing, this would fail to compile + var adapter persist.Adapter = a + + // Verify the type assertion works + if adapter == nil { + t.Fatal("Adapter should not be nil") + } + + t.Log("Successfully verified Adapter implements persist.Adapter for Casbin v3") +}