diff --git a/casdoorsdk/adapter_test.go b/casdoorsdk/adapter_test.go index fb08953..024bf12 100644 --- a/casdoorsdk/adapter_test.go +++ b/casdoorsdk/adapter_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestAdapter(t *testing.T) { @@ -26,11 +25,11 @@ func TestAdapter(t *testing.T) { // Add a new object adapter := &Adapter{ - Owner: "admin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - User: name, - Host: "https://casdoor.org", + Owner: "admin", + Name: name, + CreatedTime: GetCurrentTime(), + User: name, + Host: "https://casdoor.org", } _, err := AddAdapter(adapter) if err != nil { diff --git a/casdoorsdk/application_test.go b/casdoorsdk/application_test.go index e58395e..f5c5203 100644 --- a/casdoorsdk/application_test.go +++ b/casdoorsdk/application_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestApplication(t *testing.T) { @@ -28,7 +27,7 @@ func TestApplication(t *testing.T) { application := &Application{ Owner: "admin", Name: name, - CreatedTime: time.Now().Format(time.RFC3339), + CreatedTime: GetCurrentTime(), DisplayName: name, Logo: "https://cdn.casbin.org/img/casdoor-logo_1185x256.png", HomepageUrl: "https://casdoor.org", diff --git a/casdoorsdk/cert_test.go b/casdoorsdk/cert_test.go index f53f5c8..4dbdc9c 100644 --- a/casdoorsdk/cert_test.go +++ b/casdoorsdk/cert_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestCert(t *testing.T) { @@ -28,13 +27,13 @@ func TestCert(t *testing.T) { cert := &Cert{ Owner: "admin", Name: name, - CreatedTime: time.Now().Format(time.RFC3339), + CreatedTime: GetCurrentTime(), DisplayName: name, Scope: "JWT", Type: "x509", CryptoAlgorithm: "RS256", - BitSize: 4096, - ExpireInYears: 20, + BitSize: 4096, + ExpireInYears: 20, } _, err := AddCert(cert) if err != nil { diff --git a/casdoorsdk/enforcer_test.go b/casdoorsdk/enforcer_test.go index 1b4e633..82ee8fe 100644 --- a/casdoorsdk/enforcer_test.go +++ b/casdoorsdk/enforcer_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestEnforcer(t *testing.T) { @@ -26,13 +25,13 @@ func TestEnforcer(t *testing.T) { // Add a new object enforcer := &Enforcer{ - Owner: "admin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - DisplayName: name, - Model: "built-in/user-model-built-in", - Adapter: "built-in/user-adapter-built-in", - Description: "Casdoor Website", + Owner: "admin", + Name: name, + CreatedTime: GetCurrentTime(), + DisplayName: name, + Model: "built-in/user-model-built-in", + Adapter: "built-in/user-adapter-built-in", + Description: "Casdoor Website", } _, err := AddEnforcer(enforcer) if err != nil { diff --git a/casdoorsdk/group_test.go b/casdoorsdk/group_test.go index 47228d5..5411920 100644 --- a/casdoorsdk/group_test.go +++ b/casdoorsdk/group_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestGroup(t *testing.T) { @@ -26,10 +25,10 @@ func TestGroup(t *testing.T) { // Add a new object group := &Group{ - Owner: "admin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - DisplayName: name, + Owner: "admin", + Name: name, + CreatedTime: GetCurrentTime(), + DisplayName: name, } _, err := AddGroup(group) if err != nil { diff --git a/casdoorsdk/model_test.go b/casdoorsdk/model_test.go index a502160..7c72ce8 100644 --- a/casdoorsdk/model_test.go +++ b/casdoorsdk/model_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestModel(t *testing.T) { @@ -26,10 +25,10 @@ func TestModel(t *testing.T) { // Add a new object model := &Model{ - Owner: "casbin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - DisplayName: name, + Owner: "casbin", + Name: name, + CreatedTime: GetCurrentTime(), + DisplayName: name, ModelText: `[request_definition] r = sub, obj, act diff --git a/casdoorsdk/organization_test.go b/casdoorsdk/organization_test.go index 3b82db2..70ae3c2 100644 --- a/casdoorsdk/organization_test.go +++ b/casdoorsdk/organization_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestOrganization(t *testing.T) { @@ -28,7 +27,7 @@ func TestOrganization(t *testing.T) { organization := &Organization{ Owner: "admin", Name: name, - CreatedTime: time.Now().Format(time.RFC3339), + CreatedTime: GetCurrentTime(), DisplayName: name, WebsiteUrl: "https://example.com", PasswordType: "plain", diff --git a/casdoorsdk/payment_test.go b/casdoorsdk/payment_test.go index 9fe4a90..bf783ea 100644 --- a/casdoorsdk/payment_test.go +++ b/casdoorsdk/payment_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestPayment(t *testing.T) { @@ -26,11 +25,11 @@ func TestPayment(t *testing.T) { // Add a new object payment := &Payment{ - Owner: "admin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - DisplayName: name, - ProductName: "casbin", + Owner: "admin", + Name: name, + CreatedTime: GetCurrentTime(), + DisplayName: name, + ProductName: "casbin", } _, err := AddPayment(payment) if err != nil { diff --git a/casdoorsdk/permission_test.go b/casdoorsdk/permission_test.go index 4eb4b2a..c32a170 100644 --- a/casdoorsdk/permission_test.go +++ b/casdoorsdk/permission_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestPermission(t *testing.T) { @@ -28,7 +27,7 @@ func TestPermission(t *testing.T) { permission := &Permission{ Owner: "casbin", Name: name, - CreatedTime: time.Now().Format(time.RFC3339), + CreatedTime: GetCurrentTime(), DisplayName: name, Description: "Casdoor Website", Users: []string{"casbin/*"}, diff --git a/casdoorsdk/plan_test.go b/casdoorsdk/plan_test.go index ff2451b..fad3a89 100644 --- a/casdoorsdk/plan_test.go +++ b/casdoorsdk/plan_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestPlan(t *testing.T) { @@ -26,11 +25,11 @@ func TestPlan(t *testing.T) { // Add a new object plan := &Plan{ - Owner: "admin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - DisplayName: name, - Description: "Casdoor Website", + Owner: "admin", + Name: name, + CreatedTime: GetCurrentTime(), + DisplayName: name, + Description: "Casdoor Website", } _, err := AddPlan(plan) if err != nil { diff --git a/casdoorsdk/pricing_test.go b/casdoorsdk/pricing_test.go index 97d8b00..57d9f8b 100644 --- a/casdoorsdk/pricing_test.go +++ b/casdoorsdk/pricing_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestPricing(t *testing.T) { @@ -26,12 +25,12 @@ func TestPricing(t *testing.T) { // Add a new object pricing := &Pricing{ - Owner: "admin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - DisplayName: name, - Application: "app-admin", - Description: "Casdoor Website", + Owner: "admin", + Name: name, + CreatedTime: GetCurrentTime(), + DisplayName: name, + Application: "app-admin", + Description: "Casdoor Website", } _, err := AddPricing(pricing) if err != nil { diff --git a/casdoorsdk/product_test.go b/casdoorsdk/product_test.go index d306cdb..a30246d 100644 --- a/casdoorsdk/product_test.go +++ b/casdoorsdk/product_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestProduct(t *testing.T) { @@ -26,18 +25,18 @@ func TestProduct(t *testing.T) { // Add a new object product := &Product{ - Owner: "admin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - DisplayName: name, + Owner: "admin", + Name: name, + CreatedTime: GetCurrentTime(), + DisplayName: name, Image: "https://cdn.casbin.org/img/casdoor-logo_1185x256.png", - Description: "Casdoor Website", + Description: "Casdoor Website", Tag: "auto_created_product_for_plan", Quantity: 999, Sold: 0, - State: "Published", + State: "Published", } _, err := AddProduct(product) if err != nil { diff --git a/casdoorsdk/provider_test.go b/casdoorsdk/provider_test.go index c6dc76d..722b2de 100644 --- a/casdoorsdk/provider_test.go +++ b/casdoorsdk/provider_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestProvider(t *testing.T) { @@ -26,10 +25,10 @@ func TestProvider(t *testing.T) { // Add a new object provider := &Provider{ - Owner: "admin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - DisplayName: name, + Owner: "admin", + Name: name, + CreatedTime: GetCurrentTime(), + DisplayName: name, Category: "Captcha", Type: "Default", } diff --git a/casdoorsdk/resource_test.go b/casdoorsdk/resource_test.go index f38f927..5d8c521 100644 --- a/casdoorsdk/resource_test.go +++ b/casdoorsdk/resource_test.go @@ -19,7 +19,6 @@ import ( "io" "os" "testing" - "time" ) func (resource *Resource) GetId() string { @@ -46,7 +45,7 @@ func TestResource(t *testing.T) { resource := &Resource{ Owner: "casbin", Name: name, - CreatedTime: time.Now().Format(time.RFC3339), + CreatedTime: GetCurrentTime(), Description: "Casdoor Website", User: "casbin", FileName: filename, diff --git a/casdoorsdk/role_test.go b/casdoorsdk/role_test.go index 0ab7945..28d92e9 100644 --- a/casdoorsdk/role_test.go +++ b/casdoorsdk/role_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestRole(t *testing.T) { @@ -26,11 +25,11 @@ func TestRole(t *testing.T) { // Add a new object role := &Role{ - Owner: "admin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - DisplayName: name, - Description: "Casdoor Website", + Owner: "admin", + Name: name, + CreatedTime: GetCurrentTime(), + DisplayName: name, + Description: "Casdoor Website", } _, err := AddRole(role) if err != nil { diff --git a/casdoorsdk/session_test.go b/casdoorsdk/session_test.go index 47af76d..f2916e1 100644 --- a/casdoorsdk/session_test.go +++ b/casdoorsdk/session_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestSession(t *testing.T) { @@ -26,11 +25,11 @@ func TestSession(t *testing.T) { // Add a new object Session := &Session{ - Owner: "casbin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - Application: "app-built-in", - SessionId: []string{}, + Owner: "casbin", + Name: name, + CreatedTime: GetCurrentTime(), + Application: "app-built-in", + SessionId: []string{}, } _, err := AddSession(Session) if err != nil { @@ -63,7 +62,7 @@ func TestSession(t *testing.T) { } // Update the object - UpdateTime := time.Now().Format(time.RFC3339) + UpdateTime := GetCurrentTime() Session.CreatedTime = UpdateTime _, err = UpdateSession(Session) if err != nil { diff --git a/casdoorsdk/subscription_test.go b/casdoorsdk/subscription_test.go index 9843eb2..7fa3a20 100644 --- a/casdoorsdk/subscription_test.go +++ b/casdoorsdk/subscription_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestSubscription(t *testing.T) { @@ -26,11 +25,11 @@ func TestSubscription(t *testing.T) { // Add a new object subscription := &Subscription{ - Owner: "admin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - DisplayName: name, - Description: "Casdoor Website", + Owner: "admin", + Name: name, + CreatedTime: GetCurrentTime(), + DisplayName: name, + Description: "Casdoor Website", } _, err := AddSubscription(subscription) if err != nil { diff --git a/casdoorsdk/syncer_test.go b/casdoorsdk/syncer_test.go index 2ecffc9..77d5d79 100644 --- a/casdoorsdk/syncer_test.go +++ b/casdoorsdk/syncer_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestSyncer(t *testing.T) { @@ -28,7 +27,7 @@ func TestSyncer(t *testing.T) { Syncer := &Syncer{ Owner: "admin", Name: name, - CreatedTime: time.Now().Format(time.RFC3339), + CreatedTime: GetCurrentTime(), Organization: "casbin", Host: "localhost", Port: 3306, diff --git a/casdoorsdk/user_test.go b/casdoorsdk/user_test.go index aab9ce6..e41d86c 100644 --- a/casdoorsdk/user_test.go +++ b/casdoorsdk/user_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestUser(t *testing.T) { @@ -26,11 +25,10 @@ func TestUser(t *testing.T) { // Add a new object user := &User{ - Owner: "admin", - Name: name, - CreatedTime: time.Now().Format(time.RFC3339), - - DisplayName: name, + Owner: TestCasdoorOrganization, + Name: name, + CreatedTime: GetCurrentTime(), + DisplayName: name, } _, err := AddUser(user) if err != nil { diff --git a/casdoorsdk/util.go b/casdoorsdk/util.go index e853432..016e66f 100644 --- a/casdoorsdk/util.go +++ b/casdoorsdk/util.go @@ -20,6 +20,7 @@ import ( "io" "mime/multipart" "strings" + "time" ) func (c *Client) GetUrl(action string, queryMap map[string]string) string { @@ -73,3 +74,9 @@ func createForm(formData map[string]string) (string, io.Reader, error) { return w.FormDataContentType(), body, nil } + +func GetCurrentTime() string { + timestamp := time.Now().Unix() + tm := time.Unix(timestamp, 0) + return tm.Format(time.RFC3339) +} diff --git a/casdoorsdk/webhook_test.go b/casdoorsdk/webhook_test.go index 298883e..83b605a 100644 --- a/casdoorsdk/webhook_test.go +++ b/casdoorsdk/webhook_test.go @@ -16,7 +16,6 @@ package casdoorsdk import ( "testing" - "time" ) func TestWebhook(t *testing.T) { @@ -28,7 +27,7 @@ func TestWebhook(t *testing.T) { Webhook := &Webhook{ Owner: "casbin", Name: name, - CreatedTime: time.Now().Format(time.RFC3339), + CreatedTime: GetCurrentTime(), Organization: "casbin", } _, err := AddWebhook(Webhook)