diff --git a/CHANGELOG.md b/CHANGELOG.md index c6683fd4..c671ca1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## v2.1.0 + +* Added `GetHeaders` method to `Client` for retrieving current request headers +* Fixed chunked upload resume handling for responses returned as strings +* Updated Go module path to `v2` for proper Go modules compatibility + ## v2.0.0 * [BREAKING] Changed `$sequence` type from `int` to `string` for rows and documents diff --git a/README.md b/README.md index 4e1a34f2..a4d112c9 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ go mod init To install using `go get`: ```bash -go get github.com/appwrite/sdk-for-go +go get github.com/appwrite/sdk-for-go/v2 ``` ## Testing the SDK @@ -51,8 +51,8 @@ go get github.com/appwrite/sdk-for-go "os" "time" - "github.com/appwrite/sdk-for-go/appwrite" - "github.com/appwrite/sdk-for-go/id" + "github.com/appwrite/sdk-for-go/v2/appwrite" + "github.com/appwrite/sdk-for-go/v2/id" ) func main() { diff --git a/account/account.go b/account/account.go index fd68baaf..bf991db1 100644 --- a/account/account.go +++ b/account/account.go @@ -3,8 +3,8 @@ package account import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/account/account_test.go b/account/account_test.go new file mode 100644 index 00000000..d5a6f5d9 --- /dev/null +++ b/account/account_test.go @@ -0,0 +1,2107 @@ +package account + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestAccount(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get() + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test Create", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Create("", "email@example.com", "") + if err != nil { + t.Errorf("Method Create failed: %v", err) + } + }) + + t.Run("Test UpdateEmail", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateEmail("email@example.com", "password") + if err != nil { + t.Errorf("Method UpdateEmail failed: %v", err) + } + }) + + t.Run("Test ListIdentities", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "identities": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "provider": "email", + "providerUid": "5e5bb8c16897e", + "providerEmail": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListIdentities() + if err != nil { + t.Errorf("Method ListIdentities failed: %v", err) + } + }) + + t.Run("Test DeleteIdentity", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteIdentity("") + if err != nil { + t.Errorf("Method DeleteIdentity failed: %v", err) + } + }) + + t.Run("Test CreateJWT", func(t *testing.T) { + mockResponse := ` +{ + "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateJWT() + if err != nil { + t.Errorf("Method CreateJWT failed: %v", err) + } + }) + + t.Run("Test ListLogs", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "logs": [ + { + "event": "account.sessions.create", + "userId": "610fc2f985ee0", + "userEmail": "john@appwrite.io", + "userName": "John Doe", + "mode": "admin", + "ip": "127.0.0.1", + "time": "2020-10-15T06:38:00.000+00:00", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListLogs() + if err != nil { + t.Errorf("Method ListLogs failed: %v", err) + } + }) + + t.Run("Test UpdateMFA", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMFA(true) + if err != nil { + t.Errorf("Method UpdateMFA failed: %v", err) + } + }) + + t.Run("Test CreateMfaAuthenticator", func(t *testing.T) { + mockResponse := ` +{ + "secret": "[SHARED_SECRET]", + "uri": "otpauth://totp/appwrite:user@example.com?secret=[SHARED_SECRET]&issuer=appwrite" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMfaAuthenticator("totp") + if err != nil { + t.Errorf("Method CreateMfaAuthenticator failed: %v", err) + } + }) + + t.Run("Test CreateMFAAuthenticator", func(t *testing.T) { + mockResponse := ` +{ + "secret": "[SHARED_SECRET]", + "uri": "otpauth://totp/appwrite:user@example.com?secret=[SHARED_SECRET]&issuer=appwrite" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMFAAuthenticator("totp") + if err != nil { + t.Errorf("Method CreateMFAAuthenticator failed: %v", err) + } + }) + + t.Run("Test UpdateMfaAuthenticator", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMfaAuthenticator("totp", "") + if err != nil { + t.Errorf("Method UpdateMfaAuthenticator failed: %v", err) + } + }) + + t.Run("Test UpdateMFAAuthenticator", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMFAAuthenticator("totp", "") + if err != nil { + t.Errorf("Method UpdateMFAAuthenticator failed: %v", err) + } + }) + + t.Run("Test DeleteMfaAuthenticator", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteMfaAuthenticator("totp") + if err != nil { + t.Errorf("Method DeleteMfaAuthenticator failed: %v", err) + } + }) + + t.Run("Test DeleteMFAAuthenticator", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteMFAAuthenticator("totp") + if err != nil { + t.Errorf("Method DeleteMFAAuthenticator failed: %v", err) + } + }) + + t.Run("Test CreateMfaChallenge", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "expire": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMfaChallenge("email") + if err != nil { + t.Errorf("Method CreateMfaChallenge failed: %v", err) + } + }) + + t.Run("Test CreateMFAChallenge", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "expire": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMFAChallenge("email") + if err != nil { + t.Errorf("Method CreateMFAChallenge failed: %v", err) + } + }) + + t.Run("Test UpdateMfaChallenge", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMfaChallenge("", "") + if err != nil { + t.Errorf("Method UpdateMfaChallenge failed: %v", err) + } + }) + + t.Run("Test UpdateMFAChallenge", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMFAChallenge("", "") + if err != nil { + t.Errorf("Method UpdateMFAChallenge failed: %v", err) + } + }) + + t.Run("Test ListMfaFactors", func(t *testing.T) { + mockResponse := ` +{ + "totp": true, + "phone": true, + "email": true, + "recoveryCode": true +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListMfaFactors() + if err != nil { + t.Errorf("Method ListMfaFactors failed: %v", err) + } + }) + + t.Run("Test ListMFAFactors", func(t *testing.T) { + mockResponse := ` +{ + "totp": true, + "phone": true, + "email": true, + "recoveryCode": true +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListMFAFactors() + if err != nil { + t.Errorf("Method ListMFAFactors failed: %v", err) + } + }) + + t.Run("Test GetMfaRecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetMfaRecoveryCodes() + if err != nil { + t.Errorf("Method GetMfaRecoveryCodes failed: %v", err) + } + }) + + t.Run("Test GetMFARecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetMFARecoveryCodes() + if err != nil { + t.Errorf("Method GetMFARecoveryCodes failed: %v", err) + } + }) + + t.Run("Test CreateMfaRecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMfaRecoveryCodes() + if err != nil { + t.Errorf("Method CreateMfaRecoveryCodes failed: %v", err) + } + }) + + t.Run("Test CreateMFARecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMFARecoveryCodes() + if err != nil { + t.Errorf("Method CreateMFARecoveryCodes failed: %v", err) + } + }) + + t.Run("Test UpdateMfaRecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMfaRecoveryCodes() + if err != nil { + t.Errorf("Method UpdateMfaRecoveryCodes failed: %v", err) + } + }) + + t.Run("Test UpdateMFARecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMFARecoveryCodes() + if err != nil { + t.Errorf("Method UpdateMFARecoveryCodes failed: %v", err) + } + }) + + t.Run("Test UpdateName", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateName("") + if err != nil { + t.Errorf("Method UpdateName failed: %v", err) + } + }) + + t.Run("Test UpdatePassword", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePassword("") + if err != nil { + t.Errorf("Method UpdatePassword failed: %v", err) + } + }) + + t.Run("Test UpdatePhone", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePhone("+12065550100", "password") + if err != nil { + t.Errorf("Method UpdatePhone failed: %v", err) + } + }) + + t.Run("Test GetPrefs", func(t *testing.T) { + mockResponse := ` +{ +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetPrefs() + if err != nil { + t.Errorf("Method GetPrefs failed: %v", err) + } + }) + + t.Run("Test UpdatePrefs", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePrefs(map[string]interface{}{}) + if err != nil { + t.Errorf("Method UpdatePrefs failed: %v", err) + } + }) + + t.Run("Test CreateRecovery", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateRecovery("email@example.com", "https://example.com") + if err != nil { + t.Errorf("Method CreateRecovery failed: %v", err) + } + }) + + t.Run("Test UpdateRecovery", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateRecovery("", "", "") + if err != nil { + t.Errorf("Method UpdateRecovery failed: %v", err) + } + }) + + t.Run("Test ListSessions", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "sessions": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListSessions() + if err != nil { + t.Errorf("Method ListSessions failed: %v", err) + } + }) + + t.Run("Test DeleteSessions", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteSessions() + if err != nil { + t.Errorf("Method DeleteSessions failed: %v", err) + } + }) + + t.Run("Test CreateAnonymousSession", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateAnonymousSession() + if err != nil { + t.Errorf("Method CreateAnonymousSession failed: %v", err) + } + }) + + t.Run("Test CreateEmailPasswordSession", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateEmailPasswordSession("email@example.com", "password") + if err != nil { + t.Errorf("Method CreateEmailPasswordSession failed: %v", err) + } + }) + + t.Run("Test UpdateMagicURLSession", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMagicURLSession("", "") + if err != nil { + t.Errorf("Method UpdateMagicURLSession failed: %v", err) + } + }) + + t.Run("Test UpdatePhoneSession", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePhoneSession("", "") + if err != nil { + t.Errorf("Method UpdatePhoneSession failed: %v", err) + } + }) + + t.Run("Test CreateSession", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateSession("", "") + if err != nil { + t.Errorf("Method CreateSession failed: %v", err) + } + }) + + t.Run("Test GetSession", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetSession("") + if err != nil { + t.Errorf("Method GetSession failed: %v", err) + } + }) + + t.Run("Test UpdateSession", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSession("") + if err != nil { + t.Errorf("Method UpdateSession failed: %v", err) + } + }) + + t.Run("Test DeleteSession", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteSession("") + if err != nil { + t.Errorf("Method DeleteSession failed: %v", err) + } + }) + + t.Run("Test UpdateStatus", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateStatus() + if err != nil { + t.Errorf("Method UpdateStatus failed: %v", err) + } + }) + + t.Run("Test CreateEmailToken", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateEmailToken("", "email@example.com") + if err != nil { + t.Errorf("Method CreateEmailToken failed: %v", err) + } + }) + + t.Run("Test CreateMagicURLToken", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMagicURLToken("", "email@example.com") + if err != nil { + t.Errorf("Method CreateMagicURLToken failed: %v", err) + } + }) + + t.Run("Test CreateOAuth2Token", func(t *testing.T) { + mockResponse := `true` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateOAuth2Token("amazon") + if err != nil { + t.Errorf("Method CreateOAuth2Token failed: %v", err) + } + }) + + t.Run("Test CreatePhoneToken", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreatePhoneToken("", "+12065550100") + if err != nil { + t.Errorf("Method CreatePhoneToken failed: %v", err) + } + }) + + t.Run("Test CreateEmailVerification", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateEmailVerification("https://example.com") + if err != nil { + t.Errorf("Method CreateEmailVerification failed: %v", err) + } + }) + + t.Run("Test CreateVerification", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateVerification("https://example.com") + if err != nil { + t.Errorf("Method CreateVerification failed: %v", err) + } + }) + + t.Run("Test UpdateEmailVerification", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateEmailVerification("", "") + if err != nil { + t.Errorf("Method UpdateEmailVerification failed: %v", err) + } + }) + + t.Run("Test UpdateVerification", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateVerification("", "") + if err != nil { + t.Errorf("Method UpdateVerification failed: %v", err) + } + }) + + t.Run("Test CreatePhoneVerification", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreatePhoneVerification() + if err != nil { + t.Errorf("Method CreatePhoneVerification failed: %v", err) + } + }) + + t.Run("Test UpdatePhoneVerification", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePhoneVerification("", "") + if err != nil { + t.Errorf("Method UpdatePhoneVerification failed: %v", err) + } + }) +} diff --git a/activities/activities.go b/activities/activities.go index e22629e6..d927c5e3 100644 --- a/activities/activities.go +++ b/activities/activities.go @@ -3,8 +3,8 @@ package activities import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/activities/activities_test.go b/activities/activities_test.go new file mode 100644 index 00000000..a9f1bb1f --- /dev/null +++ b/activities/activities_test.go @@ -0,0 +1,137 @@ +package activities + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestActivities(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test ListEvents", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "events": [ + { + "$id": "5e5ea5c16897e", + "userType": "user", + "userId": "610fc2f985ee0", + "userEmail": "john@appwrite.io", + "userName": "John Doe", + "resourceParent": "database/ID", + "resourceType": "collection", + "resourceId": "610fc2f985ee0", + "resource": "collections/610fc2f985ee0", + "event": "account.sessions.create", + "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36", + "ip": "127.0.0.1", + "mode": "admin", + "country": "US", + "time": "2020-10-15T06:38:00.000+00:00", + "projectId": "610fc2f985ee0", + "teamId": "610fc2f985ee0", + "hostname": "appwrite.io", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListEvents() + if err != nil { + t.Errorf("Method ListEvents failed: %v", err) + } + }) + + t.Run("Test GetEvent", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "userType": "user", + "userId": "610fc2f985ee0", + "userEmail": "john@appwrite.io", + "userName": "John Doe", + "resourceParent": "database/ID", + "resourceType": "collection", + "resourceId": "610fc2f985ee0", + "resource": "collections/610fc2f985ee0", + "event": "account.sessions.create", + "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36", + "ip": "127.0.0.1", + "mode": "admin", + "country": "US", + "time": "2020-10-15T06:38:00.000+00:00", + "projectId": "610fc2f985ee0", + "teamId": "610fc2f985ee0", + "hostname": "appwrite.io", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetEvent("") + if err != nil { + t.Errorf("Method GetEvent failed: %v", err) + } + }) +} diff --git a/appwrite/appwrite.go b/appwrite/appwrite.go index 1f965dbb..08de7bc7 100644 --- a/appwrite/appwrite.go +++ b/appwrite/appwrite.go @@ -3,25 +3,25 @@ package appwrite import ( "time" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" - "github.com/appwrite/sdk-for-go/activities" - "github.com/appwrite/sdk-for-go/avatars" - "github.com/appwrite/sdk-for-go/backups" - "github.com/appwrite/sdk-for-go/databases" - "github.com/appwrite/sdk-for-go/functions" - "github.com/appwrite/sdk-for-go/graphql" - "github.com/appwrite/sdk-for-go/health" - "github.com/appwrite/sdk-for-go/locale" - "github.com/appwrite/sdk-for-go/messaging" - "github.com/appwrite/sdk-for-go/project" - "github.com/appwrite/sdk-for-go/sites" - "github.com/appwrite/sdk-for-go/storage" - "github.com/appwrite/sdk-for-go/tablesdb" - "github.com/appwrite/sdk-for-go/teams" - "github.com/appwrite/sdk-for-go/tokens" - "github.com/appwrite/sdk-for-go/users" - "github.com/appwrite/sdk-for-go/webhooks" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" + "github.com/appwrite/sdk-for-go/v2/activities" + "github.com/appwrite/sdk-for-go/v2/avatars" + "github.com/appwrite/sdk-for-go/v2/backups" + "github.com/appwrite/sdk-for-go/v2/databases" + "github.com/appwrite/sdk-for-go/v2/functions" + "github.com/appwrite/sdk-for-go/v2/graphql" + "github.com/appwrite/sdk-for-go/v2/health" + "github.com/appwrite/sdk-for-go/v2/locale" + "github.com/appwrite/sdk-for-go/v2/messaging" + "github.com/appwrite/sdk-for-go/v2/project" + "github.com/appwrite/sdk-for-go/v2/sites" + "github.com/appwrite/sdk-for-go/v2/storage" + "github.com/appwrite/sdk-for-go/v2/tablesdb" + "github.com/appwrite/sdk-for-go/v2/teams" + "github.com/appwrite/sdk-for-go/v2/tokens" + "github.com/appwrite/sdk-for-go/v2/users" + "github.com/appwrite/sdk-for-go/v2/webhooks" ) func NewAccount(clt client.Client) *account.Account { diff --git a/avatars/avatars.go b/avatars/avatars.go index 4027c4de..651f9884 100644 --- a/avatars/avatars.go +++ b/avatars/avatars.go @@ -3,7 +3,7 @@ package avatars import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/v2/client" "net/url" "fmt" "strings" diff --git a/avatars/avatars_test.go b/avatars/avatars_test.go new file mode 100644 index 00000000..8de3f683 --- /dev/null +++ b/avatars/avatars_test.go @@ -0,0 +1,194 @@ +package avatars + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestAvatars(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test GetBrowser", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetBrowser("aa") + if err != nil { + t.Errorf("Method GetBrowser failed: %v", err) + } + }) + + t.Run("Test GetCreditCard", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetCreditCard("amex") + if err != nil { + t.Errorf("Method GetCreditCard failed: %v", err) + } + }) + + t.Run("Test GetFavicon", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetFavicon("https://example.com") + if err != nil { + t.Errorf("Method GetFavicon failed: %v", err) + } + }) + + t.Run("Test GetFlag", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetFlag("af") + if err != nil { + t.Errorf("Method GetFlag failed: %v", err) + } + }) + + t.Run("Test GetImage", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetImage("https://example.com") + if err != nil { + t.Errorf("Method GetImage failed: %v", err) + } + }) + + t.Run("Test GetInitials", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetInitials() + if err != nil { + t.Errorf("Method GetInitials failed: %v", err) + } + }) + + t.Run("Test GetQR", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQR("") + if err != nil { + t.Errorf("Method GetQR failed: %v", err) + } + }) + + t.Run("Test GetScreenshot", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetScreenshot("https://example.com") + if err != nil { + t.Errorf("Method GetScreenshot failed: %v", err) + } + }) +} diff --git a/backups/backups.go b/backups/backups.go index 9a66beaf..6c9a4818 100644 --- a/backups/backups.go +++ b/backups/backups.go @@ -3,8 +3,8 @@ package backups import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/backups/backups_test.go b/backups/backups_test.go new file mode 100644 index 00000000..cd85e92a --- /dev/null +++ b/backups/backups_test.go @@ -0,0 +1,434 @@ +package backups + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestBackups(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test ListArchives", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "archives": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "policyId": "did8jx6ws45jana098ab7", + "size": 100000, + "status": "completed", + "startedAt": "2020-10-15T06:38:00.000+00:00", + "migrationId": "did8jx6ws45jana098ab7", + "services": [], + "resources": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListArchives() + if err != nil { + t.Errorf("Method ListArchives failed: %v", err) + } + }) + + t.Run("Test CreateArchive", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "policyId": "did8jx6ws45jana098ab7", + "size": 100000, + "status": "completed", + "startedAt": "2020-10-15T06:38:00.000+00:00", + "migrationId": "did8jx6ws45jana098ab7", + "services": [], + "resources": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateArchive([]string{}) + if err != nil { + t.Errorf("Method CreateArchive failed: %v", err) + } + }) + + t.Run("Test GetArchive", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "policyId": "did8jx6ws45jana098ab7", + "size": 100000, + "status": "completed", + "startedAt": "2020-10-15T06:38:00.000+00:00", + "migrationId": "did8jx6ws45jana098ab7", + "services": [], + "resources": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetArchive("") + if err != nil { + t.Errorf("Method GetArchive failed: %v", err) + } + }) + + t.Run("Test DeleteArchive", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteArchive("") + if err != nil { + t.Errorf("Method DeleteArchive failed: %v", err) + } + }) + + t.Run("Test ListPolicies", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "policies": [ + { + "$id": "5e5ea5c16897e", + "name": "Hourly backups", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "services": [], + "resources": [], + "retention": 7, + "schedule": "0 * * * *", + "enabled": true + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListPolicies() + if err != nil { + t.Errorf("Method ListPolicies failed: %v", err) + } + }) + + t.Run("Test CreatePolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "name": "Hourly backups", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "services": [], + "resources": [], + "retention": 7, + "schedule": "0 * * * *", + "enabled": true +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreatePolicy("", []string{}, 1, "") + if err != nil { + t.Errorf("Method CreatePolicy failed: %v", err) + } + }) + + t.Run("Test GetPolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "name": "Hourly backups", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "services": [], + "resources": [], + "retention": 7, + "schedule": "0 * * * *", + "enabled": true +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetPolicy("") + if err != nil { + t.Errorf("Method GetPolicy failed: %v", err) + } + }) + + t.Run("Test UpdatePolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "name": "Hourly backups", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "services": [], + "resources": [], + "retention": 7, + "schedule": "0 * * * *", + "enabled": true +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePolicy("") + if err != nil { + t.Errorf("Method UpdatePolicy failed: %v", err) + } + }) + + t.Run("Test DeletePolicy", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeletePolicy("") + if err != nil { + t.Errorf("Method DeletePolicy failed: %v", err) + } + }) + + t.Run("Test CreateRestoration", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "archiveId": "did8jx6ws45jana098ab7", + "policyId": "did8jx6ws45jana098ab7", + "status": "completed", + "startedAt": "2020-10-15T06:38:00.000+00:00", + "migrationId": "did8jx6ws45jana098ab7", + "services": [], + "resources": [], + "options": "{databases.database[{oldId, newId, newName}]}" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateRestoration("", []string{}) + if err != nil { + t.Errorf("Method CreateRestoration failed: %v", err) + } + }) + + t.Run("Test ListRestorations", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "restorations": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "archiveId": "did8jx6ws45jana098ab7", + "policyId": "did8jx6ws45jana098ab7", + "status": "completed", + "startedAt": "2020-10-15T06:38:00.000+00:00", + "migrationId": "did8jx6ws45jana098ab7", + "services": [], + "resources": [], + "options": "{databases.database[{oldId, newId, newName}]}" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListRestorations() + if err != nil { + t.Errorf("Method ListRestorations failed: %v", err) + } + }) + + t.Run("Test GetRestoration", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "archiveId": "did8jx6ws45jana098ab7", + "policyId": "did8jx6ws45jana098ab7", + "status": "completed", + "startedAt": "2020-10-15T06:38:00.000+00:00", + "migrationId": "did8jx6ws45jana098ab7", + "services": [], + "resources": [], + "options": "{databases.database[{oldId, newId, newName}]}" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetRestoration("") + if err != nil { + t.Errorf("Method GetRestoration failed: %v", err) + } + }) +} diff --git a/client/client.go b/client/client.go index 0cf9bb3e..6435ad9a 100644 --- a/client/client.go +++ b/client/client.go @@ -19,7 +19,7 @@ import ( "time" "runtime" - "github.com/appwrite/sdk-for-go/file" + "github.com/appwrite/sdk-for-go/v2/file" ) const ( @@ -74,11 +74,11 @@ type Client struct { func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ "X-Appwrite-Response-Format" : "1.9.0", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/v2.0.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "user-agent" : fmt.Sprintf("AppwriteGoSDK/v2.1.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "v2.0.0", + "x-sdk-version": "v2.1.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { @@ -125,6 +125,16 @@ func (client *Client) AddHeader(key string, value string) { client.Headers[key] = value } +// GetHeaders returns a copy of the client's current request headers +func (client *Client) GetHeaders() map[string]string { + headers := make(map[string]string, len(client.Headers)) + for key, value := range client.Headers { + headers[key] = value + } + + return headers +} + // GetEndpoint returns the client's current endpoint func (client *Client) GetEndpoint() string { return client.Endpoint @@ -168,7 +178,15 @@ func (client *Client) FileUpload(url string, headers map[string]interface{}, par if uploadId != "" { resp, err := client.Call("GET", url+"/"+uploadId, nil, nil) if err == nil { - currentChunk = int64(resp.Result.(map[string]interface{})["chunksUploaded"].(float64)) + var result map[string]interface{} + if resStr, ok := resp.Result.(string); ok { + _ = json.Unmarshal([]byte(resStr), &result) + } else { + result, _ = resp.Result.(map[string]interface{}) + } + if result != nil && result["chunksUploaded"] != nil { + currentChunk = int64(result["chunksUploaded"].(float64)) + } } } diff --git a/client/client_test.go b/client/client_test.go new file mode 100644 index 00000000..5f6b7d19 --- /dev/null +++ b/client/client_test.go @@ -0,0 +1,37 @@ +package client + +import ( + "testing" +) + +func TestSetProject(t *testing.T) { + c := New() + c.Headers["x-appwrite-project"] = "test_project" + if c.Headers["x-appwrite-project"] != "test_project" { + t.Errorf("Expected test_project, got %s", c.Headers["x-appwrite-project"]) + } +} + +func TestSetEndPoint(t *testing.T) { + c := New() + c.Endpoint = "https://example.com/v1" + if c.Endpoint != "https://example.com/v1" { + t.Errorf("Expected https://example.com/v1, got %s", c.Endpoint) + } +} + +func TestAddHeader(t *testing.T) { + c := New() + c.AddHeader("custom", "value") + if c.Headers["custom"] != "value" { + t.Errorf("Expected value, got %s", c.Headers["custom"]) + } +} + +func TestSetSelfSigned(t *testing.T) { + c := New() + c.SelfSigned = true + if !c.SelfSigned { + t.Errorf("Expected SelfSigned to be true") + } +} diff --git a/databases/databases.go b/databases/databases.go index 70830c2a..d15ea948 100644 --- a/databases/databases.go +++ b/databases/databases.go @@ -3,8 +3,8 @@ package databases import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/databases/databases_test.go b/databases/databases_test.go new file mode 100644 index 00000000..fa62bf8b --- /dev/null +++ b/databases/databases_test.go @@ -0,0 +1,2487 @@ +package databases + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestDatabases(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test List", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "databases": [ + { + "$id": "5e5ea5c16897e", + "name": "My Database", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "enabled": true, + "type": "legacy", + "policies": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "archives": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 + } + ] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.List() + if err != nil { + t.Errorf("Method List failed: %v", err) + } + }) + + t.Run("Test Create", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "name": "My Database", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "enabled": true, + "type": "legacy", + "policies": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "archives": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Create("", "") + if err != nil { + t.Errorf("Method Create failed: %v", err) + } + }) + + t.Run("Test ListTransactions", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "transactions": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "status": "pending", + "operations": 5, + "expiresAt": "2020-10-15T06:38:00.000+00:00" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListTransactions() + if err != nil { + t.Errorf("Method ListTransactions failed: %v", err) + } + }) + + t.Run("Test CreateTransaction", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "status": "pending", + "operations": 5, + "expiresAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTransaction() + if err != nil { + t.Errorf("Method CreateTransaction failed: %v", err) + } + }) + + t.Run("Test GetTransaction", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "status": "pending", + "operations": 5, + "expiresAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetTransaction("") + if err != nil { + t.Errorf("Method GetTransaction failed: %v", err) + } + }) + + t.Run("Test UpdateTransaction", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "status": "pending", + "operations": 5, + "expiresAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateTransaction("") + if err != nil { + t.Errorf("Method UpdateTransaction failed: %v", err) + } + }) + + t.Run("Test DeleteTransaction", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteTransaction("") + if err != nil { + t.Errorf("Method DeleteTransaction failed: %v", err) + } + }) + + t.Run("Test CreateOperations", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "status": "pending", + "operations": 5, + "expiresAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateOperations("") + if err != nil { + t.Errorf("Method CreateOperations failed: %v", err) + } + }) + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "name": "My Database", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "enabled": true, + "type": "legacy", + "policies": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "archives": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get("") + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test Update", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "name": "My Database", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "enabled": true, + "type": "legacy", + "policies": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "archives": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Update("") + if err != nil { + t.Errorf("Method Update failed: %v", err) + } + }) + + t.Run("Test Delete", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Delete("") + if err != nil { + t.Errorf("Method Delete failed: %v", err) + } + }) + + t.Run("Test ListCollections", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "collections": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListCollections("") + if err != nil { + t.Errorf("Method ListCollections failed: %v", err) + } + }) + + t.Run("Test CreateCollection", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateCollection("", "", "") + if err != nil { + t.Errorf("Method CreateCollection failed: %v", err) + } + }) + + t.Run("Test GetCollection", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetCollection("", "") + if err != nil { + t.Errorf("Method GetCollection failed: %v", err) + } + }) + + t.Run("Test UpdateCollection", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateCollection("", "") + if err != nil { + t.Errorf("Method UpdateCollection failed: %v", err) + } + }) + + t.Run("Test DeleteCollection", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteCollection("", "") + if err != nil { + t.Errorf("Method DeleteCollection failed: %v", err) + } + }) + + t.Run("Test ListAttributes", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "attributes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListAttributes("", "") + if err != nil { + t.Errorf("Method ListAttributes failed: %v", err) + } + }) + + t.Run("Test CreateBooleanAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "isEnabled", + "type": "boolean", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateBooleanAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateBooleanAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateBooleanAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "isEnabled", + "type": "boolean", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateBooleanAttribute("", "", "", true, true) + if err != nil { + t.Errorf("Method UpdateBooleanAttribute failed: %v", err) + } + }) + + t.Run("Test CreateDatetimeAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "birthDay", + "type": "datetime", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "datetime" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateDatetimeAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateDatetimeAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateDatetimeAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "birthDay", + "type": "datetime", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "datetime" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateDatetimeAttribute("", "", "", true, "2020-10-15T06:38:00.000+00:00") + if err != nil { + t.Errorf("Method UpdateDatetimeAttribute failed: %v", err) + } + }) + + t.Run("Test CreateEmailAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "userEmail", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "email" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateEmailAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateEmailAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateEmailAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "userEmail", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "email" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateEmailAttribute("", "", "", true, "email@example.com") + if err != nil { + t.Errorf("Method UpdateEmailAttribute failed: %v", err) + } + }) + + t.Run("Test CreateEnumAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "status", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "elements": [], + "format": "enum" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateEnumAttribute("", "", "", []string{}, true) + if err != nil { + t.Errorf("Method CreateEnumAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateEnumAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "status", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "elements": [], + "format": "enum" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateEnumAttribute("", "", "", []string{}, true, "") + if err != nil { + t.Errorf("Method UpdateEnumAttribute failed: %v", err) + } + }) + + t.Run("Test CreateFloatAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "percentageCompleted", + "type": "double", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateFloatAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateFloatAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateFloatAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "percentageCompleted", + "type": "double", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateFloatAttribute("", "", "", true, 1.0) + if err != nil { + t.Errorf("Method UpdateFloatAttribute failed: %v", err) + } + }) + + t.Run("Test CreateIntegerAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "count", + "type": "integer", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateIntegerAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateIntegerAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateIntegerAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "count", + "type": "integer", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateIntegerAttribute("", "", "", true, 1) + if err != nil { + t.Errorf("Method UpdateIntegerAttribute failed: %v", err) + } + }) + + t.Run("Test CreateIpAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "ipAddress", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "ip" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateIpAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateIpAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateIpAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "ipAddress", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "ip" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateIpAttribute("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateIpAttribute failed: %v", err) + } + }) + + t.Run("Test CreateLineAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateLineAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateLineAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateLineAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateLineAttribute("", "", "", true) + if err != nil { + t.Errorf("Method UpdateLineAttribute failed: %v", err) + } + }) + + t.Run("Test CreateLongtextAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateLongtextAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateLongtextAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateLongtextAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateLongtextAttribute("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateLongtextAttribute failed: %v", err) + } + }) + + t.Run("Test CreateMediumtextAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMediumtextAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateMediumtextAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateMediumtextAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMediumtextAttribute("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateMediumtextAttribute failed: %v", err) + } + }) + + t.Run("Test CreatePointAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreatePointAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreatePointAttribute failed: %v", err) + } + }) + + t.Run("Test UpdatePointAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePointAttribute("", "", "", true) + if err != nil { + t.Errorf("Method UpdatePointAttribute failed: %v", err) + } + }) + + t.Run("Test CreatePolygonAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreatePolygonAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreatePolygonAttribute failed: %v", err) + } + }) + + t.Run("Test UpdatePolygonAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePolygonAttribute("", "", "", true) + if err != nil { + t.Errorf("Method UpdatePolygonAttribute failed: %v", err) + } + }) + + t.Run("Test CreateRelationshipAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "relatedCollection": "collection", + "relationType": "oneToOne|oneToMany|manyToOne|manyToMany", + "twoWay": true, + "twoWayKey": "string", + "onDelete": "restrict|cascade|setNull", + "side": "parent|child" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateRelationshipAttribute("", "", "", "oneToOne") + if err != nil { + t.Errorf("Method CreateRelationshipAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateRelationshipAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "relatedCollection": "collection", + "relationType": "oneToOne|oneToMany|manyToOne|manyToMany", + "twoWay": true, + "twoWayKey": "string", + "onDelete": "restrict|cascade|setNull", + "side": "parent|child" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateRelationshipAttribute("", "", "") + if err != nil { + t.Errorf("Method UpdateRelationshipAttribute failed: %v", err) + } + }) + + t.Run("Test CreateStringAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "size": 128 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateStringAttribute("", "", "", 1, true) + if err != nil { + t.Errorf("Method CreateStringAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateStringAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "size": 128 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateStringAttribute("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateStringAttribute failed: %v", err) + } + }) + + t.Run("Test CreateTextAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTextAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateTextAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateTextAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateTextAttribute("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateTextAttribute failed: %v", err) + } + }) + + t.Run("Test CreateUrlAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "githubUrl", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "url" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateUrlAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateUrlAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateUrlAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "githubUrl", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "url" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateUrlAttribute("", "", "", true, "https://example.com") + if err != nil { + t.Errorf("Method UpdateUrlAttribute failed: %v", err) + } + }) + + t.Run("Test CreateVarcharAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "size": 128 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateVarcharAttribute("", "", "", 1, true) + if err != nil { + t.Errorf("Method CreateVarcharAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateVarcharAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "size": 128 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateVarcharAttribute("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateVarcharAttribute failed: %v", err) + } + }) + + t.Run("Test GetAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "isEnabled", + "type": "boolean", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetAttribute("", "", "") + if err != nil { + t.Errorf("Method GetAttribute failed: %v", err) + } + }) + + t.Run("Test DeleteAttribute", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteAttribute("", "", "") + if err != nil { + t.Errorf("Method DeleteAttribute failed: %v", err) + } + }) + + t.Run("Test ListDocuments", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "documents": [ + { + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$collectionId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListDocuments("", "") + if err != nil { + t.Errorf("Method ListDocuments failed: %v", err) + } + }) + + t.Run("Test CreateDocument", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$collectionId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateDocument("", "", "", map[string]interface{}{}) + if err != nil { + t.Errorf("Method CreateDocument failed: %v", err) + } + }) + + t.Run("Test CreateDocuments", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "documents": [ + { + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$collectionId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateDocuments("", "", []interface{}{}) + if err != nil { + t.Errorf("Method CreateDocuments failed: %v", err) + } + }) + + t.Run("Test UpsertDocuments", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "documents": [ + { + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$collectionId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpsertDocuments("", "", []interface{}{}) + if err != nil { + t.Errorf("Method UpsertDocuments failed: %v", err) + } + }) + + t.Run("Test UpdateDocuments", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "documents": [ + { + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$collectionId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateDocuments("", "") + if err != nil { + t.Errorf("Method UpdateDocuments failed: %v", err) + } + }) + + t.Run("Test DeleteDocuments", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "documents": [ + { + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$collectionId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteDocuments("", "") + if err != nil { + t.Errorf("Method DeleteDocuments failed: %v", err) + } + }) + + t.Run("Test GetDocument", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$collectionId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetDocument("", "", "") + if err != nil { + t.Errorf("Method GetDocument failed: %v", err) + } + }) + + t.Run("Test UpsertDocument", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$collectionId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpsertDocument("", "", "") + if err != nil { + t.Errorf("Method UpsertDocument failed: %v", err) + } + }) + + t.Run("Test UpdateDocument", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$collectionId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateDocument("", "", "") + if err != nil { + t.Errorf("Method UpdateDocument failed: %v", err) + } + }) + + t.Run("Test DeleteDocument", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteDocument("", "", "") + if err != nil { + t.Errorf("Method DeleteDocument failed: %v", err) + } + }) + + t.Run("Test DecrementDocumentAttribute", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$collectionId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DecrementDocumentAttribute("", "", "", "") + if err != nil { + t.Errorf("Method DecrementDocumentAttribute failed: %v", err) + } + }) + + t.Run("Test IncrementDocumentAttribute", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$collectionId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.IncrementDocumentAttribute("", "", "", "") + if err != nil { + t.Errorf("Method IncrementDocumentAttribute failed: %v", err) + } + }) + + t.Run("Test ListIndexes", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListIndexes("", "") + if err != nil { + t.Errorf("Method ListIndexes failed: %v", err) + } + }) + + t.Run("Test CreateIndex", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateIndex("", "", "", "key", []string{}) + if err != nil { + t.Errorf("Method CreateIndex failed: %v", err) + } + }) + + t.Run("Test GetIndex", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetIndex("", "", "") + if err != nil { + t.Errorf("Method GetIndex failed: %v", err) + } + }) + + t.Run("Test DeleteIndex", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteIndex("", "", "") + if err != nil { + t.Errorf("Method DeleteIndex failed: %v", err) + } + }) +} diff --git a/docs/examples/account/create-anonymous-session.md b/docs/examples/account/create-anonymous-session.md index 70f055ab..4a5e2c17 100644 --- a/docs/examples/account/create-anonymous-session.md +++ b/docs/examples/account/create-anonymous-session.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-email-password-session.md b/docs/examples/account/create-email-password-session.md index 5a220ccf..84c58943 100644 --- a/docs/examples/account/create-email-password-session.md +++ b/docs/examples/account/create-email-password-session.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-email-token.md b/docs/examples/account/create-email-token.md index d544f3a0..d7dd31cb 100644 --- a/docs/examples/account/create-email-token.md +++ b/docs/examples/account/create-email-token.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-email-verification.md b/docs/examples/account/create-email-verification.md index 76164f04..4e1ccb75 100644 --- a/docs/examples/account/create-email-verification.md +++ b/docs/examples/account/create-email-verification.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-jwt.md b/docs/examples/account/create-jwt.md index 6ebd9cde..64bfd0b3 100644 --- a/docs/examples/account/create-jwt.md +++ b/docs/examples/account/create-jwt.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-magic-url-token.md b/docs/examples/account/create-magic-url-token.md index 972bd0d7..24f34c8c 100644 --- a/docs/examples/account/create-magic-url-token.md +++ b/docs/examples/account/create-magic-url-token.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-mfa-authenticator.md b/docs/examples/account/create-mfa-authenticator.md index 05c5a17e..e387c34b 100644 --- a/docs/examples/account/create-mfa-authenticator.md +++ b/docs/examples/account/create-mfa-authenticator.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-mfa-challenge.md b/docs/examples/account/create-mfa-challenge.md index 7aee4c42..c7741587 100644 --- a/docs/examples/account/create-mfa-challenge.md +++ b/docs/examples/account/create-mfa-challenge.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-mfa-recovery-codes.md b/docs/examples/account/create-mfa-recovery-codes.md index a5744906..9c2f26ea 100644 --- a/docs/examples/account/create-mfa-recovery-codes.md +++ b/docs/examples/account/create-mfa-recovery-codes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-o-auth-2-token.md b/docs/examples/account/create-o-auth-2-token.md index 82b56a38..a11218bb 100644 --- a/docs/examples/account/create-o-auth-2-token.md +++ b/docs/examples/account/create-o-auth-2-token.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-phone-token.md b/docs/examples/account/create-phone-token.md index a652a687..8e4e806a 100644 --- a/docs/examples/account/create-phone-token.md +++ b/docs/examples/account/create-phone-token.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-phone-verification.md b/docs/examples/account/create-phone-verification.md index 391e9f20..ddb5906f 100644 --- a/docs/examples/account/create-phone-verification.md +++ b/docs/examples/account/create-phone-verification.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-recovery.md b/docs/examples/account/create-recovery.md index 64d2746f..e1d3af24 100644 --- a/docs/examples/account/create-recovery.md +++ b/docs/examples/account/create-recovery.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-session.md b/docs/examples/account/create-session.md index fdaf0f15..a98aefb3 100644 --- a/docs/examples/account/create-session.md +++ b/docs/examples/account/create-session.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create-verification.md b/docs/examples/account/create-verification.md index 05e52439..f7eb0436 100644 --- a/docs/examples/account/create-verification.md +++ b/docs/examples/account/create-verification.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/create.md b/docs/examples/account/create.md index c3d3cca1..b07bae54 100644 --- a/docs/examples/account/create.md +++ b/docs/examples/account/create.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/delete-identity.md b/docs/examples/account/delete-identity.md index d32b01c6..3d310fee 100644 --- a/docs/examples/account/delete-identity.md +++ b/docs/examples/account/delete-identity.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/delete-mfa-authenticator.md b/docs/examples/account/delete-mfa-authenticator.md index af82bdf2..814750d1 100644 --- a/docs/examples/account/delete-mfa-authenticator.md +++ b/docs/examples/account/delete-mfa-authenticator.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/delete-session.md b/docs/examples/account/delete-session.md index ca7dabab..f605768b 100644 --- a/docs/examples/account/delete-session.md +++ b/docs/examples/account/delete-session.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/delete-sessions.md b/docs/examples/account/delete-sessions.md index 17d27c05..6a32f18b 100644 --- a/docs/examples/account/delete-sessions.md +++ b/docs/examples/account/delete-sessions.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/get-mfa-recovery-codes.md b/docs/examples/account/get-mfa-recovery-codes.md index 1b8a22c1..e38eb105 100644 --- a/docs/examples/account/get-mfa-recovery-codes.md +++ b/docs/examples/account/get-mfa-recovery-codes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/get-prefs.md b/docs/examples/account/get-prefs.md index a93364ae..e9ca50b6 100644 --- a/docs/examples/account/get-prefs.md +++ b/docs/examples/account/get-prefs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/get-session.md b/docs/examples/account/get-session.md index e966b0f0..a0d55360 100644 --- a/docs/examples/account/get-session.md +++ b/docs/examples/account/get-session.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/get.md b/docs/examples/account/get.md index 39a563ef..ca5373d4 100644 --- a/docs/examples/account/get.md +++ b/docs/examples/account/get.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/list-identities.md b/docs/examples/account/list-identities.md index 7a5a1cd7..c52f89a5 100644 --- a/docs/examples/account/list-identities.md +++ b/docs/examples/account/list-identities.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/list-logs.md b/docs/examples/account/list-logs.md index f823c9c7..a92ee938 100644 --- a/docs/examples/account/list-logs.md +++ b/docs/examples/account/list-logs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/list-mfa-factors.md b/docs/examples/account/list-mfa-factors.md index 0176a4bb..f8a0fcde 100644 --- a/docs/examples/account/list-mfa-factors.md +++ b/docs/examples/account/list-mfa-factors.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/list-sessions.md b/docs/examples/account/list-sessions.md index 55ae24ba..9d2fc075 100644 --- a/docs/examples/account/list-sessions.md +++ b/docs/examples/account/list-sessions.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-email-verification.md b/docs/examples/account/update-email-verification.md index bbd504ee..aed8c239 100644 --- a/docs/examples/account/update-email-verification.md +++ b/docs/examples/account/update-email-verification.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-email.md b/docs/examples/account/update-email.md index 180c152c..6e00f331 100644 --- a/docs/examples/account/update-email.md +++ b/docs/examples/account/update-email.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-magic-url-session.md b/docs/examples/account/update-magic-url-session.md index c47f048a..ef196a03 100644 --- a/docs/examples/account/update-magic-url-session.md +++ b/docs/examples/account/update-magic-url-session.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-mfa-authenticator.md b/docs/examples/account/update-mfa-authenticator.md index 334affda..d533ffe2 100644 --- a/docs/examples/account/update-mfa-authenticator.md +++ b/docs/examples/account/update-mfa-authenticator.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-mfa-challenge.md b/docs/examples/account/update-mfa-challenge.md index 6c666d10..cbe8b6dc 100644 --- a/docs/examples/account/update-mfa-challenge.md +++ b/docs/examples/account/update-mfa-challenge.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-mfa-recovery-codes.md b/docs/examples/account/update-mfa-recovery-codes.md index 1a6f4790..87b1cf4e 100644 --- a/docs/examples/account/update-mfa-recovery-codes.md +++ b/docs/examples/account/update-mfa-recovery-codes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-mfa.md b/docs/examples/account/update-mfa.md index 31c21c50..3b0f0e3f 100644 --- a/docs/examples/account/update-mfa.md +++ b/docs/examples/account/update-mfa.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-name.md b/docs/examples/account/update-name.md index ef827ed0..a4e9145b 100644 --- a/docs/examples/account/update-name.md +++ b/docs/examples/account/update-name.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-password.md b/docs/examples/account/update-password.md index 66badad5..79626eed 100644 --- a/docs/examples/account/update-password.md +++ b/docs/examples/account/update-password.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-phone-session.md b/docs/examples/account/update-phone-session.md index 1fb33a77..7e10a146 100644 --- a/docs/examples/account/update-phone-session.md +++ b/docs/examples/account/update-phone-session.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-phone-verification.md b/docs/examples/account/update-phone-verification.md index 1c1dcbf9..3923f789 100644 --- a/docs/examples/account/update-phone-verification.md +++ b/docs/examples/account/update-phone-verification.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-phone.md b/docs/examples/account/update-phone.md index 92e4634e..d9979ca1 100644 --- a/docs/examples/account/update-phone.md +++ b/docs/examples/account/update-phone.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-prefs.md b/docs/examples/account/update-prefs.md index 0b18e513..079ae1e8 100644 --- a/docs/examples/account/update-prefs.md +++ b/docs/examples/account/update-prefs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-recovery.md b/docs/examples/account/update-recovery.md index 1222f597..a62e8888 100644 --- a/docs/examples/account/update-recovery.md +++ b/docs/examples/account/update-recovery.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-session.md b/docs/examples/account/update-session.md index 22ef7fa9..dc8ec84a 100644 --- a/docs/examples/account/update-session.md +++ b/docs/examples/account/update-session.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-status.md b/docs/examples/account/update-status.md index f2900504..2ab7c13b 100644 --- a/docs/examples/account/update-status.md +++ b/docs/examples/account/update-status.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/account/update-verification.md b/docs/examples/account/update-verification.md index a8e0c5a5..0de6aa3c 100644 --- a/docs/examples/account/update-verification.md +++ b/docs/examples/account/update-verification.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/account" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/account" ) client := client.New( diff --git a/docs/examples/activities/get-event.md b/docs/examples/activities/get-event.md index f392366c..f9478d9c 100644 --- a/docs/examples/activities/get-event.md +++ b/docs/examples/activities/get-event.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/activities" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/activities" ) client := client.New( diff --git a/docs/examples/activities/list-events.md b/docs/examples/activities/list-events.md index f5a165a4..60653038 100644 --- a/docs/examples/activities/list-events.md +++ b/docs/examples/activities/list-events.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/activities" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/activities" ) client := client.New( diff --git a/docs/examples/avatars/get-browser.md b/docs/examples/avatars/get-browser.md index ea675f08..e3b1595f 100644 --- a/docs/examples/avatars/get-browser.md +++ b/docs/examples/avatars/get-browser.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/avatars" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/avatars" ) client := client.New( diff --git a/docs/examples/avatars/get-credit-card.md b/docs/examples/avatars/get-credit-card.md index f11ccaef..71cad026 100644 --- a/docs/examples/avatars/get-credit-card.md +++ b/docs/examples/avatars/get-credit-card.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/avatars" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/avatars" ) client := client.New( diff --git a/docs/examples/avatars/get-favicon.md b/docs/examples/avatars/get-favicon.md index d341e3dd..b02741c1 100644 --- a/docs/examples/avatars/get-favicon.md +++ b/docs/examples/avatars/get-favicon.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/avatars" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/avatars" ) client := client.New( diff --git a/docs/examples/avatars/get-flag.md b/docs/examples/avatars/get-flag.md index f08a8639..58c01886 100644 --- a/docs/examples/avatars/get-flag.md +++ b/docs/examples/avatars/get-flag.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/avatars" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/avatars" ) client := client.New( diff --git a/docs/examples/avatars/get-image.md b/docs/examples/avatars/get-image.md index 6b237773..57be5763 100644 --- a/docs/examples/avatars/get-image.md +++ b/docs/examples/avatars/get-image.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/avatars" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/avatars" ) client := client.New( diff --git a/docs/examples/avatars/get-initials.md b/docs/examples/avatars/get-initials.md index 5dbd77d9..a226a56c 100644 --- a/docs/examples/avatars/get-initials.md +++ b/docs/examples/avatars/get-initials.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/avatars" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/avatars" ) client := client.New( diff --git a/docs/examples/avatars/get-qr.md b/docs/examples/avatars/get-qr.md index e0e5d874..291ca0ca 100644 --- a/docs/examples/avatars/get-qr.md +++ b/docs/examples/avatars/get-qr.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/avatars" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/avatars" ) client := client.New( diff --git a/docs/examples/avatars/get-screenshot.md b/docs/examples/avatars/get-screenshot.md index 784a96a5..cc9561ad 100644 --- a/docs/examples/avatars/get-screenshot.md +++ b/docs/examples/avatars/get-screenshot.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/avatars" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/avatars" ) client := client.New( diff --git a/docs/examples/backups/create-archive.md b/docs/examples/backups/create-archive.md index 445607ab..ef3dffd3 100644 --- a/docs/examples/backups/create-archive.md +++ b/docs/examples/backups/create-archive.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/backups/create-policy.md b/docs/examples/backups/create-policy.md index ba9acc83..cbaf5208 100644 --- a/docs/examples/backups/create-policy.md +++ b/docs/examples/backups/create-policy.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/backups/create-restoration.md b/docs/examples/backups/create-restoration.md index eb2ed98e..156e6a90 100644 --- a/docs/examples/backups/create-restoration.md +++ b/docs/examples/backups/create-restoration.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/backups/delete-archive.md b/docs/examples/backups/delete-archive.md index fb9097c2..7d34c75d 100644 --- a/docs/examples/backups/delete-archive.md +++ b/docs/examples/backups/delete-archive.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/backups/delete-policy.md b/docs/examples/backups/delete-policy.md index 56128e45..73d68cf9 100644 --- a/docs/examples/backups/delete-policy.md +++ b/docs/examples/backups/delete-policy.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/backups/get-archive.md b/docs/examples/backups/get-archive.md index 79067bc0..12ea0489 100644 --- a/docs/examples/backups/get-archive.md +++ b/docs/examples/backups/get-archive.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/backups/get-policy.md b/docs/examples/backups/get-policy.md index 175e81ed..7e0e871a 100644 --- a/docs/examples/backups/get-policy.md +++ b/docs/examples/backups/get-policy.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/backups/get-restoration.md b/docs/examples/backups/get-restoration.md index 1331320e..d55145af 100644 --- a/docs/examples/backups/get-restoration.md +++ b/docs/examples/backups/get-restoration.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/backups/list-archives.md b/docs/examples/backups/list-archives.md index 8f5b5435..5429a92e 100644 --- a/docs/examples/backups/list-archives.md +++ b/docs/examples/backups/list-archives.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/backups/list-policies.md b/docs/examples/backups/list-policies.md index cef7b8ac..43880516 100644 --- a/docs/examples/backups/list-policies.md +++ b/docs/examples/backups/list-policies.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/backups/list-restorations.md b/docs/examples/backups/list-restorations.md index 32e20b16..19783213 100644 --- a/docs/examples/backups/list-restorations.md +++ b/docs/examples/backups/list-restorations.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/backups/update-policy.md b/docs/examples/backups/update-policy.md index 5fb6060a..56267e6f 100644 --- a/docs/examples/backups/update-policy.md +++ b/docs/examples/backups/update-policy.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/backups" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/backups" ) client := client.New( diff --git a/docs/examples/databases/create-boolean-attribute.md b/docs/examples/databases/create-boolean-attribute.md index 777b7176..9f9d6442 100644 --- a/docs/examples/databases/create-boolean-attribute.md +++ b/docs/examples/databases/create-boolean-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-collection.md b/docs/examples/databases/create-collection.md index 100ba24e..83d3a0e2 100644 --- a/docs/examples/databases/create-collection.md +++ b/docs/examples/databases/create-collection.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-datetime-attribute.md b/docs/examples/databases/create-datetime-attribute.md index 7e66c56a..2298e7c9 100644 --- a/docs/examples/databases/create-datetime-attribute.md +++ b/docs/examples/databases/create-datetime-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( @@ -20,7 +20,7 @@ response, error := service.CreateDatetimeAttribute( "", "", false, - databases.WithCreateDatetimeAttributeDefault(""), + databases.WithCreateDatetimeAttributeDefault("2020-10-15T06:38:00.000+00:00"), databases.WithCreateDatetimeAttributeArray(false), ) ``` diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index 49b17215..8dc9146d 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-documents.md b/docs/examples/databases/create-documents.md index 796553bd..16564c1c 100644 --- a/docs/examples/databases/create-documents.md +++ b/docs/examples/databases/create-documents.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-email-attribute.md b/docs/examples/databases/create-email-attribute.md index 020fb16d..935e721b 100644 --- a/docs/examples/databases/create-email-attribute.md +++ b/docs/examples/databases/create-email-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-enum-attribute.md b/docs/examples/databases/create-enum-attribute.md index 3573b94c..ba28a7ee 100644 --- a/docs/examples/databases/create-enum-attribute.md +++ b/docs/examples/databases/create-enum-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-float-attribute.md b/docs/examples/databases/create-float-attribute.md index b93fa4b2..c1de137d 100644 --- a/docs/examples/databases/create-float-attribute.md +++ b/docs/examples/databases/create-float-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-index.md b/docs/examples/databases/create-index.md index 314ed8c1..c9e85b22 100644 --- a/docs/examples/databases/create-index.md +++ b/docs/examples/databases/create-index.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-integer-attribute.md b/docs/examples/databases/create-integer-attribute.md index e91d971a..a84c31fa 100644 --- a/docs/examples/databases/create-integer-attribute.md +++ b/docs/examples/databases/create-integer-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-ip-attribute.md b/docs/examples/databases/create-ip-attribute.md index adac57ad..1ecf1eb6 100644 --- a/docs/examples/databases/create-ip-attribute.md +++ b/docs/examples/databases/create-ip-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-line-attribute.md b/docs/examples/databases/create-line-attribute.md index 37659e9a..74b79f3e 100644 --- a/docs/examples/databases/create-line-attribute.md +++ b/docs/examples/databases/create-line-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-longtext-attribute.md b/docs/examples/databases/create-longtext-attribute.md index 693c4345..0325abcb 100644 --- a/docs/examples/databases/create-longtext-attribute.md +++ b/docs/examples/databases/create-longtext-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-mediumtext-attribute.md b/docs/examples/databases/create-mediumtext-attribute.md index 55a97704..08f917c6 100644 --- a/docs/examples/databases/create-mediumtext-attribute.md +++ b/docs/examples/databases/create-mediumtext-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-operations.md b/docs/examples/databases/create-operations.md index 34f33c1f..b934b87e 100644 --- a/docs/examples/databases/create-operations.md +++ b/docs/examples/databases/create-operations.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-point-attribute.md b/docs/examples/databases/create-point-attribute.md index e66512a1..72a3ddd5 100644 --- a/docs/examples/databases/create-point-attribute.md +++ b/docs/examples/databases/create-point-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-polygon-attribute.md b/docs/examples/databases/create-polygon-attribute.md index ba19973c..772aeb8f 100644 --- a/docs/examples/databases/create-polygon-attribute.md +++ b/docs/examples/databases/create-polygon-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-relationship-attribute.md b/docs/examples/databases/create-relationship-attribute.md index 15d5a0ae..925a10f1 100644 --- a/docs/examples/databases/create-relationship-attribute.md +++ b/docs/examples/databases/create-relationship-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-string-attribute.md b/docs/examples/databases/create-string-attribute.md index 8ecfdf60..b9be97f0 100644 --- a/docs/examples/databases/create-string-attribute.md +++ b/docs/examples/databases/create-string-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-text-attribute.md b/docs/examples/databases/create-text-attribute.md index 55aaa2d5..35a67a79 100644 --- a/docs/examples/databases/create-text-attribute.md +++ b/docs/examples/databases/create-text-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-transaction.md b/docs/examples/databases/create-transaction.md index 03c66138..139c96ad 100644 --- a/docs/examples/databases/create-transaction.md +++ b/docs/examples/databases/create-transaction.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-url-attribute.md b/docs/examples/databases/create-url-attribute.md index f4cae997..e62479aa 100644 --- a/docs/examples/databases/create-url-attribute.md +++ b/docs/examples/databases/create-url-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create-varchar-attribute.md b/docs/examples/databases/create-varchar-attribute.md index 56372666..58e6dca8 100644 --- a/docs/examples/databases/create-varchar-attribute.md +++ b/docs/examples/databases/create-varchar-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/create.md b/docs/examples/databases/create.md index 1c0b8e83..bae0a49d 100644 --- a/docs/examples/databases/create.md +++ b/docs/examples/databases/create.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/decrement-document-attribute.md b/docs/examples/databases/decrement-document-attribute.md index 57f9a0ad..6493d371 100644 --- a/docs/examples/databases/decrement-document-attribute.md +++ b/docs/examples/databases/decrement-document-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/delete-attribute.md b/docs/examples/databases/delete-attribute.md index 327d6a37..64b19244 100644 --- a/docs/examples/databases/delete-attribute.md +++ b/docs/examples/databases/delete-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/delete-collection.md b/docs/examples/databases/delete-collection.md index fbdc43b3..856ba6f0 100644 --- a/docs/examples/databases/delete-collection.md +++ b/docs/examples/databases/delete-collection.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/delete-document.md b/docs/examples/databases/delete-document.md index 51ff7ee5..2e98535c 100644 --- a/docs/examples/databases/delete-document.md +++ b/docs/examples/databases/delete-document.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/delete-documents.md b/docs/examples/databases/delete-documents.md index a6168c40..c81165ce 100644 --- a/docs/examples/databases/delete-documents.md +++ b/docs/examples/databases/delete-documents.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/delete-index.md b/docs/examples/databases/delete-index.md index 5546c712..8fc4eade 100644 --- a/docs/examples/databases/delete-index.md +++ b/docs/examples/databases/delete-index.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/delete-transaction.md b/docs/examples/databases/delete-transaction.md index 0c5b842e..a515154c 100644 --- a/docs/examples/databases/delete-transaction.md +++ b/docs/examples/databases/delete-transaction.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/delete.md b/docs/examples/databases/delete.md index cc22faff..e5f1a5ce 100644 --- a/docs/examples/databases/delete.md +++ b/docs/examples/databases/delete.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/get-attribute.md b/docs/examples/databases/get-attribute.md index 54f87a5b..52e9a324 100644 --- a/docs/examples/databases/get-attribute.md +++ b/docs/examples/databases/get-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/get-collection.md b/docs/examples/databases/get-collection.md index 483cc827..2871e17c 100644 --- a/docs/examples/databases/get-collection.md +++ b/docs/examples/databases/get-collection.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/get-document.md b/docs/examples/databases/get-document.md index 50be7545..a8d8dbf0 100644 --- a/docs/examples/databases/get-document.md +++ b/docs/examples/databases/get-document.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/get-index.md b/docs/examples/databases/get-index.md index c608f356..85be5f08 100644 --- a/docs/examples/databases/get-index.md +++ b/docs/examples/databases/get-index.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/get-transaction.md b/docs/examples/databases/get-transaction.md index 79d010e6..c539e2dc 100644 --- a/docs/examples/databases/get-transaction.md +++ b/docs/examples/databases/get-transaction.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/get.md b/docs/examples/databases/get.md index 16c38a5a..c0ac6637 100644 --- a/docs/examples/databases/get.md +++ b/docs/examples/databases/get.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/increment-document-attribute.md b/docs/examples/databases/increment-document-attribute.md index 9a16bf06..5e9ee2ed 100644 --- a/docs/examples/databases/increment-document-attribute.md +++ b/docs/examples/databases/increment-document-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/list-attributes.md b/docs/examples/databases/list-attributes.md index 935392f9..7ba02550 100644 --- a/docs/examples/databases/list-attributes.md +++ b/docs/examples/databases/list-attributes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/list-collections.md b/docs/examples/databases/list-collections.md index c1905e37..f5f534b4 100644 --- a/docs/examples/databases/list-collections.md +++ b/docs/examples/databases/list-collections.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md index 1c702d71..ceebb642 100644 --- a/docs/examples/databases/list-documents.md +++ b/docs/examples/databases/list-documents.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/list-indexes.md b/docs/examples/databases/list-indexes.md index c3dddf76..226bf23f 100644 --- a/docs/examples/databases/list-indexes.md +++ b/docs/examples/databases/list-indexes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/list-transactions.md b/docs/examples/databases/list-transactions.md index 90fe1c02..cf3d627a 100644 --- a/docs/examples/databases/list-transactions.md +++ b/docs/examples/databases/list-transactions.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/list.md b/docs/examples/databases/list.md index 66bb89b2..1dbd3f5a 100644 --- a/docs/examples/databases/list.md +++ b/docs/examples/databases/list.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-boolean-attribute.md b/docs/examples/databases/update-boolean-attribute.md index 9dd6a5ce..cff8402f 100644 --- a/docs/examples/databases/update-boolean-attribute.md +++ b/docs/examples/databases/update-boolean-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-collection.md b/docs/examples/databases/update-collection.md index f48e6a69..7265f35a 100644 --- a/docs/examples/databases/update-collection.md +++ b/docs/examples/databases/update-collection.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-datetime-attribute.md b/docs/examples/databases/update-datetime-attribute.md index 9c9d7c8d..91ff28e5 100644 --- a/docs/examples/databases/update-datetime-attribute.md +++ b/docs/examples/databases/update-datetime-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( @@ -20,7 +20,7 @@ response, error := service.UpdateDatetimeAttribute( "", "", false, - "", + "2020-10-15T06:38:00.000+00:00", databases.WithUpdateDatetimeAttributeNewKey(""), ) ``` diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md index 80472972..c2b90391 100644 --- a/docs/examples/databases/update-document.md +++ b/docs/examples/databases/update-document.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-documents.md b/docs/examples/databases/update-documents.md index 15c742cb..a53a32cc 100644 --- a/docs/examples/databases/update-documents.md +++ b/docs/examples/databases/update-documents.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-email-attribute.md b/docs/examples/databases/update-email-attribute.md index b10ee7a8..04b9beac 100644 --- a/docs/examples/databases/update-email-attribute.md +++ b/docs/examples/databases/update-email-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-enum-attribute.md b/docs/examples/databases/update-enum-attribute.md index 54d6fdc1..82233f13 100644 --- a/docs/examples/databases/update-enum-attribute.md +++ b/docs/examples/databases/update-enum-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-float-attribute.md b/docs/examples/databases/update-float-attribute.md index ad6dc0e6..c8c58b98 100644 --- a/docs/examples/databases/update-float-attribute.md +++ b/docs/examples/databases/update-float-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-integer-attribute.md b/docs/examples/databases/update-integer-attribute.md index 6cd5552e..05a3be59 100644 --- a/docs/examples/databases/update-integer-attribute.md +++ b/docs/examples/databases/update-integer-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-ip-attribute.md b/docs/examples/databases/update-ip-attribute.md index 19ff5740..349766c2 100644 --- a/docs/examples/databases/update-ip-attribute.md +++ b/docs/examples/databases/update-ip-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-line-attribute.md b/docs/examples/databases/update-line-attribute.md index ee4292ba..bb3a6d73 100644 --- a/docs/examples/databases/update-line-attribute.md +++ b/docs/examples/databases/update-line-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-longtext-attribute.md b/docs/examples/databases/update-longtext-attribute.md index 96fa2ef0..1e1e911e 100644 --- a/docs/examples/databases/update-longtext-attribute.md +++ b/docs/examples/databases/update-longtext-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-mediumtext-attribute.md b/docs/examples/databases/update-mediumtext-attribute.md index eb2019e2..10175d93 100644 --- a/docs/examples/databases/update-mediumtext-attribute.md +++ b/docs/examples/databases/update-mediumtext-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-point-attribute.md b/docs/examples/databases/update-point-attribute.md index 21981983..be0bbf33 100644 --- a/docs/examples/databases/update-point-attribute.md +++ b/docs/examples/databases/update-point-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-polygon-attribute.md b/docs/examples/databases/update-polygon-attribute.md index 8efcf619..c38c453a 100644 --- a/docs/examples/databases/update-polygon-attribute.md +++ b/docs/examples/databases/update-polygon-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-relationship-attribute.md b/docs/examples/databases/update-relationship-attribute.md index 2e7fdff0..c8564df7 100644 --- a/docs/examples/databases/update-relationship-attribute.md +++ b/docs/examples/databases/update-relationship-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-string-attribute.md b/docs/examples/databases/update-string-attribute.md index 161b5804..076cefd3 100644 --- a/docs/examples/databases/update-string-attribute.md +++ b/docs/examples/databases/update-string-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-text-attribute.md b/docs/examples/databases/update-text-attribute.md index 4ed090c5..6d68bc39 100644 --- a/docs/examples/databases/update-text-attribute.md +++ b/docs/examples/databases/update-text-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-transaction.md b/docs/examples/databases/update-transaction.md index bb660f9a..ee0dcdd3 100644 --- a/docs/examples/databases/update-transaction.md +++ b/docs/examples/databases/update-transaction.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-url-attribute.md b/docs/examples/databases/update-url-attribute.md index 2295ba27..de07d257 100644 --- a/docs/examples/databases/update-url-attribute.md +++ b/docs/examples/databases/update-url-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update-varchar-attribute.md b/docs/examples/databases/update-varchar-attribute.md index c65799c2..710b726e 100644 --- a/docs/examples/databases/update-varchar-attribute.md +++ b/docs/examples/databases/update-varchar-attribute.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/update.md b/docs/examples/databases/update.md index ea968098..61bc6993 100644 --- a/docs/examples/databases/update.md +++ b/docs/examples/databases/update.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/upsert-document.md b/docs/examples/databases/upsert-document.md index b4b54759..a03c4369 100644 --- a/docs/examples/databases/upsert-document.md +++ b/docs/examples/databases/upsert-document.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/databases/upsert-documents.md b/docs/examples/databases/upsert-documents.md index 71d5a175..f8897ad0 100644 --- a/docs/examples/databases/upsert-documents.md +++ b/docs/examples/databases/upsert-documents.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/databases" ) client := client.New( diff --git a/docs/examples/functions/create-deployment.md b/docs/examples/functions/create-deployment.md index 035664a2..274cac39 100644 --- a/docs/examples/functions/create-deployment.md +++ b/docs/examples/functions/create-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/create-duplicate-deployment.md b/docs/examples/functions/create-duplicate-deployment.md index 4e81af2d..ecba9990 100644 --- a/docs/examples/functions/create-duplicate-deployment.md +++ b/docs/examples/functions/create-duplicate-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index cbcec47c..8aa9c31f 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/create-template-deployment.md b/docs/examples/functions/create-template-deployment.md index e5523e8f..c086a396 100644 --- a/docs/examples/functions/create-template-deployment.md +++ b/docs/examples/functions/create-template-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/create-variable.md b/docs/examples/functions/create-variable.md index 01cebf48..23d92449 100644 --- a/docs/examples/functions/create-variable.md +++ b/docs/examples/functions/create-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/create-vcs-deployment.md b/docs/examples/functions/create-vcs-deployment.md index 8e58d4fc..9659dcaf 100644 --- a/docs/examples/functions/create-vcs-deployment.md +++ b/docs/examples/functions/create-vcs-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index 673c84d4..87effee9 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/delete-deployment.md b/docs/examples/functions/delete-deployment.md index bccfb54b..971d2abd 100644 --- a/docs/examples/functions/delete-deployment.md +++ b/docs/examples/functions/delete-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/delete-execution.md b/docs/examples/functions/delete-execution.md index dc18dc69..37f0ee7d 100644 --- a/docs/examples/functions/delete-execution.md +++ b/docs/examples/functions/delete-execution.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/delete-variable.md b/docs/examples/functions/delete-variable.md index 80403639..d7eae9cc 100644 --- a/docs/examples/functions/delete-variable.md +++ b/docs/examples/functions/delete-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/delete.md b/docs/examples/functions/delete.md index d7b67339..065afcef 100644 --- a/docs/examples/functions/delete.md +++ b/docs/examples/functions/delete.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/get-deployment-download.md b/docs/examples/functions/get-deployment-download.md index b1f15e12..aa200613 100644 --- a/docs/examples/functions/get-deployment-download.md +++ b/docs/examples/functions/get-deployment-download.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/get-deployment.md b/docs/examples/functions/get-deployment.md index 935dcb69..7faa2353 100644 --- a/docs/examples/functions/get-deployment.md +++ b/docs/examples/functions/get-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/get-execution.md b/docs/examples/functions/get-execution.md index 0a9ace45..f18a9d37 100644 --- a/docs/examples/functions/get-execution.md +++ b/docs/examples/functions/get-execution.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/get-variable.md b/docs/examples/functions/get-variable.md index dcdc3391..cd41dfc6 100644 --- a/docs/examples/functions/get-variable.md +++ b/docs/examples/functions/get-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/get.md b/docs/examples/functions/get.md index 56ce2053..71a97328 100644 --- a/docs/examples/functions/get.md +++ b/docs/examples/functions/get.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/list-deployments.md b/docs/examples/functions/list-deployments.md index 45b20c18..eb66aceb 100644 --- a/docs/examples/functions/list-deployments.md +++ b/docs/examples/functions/list-deployments.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/list-executions.md b/docs/examples/functions/list-executions.md index ac9aeb45..7f93c95c 100644 --- a/docs/examples/functions/list-executions.md +++ b/docs/examples/functions/list-executions.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/list-runtimes.md b/docs/examples/functions/list-runtimes.md index a2a1120f..672058e2 100644 --- a/docs/examples/functions/list-runtimes.md +++ b/docs/examples/functions/list-runtimes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/list-specifications.md b/docs/examples/functions/list-specifications.md index e7ee77de..f36d8098 100644 --- a/docs/examples/functions/list-specifications.md +++ b/docs/examples/functions/list-specifications.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/list-variables.md b/docs/examples/functions/list-variables.md index 9bea3674..821f05b8 100644 --- a/docs/examples/functions/list-variables.md +++ b/docs/examples/functions/list-variables.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/list.md b/docs/examples/functions/list.md index 030260ba..8bbdceec 100644 --- a/docs/examples/functions/list.md +++ b/docs/examples/functions/list.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/update-deployment-status.md b/docs/examples/functions/update-deployment-status.md index 369d13d1..bfe52015 100644 --- a/docs/examples/functions/update-deployment-status.md +++ b/docs/examples/functions/update-deployment-status.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/update-function-deployment.md b/docs/examples/functions/update-function-deployment.md index 2c381ac0..4fd679d5 100644 --- a/docs/examples/functions/update-function-deployment.md +++ b/docs/examples/functions/update-function-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/update-variable.md b/docs/examples/functions/update-variable.md index 35bc01d2..6b90898b 100644 --- a/docs/examples/functions/update-variable.md +++ b/docs/examples/functions/update-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md index 6f89a995..3cd6285c 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/functions" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/functions" ) client := client.New( diff --git a/docs/examples/graphql/mutation.md b/docs/examples/graphql/mutation.md index eec8490e..41ae85c3 100644 --- a/docs/examples/graphql/mutation.md +++ b/docs/examples/graphql/mutation.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/graphql" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/graphql" ) client := client.New( diff --git a/docs/examples/graphql/query.md b/docs/examples/graphql/query.md index a5903d4a..9cf1f7b3 100644 --- a/docs/examples/graphql/query.md +++ b/docs/examples/graphql/query.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/graphql" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/graphql" ) client := client.New( diff --git a/docs/examples/health/get-antivirus.md b/docs/examples/health/get-antivirus.md index dcb417b1..bf9f3e61 100644 --- a/docs/examples/health/get-antivirus.md +++ b/docs/examples/health/get-antivirus.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-cache.md b/docs/examples/health/get-cache.md index 935bcc09..1b103d21 100644 --- a/docs/examples/health/get-cache.md +++ b/docs/examples/health/get-cache.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-certificate.md b/docs/examples/health/get-certificate.md index 819fdd38..4c39fa58 100644 --- a/docs/examples/health/get-certificate.md +++ b/docs/examples/health/get-certificate.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-console-pausing.md b/docs/examples/health/get-console-pausing.md index 44038133..ff1ffce1 100644 --- a/docs/examples/health/get-console-pausing.md +++ b/docs/examples/health/get-console-pausing.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-db.md b/docs/examples/health/get-db.md index 1a198a7b..8c9a21c1 100644 --- a/docs/examples/health/get-db.md +++ b/docs/examples/health/get-db.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-failed-jobs.md b/docs/examples/health/get-failed-jobs.md index 97604e0c..52a42998 100644 --- a/docs/examples/health/get-failed-jobs.md +++ b/docs/examples/health/get-failed-jobs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-pub-sub.md b/docs/examples/health/get-pub-sub.md index addf5253..11676e7e 100644 --- a/docs/examples/health/get-pub-sub.md +++ b/docs/examples/health/get-pub-sub.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-audits.md b/docs/examples/health/get-queue-audits.md index 0ae8104e..36be36f9 100644 --- a/docs/examples/health/get-queue-audits.md +++ b/docs/examples/health/get-queue-audits.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-builds.md b/docs/examples/health/get-queue-builds.md index 722febe0..4e4dc219 100644 --- a/docs/examples/health/get-queue-builds.md +++ b/docs/examples/health/get-queue-builds.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-certificates.md b/docs/examples/health/get-queue-certificates.md index 86179864..cb9f9eaa 100644 --- a/docs/examples/health/get-queue-certificates.md +++ b/docs/examples/health/get-queue-certificates.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-databases.md b/docs/examples/health/get-queue-databases.md index 5f30c228..f84fca12 100644 --- a/docs/examples/health/get-queue-databases.md +++ b/docs/examples/health/get-queue-databases.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-deletes.md b/docs/examples/health/get-queue-deletes.md index a4149816..dcd2300f 100644 --- a/docs/examples/health/get-queue-deletes.md +++ b/docs/examples/health/get-queue-deletes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-functions.md b/docs/examples/health/get-queue-functions.md index df8c7e70..4b2ddf69 100644 --- a/docs/examples/health/get-queue-functions.md +++ b/docs/examples/health/get-queue-functions.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-logs.md b/docs/examples/health/get-queue-logs.md index 309a2fbd..1f9af901 100644 --- a/docs/examples/health/get-queue-logs.md +++ b/docs/examples/health/get-queue-logs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-mails.md b/docs/examples/health/get-queue-mails.md index 12d1fcae..62b9b7a3 100644 --- a/docs/examples/health/get-queue-mails.md +++ b/docs/examples/health/get-queue-mails.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-messaging.md b/docs/examples/health/get-queue-messaging.md index 07df816f..30116c8e 100644 --- a/docs/examples/health/get-queue-messaging.md +++ b/docs/examples/health/get-queue-messaging.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-migrations.md b/docs/examples/health/get-queue-migrations.md index b7416cc1..5e4e0c22 100644 --- a/docs/examples/health/get-queue-migrations.md +++ b/docs/examples/health/get-queue-migrations.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-stats-resources.md b/docs/examples/health/get-queue-stats-resources.md index ef2bff33..d1acaf1e 100644 --- a/docs/examples/health/get-queue-stats-resources.md +++ b/docs/examples/health/get-queue-stats-resources.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-usage.md b/docs/examples/health/get-queue-usage.md index 0c6b28d2..d050a88d 100644 --- a/docs/examples/health/get-queue-usage.md +++ b/docs/examples/health/get-queue-usage.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-queue-webhooks.md b/docs/examples/health/get-queue-webhooks.md index 6c5d2a9d..0112d81f 100644 --- a/docs/examples/health/get-queue-webhooks.md +++ b/docs/examples/health/get-queue-webhooks.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-storage-local.md b/docs/examples/health/get-storage-local.md index 039c8a5d..6e6b190c 100644 --- a/docs/examples/health/get-storage-local.md +++ b/docs/examples/health/get-storage-local.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-storage.md b/docs/examples/health/get-storage.md index c91f9e70..ef4e6b00 100644 --- a/docs/examples/health/get-storage.md +++ b/docs/examples/health/get-storage.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get-time.md b/docs/examples/health/get-time.md index 36763b1b..7c8a5133 100644 --- a/docs/examples/health/get-time.md +++ b/docs/examples/health/get-time.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/health/get.md b/docs/examples/health/get.md index fbab1bf2..b015dd34 100644 --- a/docs/examples/health/get.md +++ b/docs/examples/health/get.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/health" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/health" ) client := client.New( diff --git a/docs/examples/locale/get.md b/docs/examples/locale/get.md index c12da752..65a62c7f 100644 --- a/docs/examples/locale/get.md +++ b/docs/examples/locale/get.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/locale" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/locale" ) client := client.New( diff --git a/docs/examples/locale/list-codes.md b/docs/examples/locale/list-codes.md index 828cd7e5..cbbcb8d3 100644 --- a/docs/examples/locale/list-codes.md +++ b/docs/examples/locale/list-codes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/locale" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/locale" ) client := client.New( diff --git a/docs/examples/locale/list-continents.md b/docs/examples/locale/list-continents.md index 5827017b..d2e0596b 100644 --- a/docs/examples/locale/list-continents.md +++ b/docs/examples/locale/list-continents.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/locale" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/locale" ) client := client.New( diff --git a/docs/examples/locale/list-countries-eu.md b/docs/examples/locale/list-countries-eu.md index 199faf60..701dbe3b 100644 --- a/docs/examples/locale/list-countries-eu.md +++ b/docs/examples/locale/list-countries-eu.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/locale" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/locale" ) client := client.New( diff --git a/docs/examples/locale/list-countries-phones.md b/docs/examples/locale/list-countries-phones.md index f6a6dd6b..00257e88 100644 --- a/docs/examples/locale/list-countries-phones.md +++ b/docs/examples/locale/list-countries-phones.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/locale" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/locale" ) client := client.New( diff --git a/docs/examples/locale/list-countries.md b/docs/examples/locale/list-countries.md index 375f8e30..c92e67e3 100644 --- a/docs/examples/locale/list-countries.md +++ b/docs/examples/locale/list-countries.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/locale" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/locale" ) client := client.New( diff --git a/docs/examples/locale/list-currencies.md b/docs/examples/locale/list-currencies.md index 226f3676..6b81caf6 100644 --- a/docs/examples/locale/list-currencies.md +++ b/docs/examples/locale/list-currencies.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/locale" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/locale" ) client := client.New( diff --git a/docs/examples/locale/list-languages.md b/docs/examples/locale/list-languages.md index 06c26436..38377e9d 100644 --- a/docs/examples/locale/list-languages.md +++ b/docs/examples/locale/list-languages.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/locale" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/locale" ) client := client.New( diff --git a/docs/examples/messaging/create-apns-provider.md b/docs/examples/messaging/create-apns-provider.md index ef481d20..23f991ef 100644 --- a/docs/examples/messaging/create-apns-provider.md +++ b/docs/examples/messaging/create-apns-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-email.md b/docs/examples/messaging/create-email.md index ff36dfb8..539509a0 100644 --- a/docs/examples/messaging/create-email.md +++ b/docs/examples/messaging/create-email.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( @@ -27,6 +27,6 @@ response, error := service.CreateEmail( messaging.WithCreateEmailAttachments([]interface{}{}), messaging.WithCreateEmailDraft(false), messaging.WithCreateEmailHtml(false), - messaging.WithCreateEmailScheduledAt(""), + messaging.WithCreateEmailScheduledAt("2020-10-15T06:38:00.000+00:00"), ) ``` diff --git a/docs/examples/messaging/create-fcm-provider.md b/docs/examples/messaging/create-fcm-provider.md index 3bbab73b..a6e82a08 100644 --- a/docs/examples/messaging/create-fcm-provider.md +++ b/docs/examples/messaging/create-fcm-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-mailgun-provider.md b/docs/examples/messaging/create-mailgun-provider.md index 4149f591..fc10286f 100644 --- a/docs/examples/messaging/create-mailgun-provider.md +++ b/docs/examples/messaging/create-mailgun-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-msg-91-provider.md b/docs/examples/messaging/create-msg-91-provider.md index 5a5f6d9d..0e5a448a 100644 --- a/docs/examples/messaging/create-msg-91-provider.md +++ b/docs/examples/messaging/create-msg-91-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-push.md b/docs/examples/messaging/create-push.md index f39eb3ac..d62b1244 100644 --- a/docs/examples/messaging/create-push.md +++ b/docs/examples/messaging/create-push.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( @@ -31,7 +31,7 @@ response, error := service.CreatePush( messaging.WithCreatePushTag(""), messaging.WithCreatePushBadge(0), messaging.WithCreatePushDraft(false), - messaging.WithCreatePushScheduledAt(""), + messaging.WithCreatePushScheduledAt("2020-10-15T06:38:00.000+00:00"), messaging.WithCreatePushContentAvailable(false), messaging.WithCreatePushCritical(false), messaging.WithCreatePushPriority("normal"), diff --git a/docs/examples/messaging/create-resend-provider.md b/docs/examples/messaging/create-resend-provider.md index 5f693ba3..664e756c 100644 --- a/docs/examples/messaging/create-resend-provider.md +++ b/docs/examples/messaging/create-resend-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-sendgrid-provider.md b/docs/examples/messaging/create-sendgrid-provider.md index 6d95b551..902bd6ef 100644 --- a/docs/examples/messaging/create-sendgrid-provider.md +++ b/docs/examples/messaging/create-sendgrid-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-sms.md b/docs/examples/messaging/create-sms.md index 09ad8aaf..b58170f4 100644 --- a/docs/examples/messaging/create-sms.md +++ b/docs/examples/messaging/create-sms.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( @@ -22,6 +22,6 @@ response, error := service.CreateSMS( messaging.WithCreateSMSUsers([]interface{}{}), messaging.WithCreateSMSTargets([]interface{}{}), messaging.WithCreateSMSDraft(false), - messaging.WithCreateSMSScheduledAt(""), + messaging.WithCreateSMSScheduledAt("2020-10-15T06:38:00.000+00:00"), ) ``` diff --git a/docs/examples/messaging/create-smtp-provider.md b/docs/examples/messaging/create-smtp-provider.md index 10eb6f85..ad11652e 100644 --- a/docs/examples/messaging/create-smtp-provider.md +++ b/docs/examples/messaging/create-smtp-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-subscriber.md b/docs/examples/messaging/create-subscriber.md index 122b0e2f..8f7e2231 100644 --- a/docs/examples/messaging/create-subscriber.md +++ b/docs/examples/messaging/create-subscriber.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-telesign-provider.md b/docs/examples/messaging/create-telesign-provider.md index 38aecaeb..6a78c234 100644 --- a/docs/examples/messaging/create-telesign-provider.md +++ b/docs/examples/messaging/create-telesign-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-textmagic-provider.md b/docs/examples/messaging/create-textmagic-provider.md index ca64aaa1..c5f5241b 100644 --- a/docs/examples/messaging/create-textmagic-provider.md +++ b/docs/examples/messaging/create-textmagic-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-topic.md b/docs/examples/messaging/create-topic.md index 0c2ea9e0..fa6da90b 100644 --- a/docs/examples/messaging/create-topic.md +++ b/docs/examples/messaging/create-topic.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-twilio-provider.md b/docs/examples/messaging/create-twilio-provider.md index 938bf40e..ade526c9 100644 --- a/docs/examples/messaging/create-twilio-provider.md +++ b/docs/examples/messaging/create-twilio-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/create-vonage-provider.md b/docs/examples/messaging/create-vonage-provider.md index de1eb14f..0007a9d0 100644 --- a/docs/examples/messaging/create-vonage-provider.md +++ b/docs/examples/messaging/create-vonage-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/delete-provider.md b/docs/examples/messaging/delete-provider.md index 1aa13a7f..0f5a2791 100644 --- a/docs/examples/messaging/delete-provider.md +++ b/docs/examples/messaging/delete-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/delete-subscriber.md b/docs/examples/messaging/delete-subscriber.md index e5168923..37411075 100644 --- a/docs/examples/messaging/delete-subscriber.md +++ b/docs/examples/messaging/delete-subscriber.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/delete-topic.md b/docs/examples/messaging/delete-topic.md index 016c78ff..249d098c 100644 --- a/docs/examples/messaging/delete-topic.md +++ b/docs/examples/messaging/delete-topic.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/delete.md b/docs/examples/messaging/delete.md index f62753f3..5dda3d32 100644 --- a/docs/examples/messaging/delete.md +++ b/docs/examples/messaging/delete.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/get-message.md b/docs/examples/messaging/get-message.md index 8fc3c2ca..e769899f 100644 --- a/docs/examples/messaging/get-message.md +++ b/docs/examples/messaging/get-message.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/get-provider.md b/docs/examples/messaging/get-provider.md index 1b3b903c..89e6c614 100644 --- a/docs/examples/messaging/get-provider.md +++ b/docs/examples/messaging/get-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/get-subscriber.md b/docs/examples/messaging/get-subscriber.md index 12f88522..236b5c41 100644 --- a/docs/examples/messaging/get-subscriber.md +++ b/docs/examples/messaging/get-subscriber.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/get-topic.md b/docs/examples/messaging/get-topic.md index 9dcb6846..6d97b7e8 100644 --- a/docs/examples/messaging/get-topic.md +++ b/docs/examples/messaging/get-topic.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/list-message-logs.md b/docs/examples/messaging/list-message-logs.md index eb29e315..9e6e01e9 100644 --- a/docs/examples/messaging/list-message-logs.md +++ b/docs/examples/messaging/list-message-logs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/list-messages.md b/docs/examples/messaging/list-messages.md index 612a0c14..8bd8da39 100644 --- a/docs/examples/messaging/list-messages.md +++ b/docs/examples/messaging/list-messages.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/list-provider-logs.md b/docs/examples/messaging/list-provider-logs.md index 8361034b..022f5f20 100644 --- a/docs/examples/messaging/list-provider-logs.md +++ b/docs/examples/messaging/list-provider-logs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/list-providers.md b/docs/examples/messaging/list-providers.md index 6f354207..f71c4c13 100644 --- a/docs/examples/messaging/list-providers.md +++ b/docs/examples/messaging/list-providers.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/list-subscriber-logs.md b/docs/examples/messaging/list-subscriber-logs.md index 12e163b2..20518ba8 100644 --- a/docs/examples/messaging/list-subscriber-logs.md +++ b/docs/examples/messaging/list-subscriber-logs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/list-subscribers.md b/docs/examples/messaging/list-subscribers.md index 9c71bd94..fa9684bd 100644 --- a/docs/examples/messaging/list-subscribers.md +++ b/docs/examples/messaging/list-subscribers.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/list-targets.md b/docs/examples/messaging/list-targets.md index 15f0dea3..f5cb0062 100644 --- a/docs/examples/messaging/list-targets.md +++ b/docs/examples/messaging/list-targets.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/list-topic-logs.md b/docs/examples/messaging/list-topic-logs.md index 353d2aa4..1f673e15 100644 --- a/docs/examples/messaging/list-topic-logs.md +++ b/docs/examples/messaging/list-topic-logs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/list-topics.md b/docs/examples/messaging/list-topics.md index 6f34f5dd..8fda7fc2 100644 --- a/docs/examples/messaging/list-topics.md +++ b/docs/examples/messaging/list-topics.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-apns-provider.md b/docs/examples/messaging/update-apns-provider.md index 60e332ac..892b00a0 100644 --- a/docs/examples/messaging/update-apns-provider.md +++ b/docs/examples/messaging/update-apns-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-email.md b/docs/examples/messaging/update-email.md index e6d70953..31a8c96f 100644 --- a/docs/examples/messaging/update-email.md +++ b/docs/examples/messaging/update-email.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( @@ -26,7 +26,7 @@ response, error := service.UpdateEmail( messaging.WithUpdateEmailHtml(false), messaging.WithUpdateEmailCc([]interface{}{}), messaging.WithUpdateEmailBcc([]interface{}{}), - messaging.WithUpdateEmailScheduledAt(""), + messaging.WithUpdateEmailScheduledAt("2020-10-15T06:38:00.000+00:00"), messaging.WithUpdateEmailAttachments([]interface{}{}), ) ``` diff --git a/docs/examples/messaging/update-fcm-provider.md b/docs/examples/messaging/update-fcm-provider.md index 938fa007..99028c91 100644 --- a/docs/examples/messaging/update-fcm-provider.md +++ b/docs/examples/messaging/update-fcm-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-mailgun-provider.md b/docs/examples/messaging/update-mailgun-provider.md index 25deb152..f80574f2 100644 --- a/docs/examples/messaging/update-mailgun-provider.md +++ b/docs/examples/messaging/update-mailgun-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-msg-91-provider.md b/docs/examples/messaging/update-msg-91-provider.md index ff31ab94..9fbb7796 100644 --- a/docs/examples/messaging/update-msg-91-provider.md +++ b/docs/examples/messaging/update-msg-91-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-push.md b/docs/examples/messaging/update-push.md index 19287fac..54948912 100644 --- a/docs/examples/messaging/update-push.md +++ b/docs/examples/messaging/update-push.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( @@ -31,7 +31,7 @@ response, error := service.UpdatePush( messaging.WithUpdatePushTag(""), messaging.WithUpdatePushBadge(0), messaging.WithUpdatePushDraft(false), - messaging.WithUpdatePushScheduledAt(""), + messaging.WithUpdatePushScheduledAt("2020-10-15T06:38:00.000+00:00"), messaging.WithUpdatePushContentAvailable(false), messaging.WithUpdatePushCritical(false), messaging.WithUpdatePushPriority("normal"), diff --git a/docs/examples/messaging/update-resend-provider.md b/docs/examples/messaging/update-resend-provider.md index 6ac8cc6b..49addaa9 100644 --- a/docs/examples/messaging/update-resend-provider.md +++ b/docs/examples/messaging/update-resend-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-sendgrid-provider.md b/docs/examples/messaging/update-sendgrid-provider.md index 59cb4fbd..550d75ff 100644 --- a/docs/examples/messaging/update-sendgrid-provider.md +++ b/docs/examples/messaging/update-sendgrid-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-sms.md b/docs/examples/messaging/update-sms.md index 1adcdd26..141d97fb 100644 --- a/docs/examples/messaging/update-sms.md +++ b/docs/examples/messaging/update-sms.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( @@ -22,6 +22,6 @@ response, error := service.UpdateSMS( messaging.WithUpdateSMSTargets([]interface{}{}), messaging.WithUpdateSMSContent(""), messaging.WithUpdateSMSDraft(false), - messaging.WithUpdateSMSScheduledAt(""), + messaging.WithUpdateSMSScheduledAt("2020-10-15T06:38:00.000+00:00"), ) ``` diff --git a/docs/examples/messaging/update-smtp-provider.md b/docs/examples/messaging/update-smtp-provider.md index d707ee1b..0684b166 100644 --- a/docs/examples/messaging/update-smtp-provider.md +++ b/docs/examples/messaging/update-smtp-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-telesign-provider.md b/docs/examples/messaging/update-telesign-provider.md index bbcf5638..02e7f42c 100644 --- a/docs/examples/messaging/update-telesign-provider.md +++ b/docs/examples/messaging/update-telesign-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-textmagic-provider.md b/docs/examples/messaging/update-textmagic-provider.md index 702a9f5c..751a6c01 100644 --- a/docs/examples/messaging/update-textmagic-provider.md +++ b/docs/examples/messaging/update-textmagic-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-topic.md b/docs/examples/messaging/update-topic.md index 794e0d0a..ab307a4a 100644 --- a/docs/examples/messaging/update-topic.md +++ b/docs/examples/messaging/update-topic.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-twilio-provider.md b/docs/examples/messaging/update-twilio-provider.md index 1513ad98..d2158b04 100644 --- a/docs/examples/messaging/update-twilio-provider.md +++ b/docs/examples/messaging/update-twilio-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/messaging/update-vonage-provider.md b/docs/examples/messaging/update-vonage-provider.md index 133f7de2..147e8ca1 100644 --- a/docs/examples/messaging/update-vonage-provider.md +++ b/docs/examples/messaging/update-vonage-provider.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/messaging" ) client := client.New( diff --git a/docs/examples/project/create-variable.md b/docs/examples/project/create-variable.md index 84284e72..f66969dd 100644 --- a/docs/examples/project/create-variable.md +++ b/docs/examples/project/create-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/project" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/project" ) client := client.New( diff --git a/docs/examples/project/delete-variable.md b/docs/examples/project/delete-variable.md index fd5da105..5bd47512 100644 --- a/docs/examples/project/delete-variable.md +++ b/docs/examples/project/delete-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/project" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/project" ) client := client.New( diff --git a/docs/examples/project/get-variable.md b/docs/examples/project/get-variable.md index 1a765804..d4bc824d 100644 --- a/docs/examples/project/get-variable.md +++ b/docs/examples/project/get-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/project" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/project" ) client := client.New( diff --git a/docs/examples/project/list-variables.md b/docs/examples/project/list-variables.md index 15657c6a..fb8d2c75 100644 --- a/docs/examples/project/list-variables.md +++ b/docs/examples/project/list-variables.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/project" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/project" ) client := client.New( diff --git a/docs/examples/project/update-variable.md b/docs/examples/project/update-variable.md index 3da119f0..ff1d8789 100644 --- a/docs/examples/project/update-variable.md +++ b/docs/examples/project/update-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/project" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/project" ) client := client.New( diff --git a/docs/examples/sites/create-deployment.md b/docs/examples/sites/create-deployment.md index 086b5f1f..e1044038 100644 --- a/docs/examples/sites/create-deployment.md +++ b/docs/examples/sites/create-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/create-duplicate-deployment.md b/docs/examples/sites/create-duplicate-deployment.md index d5db3d89..b49962bf 100644 --- a/docs/examples/sites/create-duplicate-deployment.md +++ b/docs/examples/sites/create-duplicate-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/create-template-deployment.md b/docs/examples/sites/create-template-deployment.md index 9d221bb7..73597e91 100644 --- a/docs/examples/sites/create-template-deployment.md +++ b/docs/examples/sites/create-template-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/create-variable.md b/docs/examples/sites/create-variable.md index a5d771c2..6226b48d 100644 --- a/docs/examples/sites/create-variable.md +++ b/docs/examples/sites/create-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/create-vcs-deployment.md b/docs/examples/sites/create-vcs-deployment.md index 1c207941..6666fe28 100644 --- a/docs/examples/sites/create-vcs-deployment.md +++ b/docs/examples/sites/create-vcs-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/create.md b/docs/examples/sites/create.md index ba161003..194e2c95 100644 --- a/docs/examples/sites/create.md +++ b/docs/examples/sites/create.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/delete-deployment.md b/docs/examples/sites/delete-deployment.md index e7937847..244f9abe 100644 --- a/docs/examples/sites/delete-deployment.md +++ b/docs/examples/sites/delete-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/delete-log.md b/docs/examples/sites/delete-log.md index cd379336..c96c2a02 100644 --- a/docs/examples/sites/delete-log.md +++ b/docs/examples/sites/delete-log.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/delete-variable.md b/docs/examples/sites/delete-variable.md index ee5c0dd3..87eb7091 100644 --- a/docs/examples/sites/delete-variable.md +++ b/docs/examples/sites/delete-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/delete.md b/docs/examples/sites/delete.md index f11542f5..a4675677 100644 --- a/docs/examples/sites/delete.md +++ b/docs/examples/sites/delete.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/get-deployment-download.md b/docs/examples/sites/get-deployment-download.md index 68437275..d8ecb316 100644 --- a/docs/examples/sites/get-deployment-download.md +++ b/docs/examples/sites/get-deployment-download.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/get-deployment.md b/docs/examples/sites/get-deployment.md index 9a8a93bd..494e0fad 100644 --- a/docs/examples/sites/get-deployment.md +++ b/docs/examples/sites/get-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/get-log.md b/docs/examples/sites/get-log.md index f77a0fe3..16145c85 100644 --- a/docs/examples/sites/get-log.md +++ b/docs/examples/sites/get-log.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/get-variable.md b/docs/examples/sites/get-variable.md index 08dab1a3..0e8e1a3d 100644 --- a/docs/examples/sites/get-variable.md +++ b/docs/examples/sites/get-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/get.md b/docs/examples/sites/get.md index b8d67cdf..25c8bc77 100644 --- a/docs/examples/sites/get.md +++ b/docs/examples/sites/get.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/list-deployments.md b/docs/examples/sites/list-deployments.md index 5d8bf6b5..760edbde 100644 --- a/docs/examples/sites/list-deployments.md +++ b/docs/examples/sites/list-deployments.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/list-frameworks.md b/docs/examples/sites/list-frameworks.md index 36b78131..6f814bad 100644 --- a/docs/examples/sites/list-frameworks.md +++ b/docs/examples/sites/list-frameworks.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/list-logs.md b/docs/examples/sites/list-logs.md index c15d9894..6b2f4347 100644 --- a/docs/examples/sites/list-logs.md +++ b/docs/examples/sites/list-logs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/list-specifications.md b/docs/examples/sites/list-specifications.md index cfd22bd5..f378164c 100644 --- a/docs/examples/sites/list-specifications.md +++ b/docs/examples/sites/list-specifications.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/list-variables.md b/docs/examples/sites/list-variables.md index c57434aa..e76d1bea 100644 --- a/docs/examples/sites/list-variables.md +++ b/docs/examples/sites/list-variables.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/list.md b/docs/examples/sites/list.md index 9bb8f323..f6682f9b 100644 --- a/docs/examples/sites/list.md +++ b/docs/examples/sites/list.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/update-deployment-status.md b/docs/examples/sites/update-deployment-status.md index b3a1d889..b7182dba 100644 --- a/docs/examples/sites/update-deployment-status.md +++ b/docs/examples/sites/update-deployment-status.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/update-site-deployment.md b/docs/examples/sites/update-site-deployment.md index d89ca75e..6bee6424 100644 --- a/docs/examples/sites/update-site-deployment.md +++ b/docs/examples/sites/update-site-deployment.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/update-variable.md b/docs/examples/sites/update-variable.md index 31792066..ea4105a5 100644 --- a/docs/examples/sites/update-variable.md +++ b/docs/examples/sites/update-variable.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/sites/update.md b/docs/examples/sites/update.md index f20edc4e..2e3c0508 100644 --- a/docs/examples/sites/update.md +++ b/docs/examples/sites/update.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/sites" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/sites" ) client := client.New( diff --git a/docs/examples/storage/create-bucket.md b/docs/examples/storage/create-bucket.md index e2f688b7..98af7b2a 100644 --- a/docs/examples/storage/create-bucket.md +++ b/docs/examples/storage/create-bucket.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index 2104ae77..d0099a5c 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/delete-bucket.md b/docs/examples/storage/delete-bucket.md index 0dd2b682..cef2af79 100644 --- a/docs/examples/storage/delete-bucket.md +++ b/docs/examples/storage/delete-bucket.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/delete-file.md b/docs/examples/storage/delete-file.md index 3e9a3de8..74b594df 100644 --- a/docs/examples/storage/delete-file.md +++ b/docs/examples/storage/delete-file.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/get-bucket.md b/docs/examples/storage/get-bucket.md index d949f80d..ef83dd82 100644 --- a/docs/examples/storage/get-bucket.md +++ b/docs/examples/storage/get-bucket.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/get-file-download.md b/docs/examples/storage/get-file-download.md index c082c0b1..3df62abc 100644 --- a/docs/examples/storage/get-file-download.md +++ b/docs/examples/storage/get-file-download.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/get-file-preview.md b/docs/examples/storage/get-file-preview.md index 96a876f9..f8683f7c 100644 --- a/docs/examples/storage/get-file-preview.md +++ b/docs/examples/storage/get-file-preview.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/get-file-view.md b/docs/examples/storage/get-file-view.md index cc35241b..f16d672f 100644 --- a/docs/examples/storage/get-file-view.md +++ b/docs/examples/storage/get-file-view.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/get-file.md b/docs/examples/storage/get-file.md index 0a22eaff..f7301532 100644 --- a/docs/examples/storage/get-file.md +++ b/docs/examples/storage/get-file.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/list-buckets.md b/docs/examples/storage/list-buckets.md index 04972e27..020197fa 100644 --- a/docs/examples/storage/list-buckets.md +++ b/docs/examples/storage/list-buckets.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/list-files.md b/docs/examples/storage/list-files.md index 1393b19d..a2c9524c 100644 --- a/docs/examples/storage/list-files.md +++ b/docs/examples/storage/list-files.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/update-bucket.md b/docs/examples/storage/update-bucket.md index a3d2d421..f16606cc 100644 --- a/docs/examples/storage/update-bucket.md +++ b/docs/examples/storage/update-bucket.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/storage/update-file.md b/docs/examples/storage/update-file.md index e1ab83d0..90a16b7b 100644 --- a/docs/examples/storage/update-file.md +++ b/docs/examples/storage/update-file.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/storage" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/storage" ) client := client.New( diff --git a/docs/examples/tablesdb/create-boolean-column.md b/docs/examples/tablesdb/create-boolean-column.md index 06b02734..5daec556 100644 --- a/docs/examples/tablesdb/create-boolean-column.md +++ b/docs/examples/tablesdb/create-boolean-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-datetime-column.md b/docs/examples/tablesdb/create-datetime-column.md index e13f15cf..e3048a6a 100644 --- a/docs/examples/tablesdb/create-datetime-column.md +++ b/docs/examples/tablesdb/create-datetime-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( @@ -20,7 +20,7 @@ response, error := service.CreateDatetimeColumn( "", "", false, - tablesdb.WithCreateDatetimeColumnDefault(""), + tablesdb.WithCreateDatetimeColumnDefault("2020-10-15T06:38:00.000+00:00"), tablesdb.WithCreateDatetimeColumnArray(false), ) ``` diff --git a/docs/examples/tablesdb/create-email-column.md b/docs/examples/tablesdb/create-email-column.md index 37648dce..ecd11f5e 100644 --- a/docs/examples/tablesdb/create-email-column.md +++ b/docs/examples/tablesdb/create-email-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-enum-column.md b/docs/examples/tablesdb/create-enum-column.md index d0aae3b0..a8126802 100644 --- a/docs/examples/tablesdb/create-enum-column.md +++ b/docs/examples/tablesdb/create-enum-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-float-column.md b/docs/examples/tablesdb/create-float-column.md index 32e9bd6d..f99a28cf 100644 --- a/docs/examples/tablesdb/create-float-column.md +++ b/docs/examples/tablesdb/create-float-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-index.md b/docs/examples/tablesdb/create-index.md index 8f0adb3d..32e0d133 100644 --- a/docs/examples/tablesdb/create-index.md +++ b/docs/examples/tablesdb/create-index.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-integer-column.md b/docs/examples/tablesdb/create-integer-column.md index ce9faa7b..026bf062 100644 --- a/docs/examples/tablesdb/create-integer-column.md +++ b/docs/examples/tablesdb/create-integer-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-ip-column.md b/docs/examples/tablesdb/create-ip-column.md index 5c29c003..7552bbff 100644 --- a/docs/examples/tablesdb/create-ip-column.md +++ b/docs/examples/tablesdb/create-ip-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-line-column.md b/docs/examples/tablesdb/create-line-column.md index 65532929..517da126 100644 --- a/docs/examples/tablesdb/create-line-column.md +++ b/docs/examples/tablesdb/create-line-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-longtext-column.md b/docs/examples/tablesdb/create-longtext-column.md index 708c13c7..72c86433 100644 --- a/docs/examples/tablesdb/create-longtext-column.md +++ b/docs/examples/tablesdb/create-longtext-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-mediumtext-column.md b/docs/examples/tablesdb/create-mediumtext-column.md index 0f8e692b..fad86096 100644 --- a/docs/examples/tablesdb/create-mediumtext-column.md +++ b/docs/examples/tablesdb/create-mediumtext-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-operations.md b/docs/examples/tablesdb/create-operations.md index c26ac618..f9527620 100644 --- a/docs/examples/tablesdb/create-operations.md +++ b/docs/examples/tablesdb/create-operations.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-point-column.md b/docs/examples/tablesdb/create-point-column.md index 41569ee8..8c5517a1 100644 --- a/docs/examples/tablesdb/create-point-column.md +++ b/docs/examples/tablesdb/create-point-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-polygon-column.md b/docs/examples/tablesdb/create-polygon-column.md index 300bbf4e..18d18d11 100644 --- a/docs/examples/tablesdb/create-polygon-column.md +++ b/docs/examples/tablesdb/create-polygon-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-relationship-column.md b/docs/examples/tablesdb/create-relationship-column.md index 67122f11..5096aa5c 100644 --- a/docs/examples/tablesdb/create-relationship-column.md +++ b/docs/examples/tablesdb/create-relationship-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-row.md b/docs/examples/tablesdb/create-row.md index 2068727b..3e1a9396 100644 --- a/docs/examples/tablesdb/create-row.md +++ b/docs/examples/tablesdb/create-row.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-rows.md b/docs/examples/tablesdb/create-rows.md index 1a458204..4de6d38e 100644 --- a/docs/examples/tablesdb/create-rows.md +++ b/docs/examples/tablesdb/create-rows.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-string-column.md b/docs/examples/tablesdb/create-string-column.md index a4128e10..ec2648c0 100644 --- a/docs/examples/tablesdb/create-string-column.md +++ b/docs/examples/tablesdb/create-string-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-table.md b/docs/examples/tablesdb/create-table.md index f08cbbbc..6dd4221f 100644 --- a/docs/examples/tablesdb/create-table.md +++ b/docs/examples/tablesdb/create-table.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-text-column.md b/docs/examples/tablesdb/create-text-column.md index bd85e440..e36becb2 100644 --- a/docs/examples/tablesdb/create-text-column.md +++ b/docs/examples/tablesdb/create-text-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-transaction.md b/docs/examples/tablesdb/create-transaction.md index 69fc2820..bd3df135 100644 --- a/docs/examples/tablesdb/create-transaction.md +++ b/docs/examples/tablesdb/create-transaction.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-url-column.md b/docs/examples/tablesdb/create-url-column.md index aae95af5..8a23dbfe 100644 --- a/docs/examples/tablesdb/create-url-column.md +++ b/docs/examples/tablesdb/create-url-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create-varchar-column.md b/docs/examples/tablesdb/create-varchar-column.md index 0f265ebd..ebe6c96c 100644 --- a/docs/examples/tablesdb/create-varchar-column.md +++ b/docs/examples/tablesdb/create-varchar-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/create.md b/docs/examples/tablesdb/create.md index 96d3591e..0483cde4 100644 --- a/docs/examples/tablesdb/create.md +++ b/docs/examples/tablesdb/create.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/decrement-row-column.md b/docs/examples/tablesdb/decrement-row-column.md index 25e88937..202e80c1 100644 --- a/docs/examples/tablesdb/decrement-row-column.md +++ b/docs/examples/tablesdb/decrement-row-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/delete-column.md b/docs/examples/tablesdb/delete-column.md index 4b6ded52..ae17f3b8 100644 --- a/docs/examples/tablesdb/delete-column.md +++ b/docs/examples/tablesdb/delete-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/delete-index.md b/docs/examples/tablesdb/delete-index.md index 3b51b6b4..346d8612 100644 --- a/docs/examples/tablesdb/delete-index.md +++ b/docs/examples/tablesdb/delete-index.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/delete-row.md b/docs/examples/tablesdb/delete-row.md index ed2cedc2..7f87b906 100644 --- a/docs/examples/tablesdb/delete-row.md +++ b/docs/examples/tablesdb/delete-row.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/delete-rows.md b/docs/examples/tablesdb/delete-rows.md index f9a04cef..8600cc4e 100644 --- a/docs/examples/tablesdb/delete-rows.md +++ b/docs/examples/tablesdb/delete-rows.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/delete-table.md b/docs/examples/tablesdb/delete-table.md index 1f6d922e..088497ab 100644 --- a/docs/examples/tablesdb/delete-table.md +++ b/docs/examples/tablesdb/delete-table.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/delete-transaction.md b/docs/examples/tablesdb/delete-transaction.md index be7918eb..0c9bca71 100644 --- a/docs/examples/tablesdb/delete-transaction.md +++ b/docs/examples/tablesdb/delete-transaction.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/delete.md b/docs/examples/tablesdb/delete.md index 80507361..096bd460 100644 --- a/docs/examples/tablesdb/delete.md +++ b/docs/examples/tablesdb/delete.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/get-column.md b/docs/examples/tablesdb/get-column.md index 28dcde5d..a376d846 100644 --- a/docs/examples/tablesdb/get-column.md +++ b/docs/examples/tablesdb/get-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/get-index.md b/docs/examples/tablesdb/get-index.md index 06a3dff3..875e8cf5 100644 --- a/docs/examples/tablesdb/get-index.md +++ b/docs/examples/tablesdb/get-index.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/get-row.md b/docs/examples/tablesdb/get-row.md index 74172cf3..070875ab 100644 --- a/docs/examples/tablesdb/get-row.md +++ b/docs/examples/tablesdb/get-row.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/get-table.md b/docs/examples/tablesdb/get-table.md index bb3caada..3012687d 100644 --- a/docs/examples/tablesdb/get-table.md +++ b/docs/examples/tablesdb/get-table.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/get-transaction.md b/docs/examples/tablesdb/get-transaction.md index e33f9b22..d7a209db 100644 --- a/docs/examples/tablesdb/get-transaction.md +++ b/docs/examples/tablesdb/get-transaction.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/get.md b/docs/examples/tablesdb/get.md index 91eaa271..c4afad3f 100644 --- a/docs/examples/tablesdb/get.md +++ b/docs/examples/tablesdb/get.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/increment-row-column.md b/docs/examples/tablesdb/increment-row-column.md index c2ff437b..359bf503 100644 --- a/docs/examples/tablesdb/increment-row-column.md +++ b/docs/examples/tablesdb/increment-row-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/list-columns.md b/docs/examples/tablesdb/list-columns.md index 0bad3360..154bb0da 100644 --- a/docs/examples/tablesdb/list-columns.md +++ b/docs/examples/tablesdb/list-columns.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/list-indexes.md b/docs/examples/tablesdb/list-indexes.md index bb9b632d..33429f8d 100644 --- a/docs/examples/tablesdb/list-indexes.md +++ b/docs/examples/tablesdb/list-indexes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/list-rows.md b/docs/examples/tablesdb/list-rows.md index 49c382f9..e46c77e5 100644 --- a/docs/examples/tablesdb/list-rows.md +++ b/docs/examples/tablesdb/list-rows.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/list-tables.md b/docs/examples/tablesdb/list-tables.md index f16e9df4..8c75c609 100644 --- a/docs/examples/tablesdb/list-tables.md +++ b/docs/examples/tablesdb/list-tables.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/list-transactions.md b/docs/examples/tablesdb/list-transactions.md index edeff0ba..4ac86de1 100644 --- a/docs/examples/tablesdb/list-transactions.md +++ b/docs/examples/tablesdb/list-transactions.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/list.md b/docs/examples/tablesdb/list.md index 596a8cc8..06090987 100644 --- a/docs/examples/tablesdb/list.md +++ b/docs/examples/tablesdb/list.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-boolean-column.md b/docs/examples/tablesdb/update-boolean-column.md index c1948aed..5daa856c 100644 --- a/docs/examples/tablesdb/update-boolean-column.md +++ b/docs/examples/tablesdb/update-boolean-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-datetime-column.md b/docs/examples/tablesdb/update-datetime-column.md index 8a75b756..86d221b5 100644 --- a/docs/examples/tablesdb/update-datetime-column.md +++ b/docs/examples/tablesdb/update-datetime-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( @@ -20,7 +20,7 @@ response, error := service.UpdateDatetimeColumn( "", "", false, - "", + "2020-10-15T06:38:00.000+00:00", tablesdb.WithUpdateDatetimeColumnNewKey(""), ) ``` diff --git a/docs/examples/tablesdb/update-email-column.md b/docs/examples/tablesdb/update-email-column.md index d4e8e4ae..befd622f 100644 --- a/docs/examples/tablesdb/update-email-column.md +++ b/docs/examples/tablesdb/update-email-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-enum-column.md b/docs/examples/tablesdb/update-enum-column.md index 4a43bc1f..0488f6e0 100644 --- a/docs/examples/tablesdb/update-enum-column.md +++ b/docs/examples/tablesdb/update-enum-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-float-column.md b/docs/examples/tablesdb/update-float-column.md index 256b14b2..1bfa2dfd 100644 --- a/docs/examples/tablesdb/update-float-column.md +++ b/docs/examples/tablesdb/update-float-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-integer-column.md b/docs/examples/tablesdb/update-integer-column.md index 829fd09f..6a2ada84 100644 --- a/docs/examples/tablesdb/update-integer-column.md +++ b/docs/examples/tablesdb/update-integer-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-ip-column.md b/docs/examples/tablesdb/update-ip-column.md index 1b9e5351..3a7b1c14 100644 --- a/docs/examples/tablesdb/update-ip-column.md +++ b/docs/examples/tablesdb/update-ip-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-line-column.md b/docs/examples/tablesdb/update-line-column.md index fa1d84e5..685be30b 100644 --- a/docs/examples/tablesdb/update-line-column.md +++ b/docs/examples/tablesdb/update-line-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-longtext-column.md b/docs/examples/tablesdb/update-longtext-column.md index 89be1c6b..15d74dbe 100644 --- a/docs/examples/tablesdb/update-longtext-column.md +++ b/docs/examples/tablesdb/update-longtext-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-mediumtext-column.md b/docs/examples/tablesdb/update-mediumtext-column.md index 115b75fa..d356149d 100644 --- a/docs/examples/tablesdb/update-mediumtext-column.md +++ b/docs/examples/tablesdb/update-mediumtext-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-point-column.md b/docs/examples/tablesdb/update-point-column.md index 1e3b0400..cfcef3c9 100644 --- a/docs/examples/tablesdb/update-point-column.md +++ b/docs/examples/tablesdb/update-point-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-polygon-column.md b/docs/examples/tablesdb/update-polygon-column.md index 1197f849..f6cc4526 100644 --- a/docs/examples/tablesdb/update-polygon-column.md +++ b/docs/examples/tablesdb/update-polygon-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-relationship-column.md b/docs/examples/tablesdb/update-relationship-column.md index f3b63f25..bacd7f44 100644 --- a/docs/examples/tablesdb/update-relationship-column.md +++ b/docs/examples/tablesdb/update-relationship-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-row.md b/docs/examples/tablesdb/update-row.md index dd2b3b92..a4d22bae 100644 --- a/docs/examples/tablesdb/update-row.md +++ b/docs/examples/tablesdb/update-row.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-rows.md b/docs/examples/tablesdb/update-rows.md index 95203a20..b43d27ad 100644 --- a/docs/examples/tablesdb/update-rows.md +++ b/docs/examples/tablesdb/update-rows.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-string-column.md b/docs/examples/tablesdb/update-string-column.md index c3ad25ef..8bfe5bb4 100644 --- a/docs/examples/tablesdb/update-string-column.md +++ b/docs/examples/tablesdb/update-string-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-table.md b/docs/examples/tablesdb/update-table.md index f77781d6..424fd935 100644 --- a/docs/examples/tablesdb/update-table.md +++ b/docs/examples/tablesdb/update-table.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-text-column.md b/docs/examples/tablesdb/update-text-column.md index 5b406f7e..16144e07 100644 --- a/docs/examples/tablesdb/update-text-column.md +++ b/docs/examples/tablesdb/update-text-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-transaction.md b/docs/examples/tablesdb/update-transaction.md index 5cce91ae..7f2e2f23 100644 --- a/docs/examples/tablesdb/update-transaction.md +++ b/docs/examples/tablesdb/update-transaction.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-url-column.md b/docs/examples/tablesdb/update-url-column.md index 4a809e1e..24b6faa2 100644 --- a/docs/examples/tablesdb/update-url-column.md +++ b/docs/examples/tablesdb/update-url-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update-varchar-column.md b/docs/examples/tablesdb/update-varchar-column.md index 7ee853e7..555806b6 100644 --- a/docs/examples/tablesdb/update-varchar-column.md +++ b/docs/examples/tablesdb/update-varchar-column.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/update.md b/docs/examples/tablesdb/update.md index 268b1852..d0f389f3 100644 --- a/docs/examples/tablesdb/update.md +++ b/docs/examples/tablesdb/update.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/upsert-row.md b/docs/examples/tablesdb/upsert-row.md index 2f1507de..9edb7d4c 100644 --- a/docs/examples/tablesdb/upsert-row.md +++ b/docs/examples/tablesdb/upsert-row.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/tablesdb/upsert-rows.md b/docs/examples/tablesdb/upsert-rows.md index 322b1ccb..251c1df8 100644 --- a/docs/examples/tablesdb/upsert-rows.md +++ b/docs/examples/tablesdb/upsert-rows.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tablesdb" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tablesdb" ) client := client.New( diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md index a640e661..e6a49435 100644 --- a/docs/examples/teams/create-membership.md +++ b/docs/examples/teams/create-membership.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/create.md b/docs/examples/teams/create.md index b86ee631..28c7df26 100644 --- a/docs/examples/teams/create.md +++ b/docs/examples/teams/create.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/delete-membership.md b/docs/examples/teams/delete-membership.md index 77f058a3..4f2b49c1 100644 --- a/docs/examples/teams/delete-membership.md +++ b/docs/examples/teams/delete-membership.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/delete.md b/docs/examples/teams/delete.md index 88305907..39fe51b3 100644 --- a/docs/examples/teams/delete.md +++ b/docs/examples/teams/delete.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/get-membership.md b/docs/examples/teams/get-membership.md index 1688bdb9..35644950 100644 --- a/docs/examples/teams/get-membership.md +++ b/docs/examples/teams/get-membership.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/get-prefs.md b/docs/examples/teams/get-prefs.md index 1de3006b..58831987 100644 --- a/docs/examples/teams/get-prefs.md +++ b/docs/examples/teams/get-prefs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/get.md b/docs/examples/teams/get.md index ab8ee6cb..72a9ec40 100644 --- a/docs/examples/teams/get.md +++ b/docs/examples/teams/get.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/list-memberships.md b/docs/examples/teams/list-memberships.md index b7da5b3d..b9334139 100644 --- a/docs/examples/teams/list-memberships.md +++ b/docs/examples/teams/list-memberships.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/list.md b/docs/examples/teams/list.md index 53332b2a..64ea913c 100644 --- a/docs/examples/teams/list.md +++ b/docs/examples/teams/list.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/update-membership-status.md b/docs/examples/teams/update-membership-status.md index 905e35d1..1526f30c 100644 --- a/docs/examples/teams/update-membership-status.md +++ b/docs/examples/teams/update-membership-status.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/update-membership.md b/docs/examples/teams/update-membership.md index b4ac9da8..bdba20ae 100644 --- a/docs/examples/teams/update-membership.md +++ b/docs/examples/teams/update-membership.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/update-name.md b/docs/examples/teams/update-name.md index 3de69240..6c47b105 100644 --- a/docs/examples/teams/update-name.md +++ b/docs/examples/teams/update-name.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/teams/update-prefs.md b/docs/examples/teams/update-prefs.md index c042d0af..6b09ceff 100644 --- a/docs/examples/teams/update-prefs.md +++ b/docs/examples/teams/update-prefs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/teams" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/teams" ) client := client.New( diff --git a/docs/examples/tokens/create-file-token.md b/docs/examples/tokens/create-file-token.md index f21569d3..34cf12c7 100644 --- a/docs/examples/tokens/create-file-token.md +++ b/docs/examples/tokens/create-file-token.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tokens" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tokens" ) client := client.New( @@ -18,6 +18,6 @@ service := tokens.New(client) response, error := service.CreateFileToken( "", "", - tokens.WithCreateFileTokenExpire(""), + tokens.WithCreateFileTokenExpire("2020-10-15T06:38:00.000+00:00"), ) ``` diff --git a/docs/examples/tokens/delete.md b/docs/examples/tokens/delete.md index e0d72aed..77d602ee 100644 --- a/docs/examples/tokens/delete.md +++ b/docs/examples/tokens/delete.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tokens" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tokens" ) client := client.New( diff --git a/docs/examples/tokens/get.md b/docs/examples/tokens/get.md index eef351dd..c422eb33 100644 --- a/docs/examples/tokens/get.md +++ b/docs/examples/tokens/get.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tokens" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tokens" ) client := client.New( diff --git a/docs/examples/tokens/list.md b/docs/examples/tokens/list.md index a702a858..f7d31a5d 100644 --- a/docs/examples/tokens/list.md +++ b/docs/examples/tokens/list.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tokens" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tokens" ) client := client.New( diff --git a/docs/examples/tokens/update.md b/docs/examples/tokens/update.md index a1c14c48..b5ec9b44 100644 --- a/docs/examples/tokens/update.md +++ b/docs/examples/tokens/update.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/tokens" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/tokens" ) client := client.New( @@ -17,6 +17,6 @@ service := tokens.New(client) response, error := service.Update( "", - tokens.WithUpdateExpire(""), + tokens.WithUpdateExpire("2020-10-15T06:38:00.000+00:00"), ) ``` diff --git a/docs/examples/users/create-argon-2-user.md b/docs/examples/users/create-argon-2-user.md index cb795ee8..b235023f 100644 --- a/docs/examples/users/create-argon-2-user.md +++ b/docs/examples/users/create-argon-2-user.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create-bcrypt-user.md b/docs/examples/users/create-bcrypt-user.md index bc0faa82..f62b2f17 100644 --- a/docs/examples/users/create-bcrypt-user.md +++ b/docs/examples/users/create-bcrypt-user.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create-jwt.md b/docs/examples/users/create-jwt.md index 6530a21c..a9d5ff89 100644 --- a/docs/examples/users/create-jwt.md +++ b/docs/examples/users/create-jwt.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create-md-5-user.md b/docs/examples/users/create-md-5-user.md index 69b5d795..9e49ca63 100644 --- a/docs/examples/users/create-md-5-user.md +++ b/docs/examples/users/create-md-5-user.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create-mfa-recovery-codes.md b/docs/examples/users/create-mfa-recovery-codes.md index dbe85cb1..f41145bd 100644 --- a/docs/examples/users/create-mfa-recovery-codes.md +++ b/docs/examples/users/create-mfa-recovery-codes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create-ph-pass-user.md b/docs/examples/users/create-ph-pass-user.md index da042352..d3cde8db 100644 --- a/docs/examples/users/create-ph-pass-user.md +++ b/docs/examples/users/create-ph-pass-user.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create-scrypt-modified-user.md b/docs/examples/users/create-scrypt-modified-user.md index 20930c4f..54ba40c2 100644 --- a/docs/examples/users/create-scrypt-modified-user.md +++ b/docs/examples/users/create-scrypt-modified-user.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create-scrypt-user.md b/docs/examples/users/create-scrypt-user.md index 16e76b4d..766f2f03 100644 --- a/docs/examples/users/create-scrypt-user.md +++ b/docs/examples/users/create-scrypt-user.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create-session.md b/docs/examples/users/create-session.md index 3b87e89a..a6de8363 100644 --- a/docs/examples/users/create-session.md +++ b/docs/examples/users/create-session.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create-sha-user.md b/docs/examples/users/create-sha-user.md index 703897d6..d81588ae 100644 --- a/docs/examples/users/create-sha-user.md +++ b/docs/examples/users/create-sha-user.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create-target.md b/docs/examples/users/create-target.md index cf8e350c..10f21353 100644 --- a/docs/examples/users/create-target.md +++ b/docs/examples/users/create-target.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create-token.md b/docs/examples/users/create-token.md index 47c8fbe7..2332f3e4 100644 --- a/docs/examples/users/create-token.md +++ b/docs/examples/users/create-token.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/create.md b/docs/examples/users/create.md index 8ccdd6b5..4765d88b 100644 --- a/docs/examples/users/create.md +++ b/docs/examples/users/create.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/delete-identity.md b/docs/examples/users/delete-identity.md index 6ecce869..c901f5cc 100644 --- a/docs/examples/users/delete-identity.md +++ b/docs/examples/users/delete-identity.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/delete-mfa-authenticator.md b/docs/examples/users/delete-mfa-authenticator.md index 1f7d7d9c..d4efcbca 100644 --- a/docs/examples/users/delete-mfa-authenticator.md +++ b/docs/examples/users/delete-mfa-authenticator.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/delete-session.md b/docs/examples/users/delete-session.md index d53a8be6..acbf44fe 100644 --- a/docs/examples/users/delete-session.md +++ b/docs/examples/users/delete-session.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/delete-sessions.md b/docs/examples/users/delete-sessions.md index 49cee0b6..1a33547f 100644 --- a/docs/examples/users/delete-sessions.md +++ b/docs/examples/users/delete-sessions.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/delete-target.md b/docs/examples/users/delete-target.md index 15cbd4ef..85b3eb8b 100644 --- a/docs/examples/users/delete-target.md +++ b/docs/examples/users/delete-target.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/delete.md b/docs/examples/users/delete.md index 04fe1ba6..43f228d1 100644 --- a/docs/examples/users/delete.md +++ b/docs/examples/users/delete.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/get-mfa-recovery-codes.md b/docs/examples/users/get-mfa-recovery-codes.md index a745c402..d83e3cfa 100644 --- a/docs/examples/users/get-mfa-recovery-codes.md +++ b/docs/examples/users/get-mfa-recovery-codes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/get-prefs.md b/docs/examples/users/get-prefs.md index 832a26bf..b4c7b03d 100644 --- a/docs/examples/users/get-prefs.md +++ b/docs/examples/users/get-prefs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/get-target.md b/docs/examples/users/get-target.md index 5722608e..ab0ecb83 100644 --- a/docs/examples/users/get-target.md +++ b/docs/examples/users/get-target.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/get.md b/docs/examples/users/get.md index 5b0d2265..711e04f6 100644 --- a/docs/examples/users/get.md +++ b/docs/examples/users/get.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/list-identities.md b/docs/examples/users/list-identities.md index ffd780de..840abc70 100644 --- a/docs/examples/users/list-identities.md +++ b/docs/examples/users/list-identities.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/list-logs.md b/docs/examples/users/list-logs.md index 0906c3b5..101c6902 100644 --- a/docs/examples/users/list-logs.md +++ b/docs/examples/users/list-logs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/list-memberships.md b/docs/examples/users/list-memberships.md index ac8469cf..68d45d3e 100644 --- a/docs/examples/users/list-memberships.md +++ b/docs/examples/users/list-memberships.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/list-mfa-factors.md b/docs/examples/users/list-mfa-factors.md index a8c8df5a..8367b889 100644 --- a/docs/examples/users/list-mfa-factors.md +++ b/docs/examples/users/list-mfa-factors.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/list-sessions.md b/docs/examples/users/list-sessions.md index 40047a7b..f1f1c825 100644 --- a/docs/examples/users/list-sessions.md +++ b/docs/examples/users/list-sessions.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/list-targets.md b/docs/examples/users/list-targets.md index 193282ea..03fce153 100644 --- a/docs/examples/users/list-targets.md +++ b/docs/examples/users/list-targets.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/list.md b/docs/examples/users/list.md index ca7d0763..b38f9918 100644 --- a/docs/examples/users/list.md +++ b/docs/examples/users/list.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-email-verification.md b/docs/examples/users/update-email-verification.md index 72d2fa88..f35307c8 100644 --- a/docs/examples/users/update-email-verification.md +++ b/docs/examples/users/update-email-verification.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-email.md b/docs/examples/users/update-email.md index 22871898..bb3a676e 100644 --- a/docs/examples/users/update-email.md +++ b/docs/examples/users/update-email.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-impersonator.md b/docs/examples/users/update-impersonator.md index 0e0445f7..bdc79e49 100644 --- a/docs/examples/users/update-impersonator.md +++ b/docs/examples/users/update-impersonator.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-labels.md b/docs/examples/users/update-labels.md index f02616b5..c8060145 100644 --- a/docs/examples/users/update-labels.md +++ b/docs/examples/users/update-labels.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-mfa-recovery-codes.md b/docs/examples/users/update-mfa-recovery-codes.md index e1f8351a..e6994313 100644 --- a/docs/examples/users/update-mfa-recovery-codes.md +++ b/docs/examples/users/update-mfa-recovery-codes.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-mfa.md b/docs/examples/users/update-mfa.md index 75dfe95a..217b1eab 100644 --- a/docs/examples/users/update-mfa.md +++ b/docs/examples/users/update-mfa.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-name.md b/docs/examples/users/update-name.md index 1bbed897..b3faa7d2 100644 --- a/docs/examples/users/update-name.md +++ b/docs/examples/users/update-name.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-password.md b/docs/examples/users/update-password.md index 54d67621..c582b499 100644 --- a/docs/examples/users/update-password.md +++ b/docs/examples/users/update-password.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-phone-verification.md b/docs/examples/users/update-phone-verification.md index 9f7fb5e9..0e7bb827 100644 --- a/docs/examples/users/update-phone-verification.md +++ b/docs/examples/users/update-phone-verification.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-phone.md b/docs/examples/users/update-phone.md index f9a72c3c..2d562764 100644 --- a/docs/examples/users/update-phone.md +++ b/docs/examples/users/update-phone.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-prefs.md b/docs/examples/users/update-prefs.md index cca857ea..42580160 100644 --- a/docs/examples/users/update-prefs.md +++ b/docs/examples/users/update-prefs.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-status.md b/docs/examples/users/update-status.md index b31b714d..84c4e0ed 100644 --- a/docs/examples/users/update-status.md +++ b/docs/examples/users/update-status.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/users/update-target.md b/docs/examples/users/update-target.md index c6f6d4a0..6d87b86f 100644 --- a/docs/examples/users/update-target.md +++ b/docs/examples/users/update-target.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/users" ) client := client.New( diff --git a/docs/examples/webhooks/create.md b/docs/examples/webhooks/create.md index 14484c56..1ee686ec 100644 --- a/docs/examples/webhooks/create.md +++ b/docs/examples/webhooks/create.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/webhooks" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/webhooks" ) client := client.New( diff --git a/docs/examples/webhooks/delete.md b/docs/examples/webhooks/delete.md index c193e7b1..687d4e91 100644 --- a/docs/examples/webhooks/delete.md +++ b/docs/examples/webhooks/delete.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/webhooks" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/webhooks" ) client := client.New( diff --git a/docs/examples/webhooks/get.md b/docs/examples/webhooks/get.md index ce01f93b..40c7108e 100644 --- a/docs/examples/webhooks/get.md +++ b/docs/examples/webhooks/get.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/webhooks" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/webhooks" ) client := client.New( diff --git a/docs/examples/webhooks/list.md b/docs/examples/webhooks/list.md index e2d4a851..9529fe19 100644 --- a/docs/examples/webhooks/list.md +++ b/docs/examples/webhooks/list.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/webhooks" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/webhooks" ) client := client.New( diff --git a/docs/examples/webhooks/update-signature.md b/docs/examples/webhooks/update-signature.md index 0c73804f..421c0d71 100644 --- a/docs/examples/webhooks/update-signature.md +++ b/docs/examples/webhooks/update-signature.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/webhooks" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/webhooks" ) client := client.New( diff --git a/docs/examples/webhooks/update.md b/docs/examples/webhooks/update.md index 91f3f2e9..58ff0296 100644 --- a/docs/examples/webhooks/update.md +++ b/docs/examples/webhooks/update.md @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/webhooks" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/webhooks" ) client := client.New( diff --git a/functions/functions.go b/functions/functions.go index 84ebc1a5..814b2d6f 100644 --- a/functions/functions.go +++ b/functions/functions.go @@ -3,9 +3,9 @@ package functions import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" - "github.com/appwrite/sdk-for-go/file" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" + "github.com/appwrite/sdk-for-go/v2/file" "net/url" "fmt" "strings" diff --git a/functions/functions_test.go b/functions/functions_test.go new file mode 100644 index 00000000..963934f3 --- /dev/null +++ b/functions/functions_test.go @@ -0,0 +1,1233 @@ +package functions + +import ( + "net/http" + "net/http/httptest" + "testing" + "os" + + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/file") + +func TestFunctions(t *testing.T) { + tmpFile, err := os.CreateTemp("", "test") + if err != nil { + t.Fatal(err) + } + defer os.Remove(tmpFile.Name()) + _, _ = tmpFile.WriteString("test content") + _ = tmpFile.Close() + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test List", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "functions": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "execute": [], + "name": "My Function", + "enabled": true, + "live": true, + "logging": true, + "runtime": "python-3.8", + "deploymentRetention": 7, + "deploymentId": "5e5ea5c16897e", + "deploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentId": "5e5ea5c16897e", + "latestDeploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentStatus": "ready", + "scopes": [], + "vars": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ], + "events": [], + "schedule": "5 4 * * *", + "timeout": 300, + "entrypoint": "index.js", + "commands": "npm install", + "version": "v2", + "installationId": "6m40at4ejk5h2u9s1hboo", + "providerRepositoryId": "appwrite", + "providerBranch": "main", + "providerRootDirectory": "functions/helloWorld", + "providerSilentMode": true, + "buildSpecification": "s-1vcpu-512mb", + "runtimeSpecification": "s-1vcpu-512mb" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.List() + if err != nil { + t.Errorf("Method List failed: %v", err) + } + }) + + t.Run("Test Create", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "execute": [], + "name": "My Function", + "enabled": true, + "live": true, + "logging": true, + "runtime": "python-3.8", + "deploymentRetention": 7, + "deploymentId": "5e5ea5c16897e", + "deploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentId": "5e5ea5c16897e", + "latestDeploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentStatus": "ready", + "scopes": [], + "vars": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ], + "events": [], + "schedule": "5 4 * * *", + "timeout": 300, + "entrypoint": "index.js", + "commands": "npm install", + "version": "v2", + "installationId": "6m40at4ejk5h2u9s1hboo", + "providerRepositoryId": "appwrite", + "providerBranch": "main", + "providerRootDirectory": "functions/helloWorld", + "providerSilentMode": true, + "buildSpecification": "s-1vcpu-512mb", + "runtimeSpecification": "s-1vcpu-512mb" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Create("", "", "node-14.5") + if err != nil { + t.Errorf("Method Create failed: %v", err) + } + }) + + t.Run("Test ListRuntimes", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "runtimes": [ + { + "$id": "python-3.8", + "key": "python", + "name": "Python", + "version": "3.8", + "base": "python:3.8-alpine", + "image": "appwrite\\/runtime-for-python:3.8", + "logo": "python.png", + "supports": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListRuntimes() + if err != nil { + t.Errorf("Method ListRuntimes failed: %v", err) + } + }) + + t.Run("Test ListSpecifications", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "specifications": [ + { + "memory": 512, + "cpus": 1, + "enabled": true, + "slug": "s-1vcpu-512mb" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListSpecifications() + if err != nil { + t.Errorf("Method ListSpecifications failed: %v", err) + } + }) + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "execute": [], + "name": "My Function", + "enabled": true, + "live": true, + "logging": true, + "runtime": "python-3.8", + "deploymentRetention": 7, + "deploymentId": "5e5ea5c16897e", + "deploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentId": "5e5ea5c16897e", + "latestDeploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentStatus": "ready", + "scopes": [], + "vars": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ], + "events": [], + "schedule": "5 4 * * *", + "timeout": 300, + "entrypoint": "index.js", + "commands": "npm install", + "version": "v2", + "installationId": "6m40at4ejk5h2u9s1hboo", + "providerRepositoryId": "appwrite", + "providerBranch": "main", + "providerRootDirectory": "functions/helloWorld", + "providerSilentMode": true, + "buildSpecification": "s-1vcpu-512mb", + "runtimeSpecification": "s-1vcpu-512mb" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get("") + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test Update", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "execute": [], + "name": "My Function", + "enabled": true, + "live": true, + "logging": true, + "runtime": "python-3.8", + "deploymentRetention": 7, + "deploymentId": "5e5ea5c16897e", + "deploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentId": "5e5ea5c16897e", + "latestDeploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentStatus": "ready", + "scopes": [], + "vars": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ], + "events": [], + "schedule": "5 4 * * *", + "timeout": 300, + "entrypoint": "index.js", + "commands": "npm install", + "version": "v2", + "installationId": "6m40at4ejk5h2u9s1hboo", + "providerRepositoryId": "appwrite", + "providerBranch": "main", + "providerRootDirectory": "functions/helloWorld", + "providerSilentMode": true, + "buildSpecification": "s-1vcpu-512mb", + "runtimeSpecification": "s-1vcpu-512mb" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Update("", "") + if err != nil { + t.Errorf("Method Update failed: %v", err) + } + }) + + t.Run("Test Delete", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Delete("") + if err != nil { + t.Errorf("Method Delete failed: %v", err) + } + }) + + t.Run("Test UpdateFunctionDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "execute": [], + "name": "My Function", + "enabled": true, + "live": true, + "logging": true, + "runtime": "python-3.8", + "deploymentRetention": 7, + "deploymentId": "5e5ea5c16897e", + "deploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentId": "5e5ea5c16897e", + "latestDeploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentStatus": "ready", + "scopes": [], + "vars": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ], + "events": [], + "schedule": "5 4 * * *", + "timeout": 300, + "entrypoint": "index.js", + "commands": "npm install", + "version": "v2", + "installationId": "6m40at4ejk5h2u9s1hboo", + "providerRepositoryId": "appwrite", + "providerBranch": "main", + "providerRootDirectory": "functions/helloWorld", + "providerSilentMode": true, + "buildSpecification": "s-1vcpu-512mb", + "runtimeSpecification": "s-1vcpu-512mb" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateFunctionDeployment("", "") + if err != nil { + t.Errorf("Method UpdateFunctionDeployment failed: %v", err) + } + }) + + t.Run("Test ListDeployments", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "deployments": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListDeployments("") + if err != nil { + t.Errorf("Method ListDeployments failed: %v", err) + } + }) + + t.Run("Test CreateDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == "GET" && "POST" != "GET" { + // Handle file upload resume check + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"chunksUploaded": 0}`)) + return + } + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateDeployment("", file.NewInputFile(tmpFile.Name(), "test.txt"), true) + if err != nil { + t.Errorf("Method CreateDeployment failed: %v", err) + } + }) + + t.Run("Test CreateDuplicateDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateDuplicateDeployment("", "") + if err != nil { + t.Errorf("Method CreateDuplicateDeployment failed: %v", err) + } + }) + + t.Run("Test CreateTemplateDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTemplateDeployment("", "", "", "", "commit", "") + if err != nil { + t.Errorf("Method CreateTemplateDeployment failed: %v", err) + } + }) + + t.Run("Test CreateVcsDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateVcsDeployment("", "branch", "") + if err != nil { + t.Errorf("Method CreateVcsDeployment failed: %v", err) + } + }) + + t.Run("Test GetDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetDeployment("", "") + if err != nil { + t.Errorf("Method GetDeployment failed: %v", err) + } + }) + + t.Run("Test DeleteDeployment", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteDeployment("", "") + if err != nil { + t.Errorf("Method DeleteDeployment failed: %v", err) + } + }) + + t.Run("Test GetDeploymentDownload", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetDeploymentDownload("", "") + if err != nil { + t.Errorf("Method GetDeploymentDownload failed: %v", err) + } + }) + + t.Run("Test UpdateDeploymentStatus", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateDeploymentStatus("", "") + if err != nil { + t.Errorf("Method UpdateDeploymentStatus failed: %v", err) + } + }) + + t.Run("Test ListExecutions", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "executions": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "functionId": "5e5ea6g16897e", + "deploymentId": "5e5ea5c16897e", + "trigger": "http", + "status": "processing", + "requestMethod": "GET", + "requestPath": "/articles?id=5", + "requestHeaders": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "responseStatusCode": 200, + "responseBody": "string", + "responseHeaders": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "logs": "string", + "errors": "string", + "duration": 0.4 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListExecutions("") + if err != nil { + t.Errorf("Method ListExecutions failed: %v", err) + } + }) + + t.Run("Test CreateExecution", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "functionId": "5e5ea6g16897e", + "deploymentId": "5e5ea5c16897e", + "trigger": "http", + "status": "processing", + "requestMethod": "GET", + "requestPath": "/articles?id=5", + "requestHeaders": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "responseStatusCode": 200, + "responseBody": "string", + "responseHeaders": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "logs": "string", + "errors": "string", + "duration": 0.4 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateExecution("") + if err != nil { + t.Errorf("Method CreateExecution failed: %v", err) + } + }) + + t.Run("Test GetExecution", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "functionId": "5e5ea6g16897e", + "deploymentId": "5e5ea5c16897e", + "trigger": "http", + "status": "processing", + "requestMethod": "GET", + "requestPath": "/articles?id=5", + "requestHeaders": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "responseStatusCode": 200, + "responseBody": "string", + "responseHeaders": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "logs": "string", + "errors": "string", + "duration": 0.4 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetExecution("", "") + if err != nil { + t.Errorf("Method GetExecution failed: %v", err) + } + }) + + t.Run("Test DeleteExecution", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteExecution("", "") + if err != nil { + t.Errorf("Method DeleteExecution failed: %v", err) + } + }) + + t.Run("Test ListVariables", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "variables": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListVariables("") + if err != nil { + t.Errorf("Method ListVariables failed: %v", err) + } + }) + + t.Run("Test CreateVariable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateVariable("", "", "") + if err != nil { + t.Errorf("Method CreateVariable failed: %v", err) + } + }) + + t.Run("Test GetVariable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetVariable("", "") + if err != nil { + t.Errorf("Method GetVariable failed: %v", err) + } + }) + + t.Run("Test UpdateVariable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateVariable("", "", "") + if err != nil { + t.Errorf("Method UpdateVariable failed: %v", err) + } + }) + + t.Run("Test DeleteVariable", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteVariable("", "") + if err != nil { + t.Errorf("Method DeleteVariable failed: %v", err) + } + }) +} diff --git a/go.mod b/go.mod index 04d010d3..3026adf9 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/appwrite/sdk-for-go +module github.com/appwrite/sdk-for-go/v2 go 1.22.5 diff --git a/graphql/graphql.go b/graphql/graphql.go index 243b956d..426e03c4 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -3,7 +3,7 @@ package graphql import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/v2/client" "strings" ) diff --git a/graphql/graphql_test.go b/graphql/graphql_test.go new file mode 100644 index 00000000..475ea589 --- /dev/null +++ b/graphql/graphql_test.go @@ -0,0 +1,70 @@ +package graphql + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestGraphql(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test Query", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Query(map[string]interface{}{}) + if err != nil { + t.Errorf("Method Query failed: %v", err) + } + }) + + t.Run("Test Mutation", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Mutation(map[string]interface{}{}) + if err != nil { + t.Errorf("Method Mutation failed: %v", err) + } + }) +} diff --git a/health/health.go b/health/health.go index 6cbe5af2..81d251f4 100644 --- a/health/health.go +++ b/health/health.go @@ -3,8 +3,8 @@ package health import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/health/health_test.go b/health/health_test.go new file mode 100644 index 00000000..075c1bee --- /dev/null +++ b/health/health_test.go @@ -0,0 +1,679 @@ +package health + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestHealth(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "name": "database", + "ping": 128, + "status": "pass" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get() + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test GetAntivirus", func(t *testing.T) { + mockResponse := ` +{ + "version": "1.0.0", + "status": "online" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetAntivirus() + if err != nil { + t.Errorf("Method GetAntivirus failed: %v", err) + } + }) + + t.Run("Test GetCache", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "statuses": [ + { + "name": "database", + "ping": 128, + "status": "pass" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetCache() + if err != nil { + t.Errorf("Method GetCache failed: %v", err) + } + }) + + t.Run("Test GetCertificate", func(t *testing.T) { + mockResponse := ` +{ + "name": "/CN=www.google.com", + "subjectSN": "string", + "issuerOrganisation": "string", + "validFrom": "1704200998", + "validTo": "1711458597", + "signatureTypeSN": "RSA-SHA256" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetCertificate() + if err != nil { + t.Errorf("Method GetCertificate failed: %v", err) + } + }) + + t.Run("Test GetConsolePausing", func(t *testing.T) { + mockResponse := ` +{ + "name": "database", + "ping": 128, + "status": "pass" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetConsolePausing() + if err != nil { + t.Errorf("Method GetConsolePausing failed: %v", err) + } + }) + + t.Run("Test GetDB", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "statuses": [ + { + "name": "database", + "ping": 128, + "status": "pass" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetDB() + if err != nil { + t.Errorf("Method GetDB failed: %v", err) + } + }) + + t.Run("Test GetPubSub", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "statuses": [ + { + "name": "database", + "ping": 128, + "status": "pass" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetPubSub() + if err != nil { + t.Errorf("Method GetPubSub failed: %v", err) + } + }) + + t.Run("Test GetQueueAudits", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueAudits() + if err != nil { + t.Errorf("Method GetQueueAudits failed: %v", err) + } + }) + + t.Run("Test GetQueueBuilds", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueBuilds() + if err != nil { + t.Errorf("Method GetQueueBuilds failed: %v", err) + } + }) + + t.Run("Test GetQueueCertificates", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueCertificates() + if err != nil { + t.Errorf("Method GetQueueCertificates failed: %v", err) + } + }) + + t.Run("Test GetQueueDatabases", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueDatabases() + if err != nil { + t.Errorf("Method GetQueueDatabases failed: %v", err) + } + }) + + t.Run("Test GetQueueDeletes", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueDeletes() + if err != nil { + t.Errorf("Method GetQueueDeletes failed: %v", err) + } + }) + + t.Run("Test GetFailedJobs", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetFailedJobs("v1-database") + if err != nil { + t.Errorf("Method GetFailedJobs failed: %v", err) + } + }) + + t.Run("Test GetQueueFunctions", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueFunctions() + if err != nil { + t.Errorf("Method GetQueueFunctions failed: %v", err) + } + }) + + t.Run("Test GetQueueLogs", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueLogs() + if err != nil { + t.Errorf("Method GetQueueLogs failed: %v", err) + } + }) + + t.Run("Test GetQueueMails", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueMails() + if err != nil { + t.Errorf("Method GetQueueMails failed: %v", err) + } + }) + + t.Run("Test GetQueueMessaging", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueMessaging() + if err != nil { + t.Errorf("Method GetQueueMessaging failed: %v", err) + } + }) + + t.Run("Test GetQueueMigrations", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueMigrations() + if err != nil { + t.Errorf("Method GetQueueMigrations failed: %v", err) + } + }) + + t.Run("Test GetQueueStatsResources", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueStatsResources() + if err != nil { + t.Errorf("Method GetQueueStatsResources failed: %v", err) + } + }) + + t.Run("Test GetQueueUsage", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueUsage() + if err != nil { + t.Errorf("Method GetQueueUsage failed: %v", err) + } + }) + + t.Run("Test GetQueueWebhooks", func(t *testing.T) { + mockResponse := ` +{ + "size": 8 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetQueueWebhooks() + if err != nil { + t.Errorf("Method GetQueueWebhooks failed: %v", err) + } + }) + + t.Run("Test GetStorage", func(t *testing.T) { + mockResponse := ` +{ + "name": "database", + "ping": 128, + "status": "pass" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetStorage() + if err != nil { + t.Errorf("Method GetStorage failed: %v", err) + } + }) + + t.Run("Test GetStorageLocal", func(t *testing.T) { + mockResponse := ` +{ + "name": "database", + "ping": 128, + "status": "pass" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetStorageLocal() + if err != nil { + t.Errorf("Method GetStorageLocal failed: %v", err) + } + }) + + t.Run("Test GetTime", func(t *testing.T) { + mockResponse := ` +{ + "remoteTime": 1639490751, + "localTime": 1639490844, + "diff": 93 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetTime() + if err != nil { + t.Errorf("Method GetTime failed: %v", err) + } + }) +} diff --git a/id/id_test.go b/id/id_test.go new file mode 100644 index 00000000..9e1dec4d --- /dev/null +++ b/id/id_test.go @@ -0,0 +1,19 @@ +package id + +import ( + "testing" +) + +func TestUnique(t *testing.T) { + id := Unique() + if len(id) < 15 || len(id) > 25 { + t.Errorf("Expected length between 15 and 25, got %d", len(id)) + } +} + +func TestCustom(t *testing.T) { + id := Custom("custom_id") + if id != "custom_id" { + t.Errorf("Expected custom_id, got %s", id) + } +} diff --git a/locale/locale.go b/locale/locale.go index 106b8d40..787f6bf0 100644 --- a/locale/locale.go +++ b/locale/locale.go @@ -3,8 +3,8 @@ package locale import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/locale/locale_test.go b/locale/locale_test.go new file mode 100644 index 00000000..a1c04136 --- /dev/null +++ b/locale/locale_test.go @@ -0,0 +1,281 @@ +package locale + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestLocale(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "ip": "127.0.0.1", + "countryCode": "US", + "country": "United States", + "continentCode": "NA", + "continent": "North America", + "eu": true, + "currency": "USD" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get() + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test ListCodes", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "localeCodes": [ + { + "code": "en-us", + "name": "US" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListCodes() + if err != nil { + t.Errorf("Method ListCodes failed: %v", err) + } + }) + + t.Run("Test ListContinents", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "continents": [ + { + "name": "Europe", + "code": "EU" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListContinents() + if err != nil { + t.Errorf("Method ListContinents failed: %v", err) + } + }) + + t.Run("Test ListCountries", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "countries": [ + { + "name": "United States", + "code": "US" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListCountries() + if err != nil { + t.Errorf("Method ListCountries failed: %v", err) + } + }) + + t.Run("Test ListCountriesEU", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "countries": [ + { + "name": "United States", + "code": "US" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListCountriesEU() + if err != nil { + t.Errorf("Method ListCountriesEU failed: %v", err) + } + }) + + t.Run("Test ListCountriesPhones", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "phones": [ + { + "code": "+1", + "countryCode": "US", + "countryName": "United States" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListCountriesPhones() + if err != nil { + t.Errorf("Method ListCountriesPhones failed: %v", err) + } + }) + + t.Run("Test ListCurrencies", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "currencies": [ + { + "symbol": "$", + "name": "US dollar", + "symbolNative": "$", + "decimalDigits": 2, + "rounding": 0, + "code": "USD", + "namePlural": "US dollars" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListCurrencies() + if err != nil { + t.Errorf("Method ListCurrencies failed: %v", err) + } + }) + + t.Run("Test ListLanguages", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "languages": [ + { + "name": "Italian", + "code": "it", + "nativeName": "Italiano" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListLanguages() + if err != nil { + t.Errorf("Method ListLanguages failed: %v", err) + } + }) +} diff --git a/messaging/messaging.go b/messaging/messaging.go index 7c59c972..751406e5 100644 --- a/messaging/messaging.go +++ b/messaging/messaging.go @@ -3,8 +3,8 @@ package messaging import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/messaging/messaging_test.go b/messaging/messaging_test.go new file mode 100644 index 00000000..0e8c535e --- /dev/null +++ b/messaging/messaging_test.go @@ -0,0 +1,1985 @@ +package messaging + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestMessaging(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test ListMessages", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "messages": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "providerType": "email", + "topics": [], + "users": [], + "targets": [], + "deliveredTotal": 1, + "data": {}, + "status": "processing" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListMessages() + if err != nil { + t.Errorf("Method ListMessages failed: %v", err) + } + }) + + t.Run("Test CreateEmail", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "providerType": "email", + "topics": [], + "users": [], + "targets": [], + "deliveredTotal": 1, + "data": {}, + "status": "processing" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateEmail("", "", "") + if err != nil { + t.Errorf("Method CreateEmail failed: %v", err) + } + }) + + t.Run("Test UpdateEmail", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "providerType": "email", + "topics": [], + "users": [], + "targets": [], + "deliveredTotal": 1, + "data": {}, + "status": "processing" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateEmail("") + if err != nil { + t.Errorf("Method UpdateEmail failed: %v", err) + } + }) + + t.Run("Test CreatePush", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "providerType": "email", + "topics": [], + "users": [], + "targets": [], + "deliveredTotal": 1, + "data": {}, + "status": "processing" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreatePush("") + if err != nil { + t.Errorf("Method CreatePush failed: %v", err) + } + }) + + t.Run("Test UpdatePush", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "providerType": "email", + "topics": [], + "users": [], + "targets": [], + "deliveredTotal": 1, + "data": {}, + "status": "processing" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePush("") + if err != nil { + t.Errorf("Method UpdatePush failed: %v", err) + } + }) + + t.Run("Test CreateSms", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "providerType": "email", + "topics": [], + "users": [], + "targets": [], + "deliveredTotal": 1, + "data": {}, + "status": "processing" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateSms("", "") + if err != nil { + t.Errorf("Method CreateSms failed: %v", err) + } + }) + + t.Run("Test CreateSMS", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "providerType": "email", + "topics": [], + "users": [], + "targets": [], + "deliveredTotal": 1, + "data": {}, + "status": "processing" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateSMS("", "") + if err != nil { + t.Errorf("Method CreateSMS failed: %v", err) + } + }) + + t.Run("Test UpdateSms", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "providerType": "email", + "topics": [], + "users": [], + "targets": [], + "deliveredTotal": 1, + "data": {}, + "status": "processing" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSms("") + if err != nil { + t.Errorf("Method UpdateSms failed: %v", err) + } + }) + + t.Run("Test UpdateSMS", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "providerType": "email", + "topics": [], + "users": [], + "targets": [], + "deliveredTotal": 1, + "data": {}, + "status": "processing" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSMS("") + if err != nil { + t.Errorf("Method UpdateSMS failed: %v", err) + } + }) + + t.Run("Test GetMessage", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "providerType": "email", + "topics": [], + "users": [], + "targets": [], + "deliveredTotal": 1, + "data": {}, + "status": "processing" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetMessage("") + if err != nil { + t.Errorf("Method GetMessage failed: %v", err) + } + }) + + t.Run("Test Delete", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Delete("") + if err != nil { + t.Errorf("Method Delete failed: %v", err) + } + }) + + t.Run("Test ListMessageLogs", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "logs": [ + { + "event": "account.sessions.create", + "userId": "610fc2f985ee0", + "userEmail": "john@appwrite.io", + "userName": "John Doe", + "mode": "admin", + "ip": "127.0.0.1", + "time": "2020-10-15T06:38:00.000+00:00", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListMessageLogs("") + if err != nil { + t.Errorf("Method ListMessageLogs failed: %v", err) + } + }) + + t.Run("Test ListTargets", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListTargets("") + if err != nil { + t.Errorf("Method ListTargets failed: %v", err) + } + }) + + t.Run("Test ListProviders", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "providers": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListProviders() + if err != nil { + t.Errorf("Method ListProviders failed: %v", err) + } + }) + + t.Run("Test CreateApnsProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateApnsProvider("", "") + if err != nil { + t.Errorf("Method CreateApnsProvider failed: %v", err) + } + }) + + t.Run("Test CreateAPNSProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateAPNSProvider("", "") + if err != nil { + t.Errorf("Method CreateAPNSProvider failed: %v", err) + } + }) + + t.Run("Test UpdateApnsProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateApnsProvider("") + if err != nil { + t.Errorf("Method UpdateApnsProvider failed: %v", err) + } + }) + + t.Run("Test UpdateAPNSProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateAPNSProvider("") + if err != nil { + t.Errorf("Method UpdateAPNSProvider failed: %v", err) + } + }) + + t.Run("Test CreateFcmProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateFcmProvider("", "") + if err != nil { + t.Errorf("Method CreateFcmProvider failed: %v", err) + } + }) + + t.Run("Test CreateFCMProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateFCMProvider("", "") + if err != nil { + t.Errorf("Method CreateFCMProvider failed: %v", err) + } + }) + + t.Run("Test UpdateFcmProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateFcmProvider("") + if err != nil { + t.Errorf("Method UpdateFcmProvider failed: %v", err) + } + }) + + t.Run("Test UpdateFCMProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateFCMProvider("") + if err != nil { + t.Errorf("Method UpdateFCMProvider failed: %v", err) + } + }) + + t.Run("Test CreateMailgunProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMailgunProvider("", "") + if err != nil { + t.Errorf("Method CreateMailgunProvider failed: %v", err) + } + }) + + t.Run("Test UpdateMailgunProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMailgunProvider("") + if err != nil { + t.Errorf("Method UpdateMailgunProvider failed: %v", err) + } + }) + + t.Run("Test CreateMsg91Provider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMsg91Provider("", "") + if err != nil { + t.Errorf("Method CreateMsg91Provider failed: %v", err) + } + }) + + t.Run("Test UpdateMsg91Provider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMsg91Provider("") + if err != nil { + t.Errorf("Method UpdateMsg91Provider failed: %v", err) + } + }) + + t.Run("Test CreateResendProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateResendProvider("", "") + if err != nil { + t.Errorf("Method CreateResendProvider failed: %v", err) + } + }) + + t.Run("Test UpdateResendProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateResendProvider("") + if err != nil { + t.Errorf("Method UpdateResendProvider failed: %v", err) + } + }) + + t.Run("Test CreateSendgridProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateSendgridProvider("", "") + if err != nil { + t.Errorf("Method CreateSendgridProvider failed: %v", err) + } + }) + + t.Run("Test UpdateSendgridProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSendgridProvider("") + if err != nil { + t.Errorf("Method UpdateSendgridProvider failed: %v", err) + } + }) + + t.Run("Test CreateSmtpProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateSmtpProvider("", "", "") + if err != nil { + t.Errorf("Method CreateSmtpProvider failed: %v", err) + } + }) + + t.Run("Test CreateSMTPProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateSMTPProvider("", "", "") + if err != nil { + t.Errorf("Method CreateSMTPProvider failed: %v", err) + } + }) + + t.Run("Test UpdateSmtpProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSmtpProvider("") + if err != nil { + t.Errorf("Method UpdateSmtpProvider failed: %v", err) + } + }) + + t.Run("Test UpdateSMTPProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSMTPProvider("") + if err != nil { + t.Errorf("Method UpdateSMTPProvider failed: %v", err) + } + }) + + t.Run("Test CreateTelesignProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTelesignProvider("", "") + if err != nil { + t.Errorf("Method CreateTelesignProvider failed: %v", err) + } + }) + + t.Run("Test UpdateTelesignProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateTelesignProvider("") + if err != nil { + t.Errorf("Method UpdateTelesignProvider failed: %v", err) + } + }) + + t.Run("Test CreateTextmagicProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTextmagicProvider("", "") + if err != nil { + t.Errorf("Method CreateTextmagicProvider failed: %v", err) + } + }) + + t.Run("Test UpdateTextmagicProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateTextmagicProvider("") + if err != nil { + t.Errorf("Method UpdateTextmagicProvider failed: %v", err) + } + }) + + t.Run("Test CreateTwilioProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTwilioProvider("", "") + if err != nil { + t.Errorf("Method CreateTwilioProvider failed: %v", err) + } + }) + + t.Run("Test UpdateTwilioProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateTwilioProvider("") + if err != nil { + t.Errorf("Method UpdateTwilioProvider failed: %v", err) + } + }) + + t.Run("Test CreateVonageProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateVonageProvider("", "") + if err != nil { + t.Errorf("Method CreateVonageProvider failed: %v", err) + } + }) + + t.Run("Test UpdateVonageProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateVonageProvider("") + if err != nil { + t.Errorf("Method UpdateVonageProvider failed: %v", err) + } + }) + + t.Run("Test GetProvider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": true, + "type": "sms", + "credentials": {} +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetProvider("") + if err != nil { + t.Errorf("Method GetProvider failed: %v", err) + } + }) + + t.Run("Test DeleteProvider", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteProvider("") + if err != nil { + t.Errorf("Method DeleteProvider failed: %v", err) + } + }) + + t.Run("Test ListProviderLogs", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "logs": [ + { + "event": "account.sessions.create", + "userId": "610fc2f985ee0", + "userEmail": "john@appwrite.io", + "userName": "John Doe", + "mode": "admin", + "ip": "127.0.0.1", + "time": "2020-10-15T06:38:00.000+00:00", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListProviderLogs("") + if err != nil { + t.Errorf("Method ListProviderLogs failed: %v", err) + } + }) + + t.Run("Test ListSubscriberLogs", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "logs": [ + { + "event": "account.sessions.create", + "userId": "610fc2f985ee0", + "userEmail": "john@appwrite.io", + "userName": "John Doe", + "mode": "admin", + "ip": "127.0.0.1", + "time": "2020-10-15T06:38:00.000+00:00", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListSubscriberLogs("") + if err != nil { + t.Errorf("Method ListSubscriberLogs failed: %v", err) + } + }) + + t.Run("Test ListTopics", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "topics": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "events", + "emailTotal": 100, + "smsTotal": 100, + "pushTotal": 100, + "subscribe": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListTopics() + if err != nil { + t.Errorf("Method ListTopics failed: %v", err) + } + }) + + t.Run("Test CreateTopic", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "events", + "emailTotal": 100, + "smsTotal": 100, + "pushTotal": 100, + "subscribe": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTopic("", "") + if err != nil { + t.Errorf("Method CreateTopic failed: %v", err) + } + }) + + t.Run("Test GetTopic", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "events", + "emailTotal": 100, + "smsTotal": 100, + "pushTotal": 100, + "subscribe": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetTopic("") + if err != nil { + t.Errorf("Method GetTopic failed: %v", err) + } + }) + + t.Run("Test UpdateTopic", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "events", + "emailTotal": 100, + "smsTotal": 100, + "pushTotal": 100, + "subscribe": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateTopic("") + if err != nil { + t.Errorf("Method UpdateTopic failed: %v", err) + } + }) + + t.Run("Test DeleteTopic", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteTopic("") + if err != nil { + t.Errorf("Method DeleteTopic failed: %v", err) + } + }) + + t.Run("Test ListTopicLogs", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "logs": [ + { + "event": "account.sessions.create", + "userId": "610fc2f985ee0", + "userEmail": "john@appwrite.io", + "userName": "John Doe", + "mode": "admin", + "ip": "127.0.0.1", + "time": "2020-10-15T06:38:00.000+00:00", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListTopicLogs("") + if err != nil { + t.Errorf("Method ListTopicLogs failed: %v", err) + } + }) + + t.Run("Test ListSubscribers", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "subscribers": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "targetId": "259125845563242502", + "target": { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + }, + "userId": "5e5ea5c16897e", + "userName": "Aegon Targaryen", + "topicId": "259125845563242502", + "providerType": "email" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListSubscribers("") + if err != nil { + t.Errorf("Method ListSubscribers failed: %v", err) + } + }) + + t.Run("Test CreateSubscriber", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "targetId": "259125845563242502", + "target": { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + }, + "userId": "5e5ea5c16897e", + "userName": "Aegon Targaryen", + "topicId": "259125845563242502", + "providerType": "email" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateSubscriber("", "", "") + if err != nil { + t.Errorf("Method CreateSubscriber failed: %v", err) + } + }) + + t.Run("Test GetSubscriber", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "targetId": "259125845563242502", + "target": { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + }, + "userId": "5e5ea5c16897e", + "userName": "Aegon Targaryen", + "topicId": "259125845563242502", + "providerType": "email" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetSubscriber("", "") + if err != nil { + t.Errorf("Method GetSubscriber failed: %v", err) + } + }) + + t.Run("Test DeleteSubscriber", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteSubscriber("", "") + if err != nil { + t.Errorf("Method DeleteSubscriber failed: %v", err) + } + }) +} diff --git a/models/activity_event_list_test.go b/models/activity_event_list_test.go new file mode 100644 index 00000000..4c299610 --- /dev/null +++ b/models/activity_event_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestActivityEventListModel(t *testing.T) { + model := ActivityEventList{ Total: 5, Events: []ActivityEvent{ActivityEvent{ Id: "5e5ea5c16897e", UserType: "user", UserId: "610fc2f985ee0", UserEmail: "john@appwrite.io", UserName: "John Doe", ResourceParent: "database/ID", ResourceType: "collection", ResourceId: "610fc2f985ee0", Resource: "collections/610fc2f985ee0", Event: "account.sessions.create", UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36", Ip: "127.0.0.1", Mode: "admin", Country: "US", Time: "2020-10-15T06:38:00.000+00:00", ProjectId: "610fc2f985ee0", TeamId: "610fc2f985ee0", Hostname: "appwrite.io", OsCode: "Mac", OsName: "Mac", OsVersion: "Mac", ClientType: "browser", ClientCode: "CM", ClientName: "Chrome Mobile iOS", ClientVersion: "84.0", ClientEngine: "WebKit", ClientEngineVersion: "605.1.15", DeviceName: "smartphone", DeviceBrand: "Google", DeviceModel: "Nexus 5", CountryCode: "US", CountryName: "United States", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ActivityEventList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/activity_event_test.go b/models/activity_event_test.go new file mode 100644 index 00000000..2ce41227 --- /dev/null +++ b/models/activity_event_test.go @@ -0,0 +1,116 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestActivityEventModel(t *testing.T) { + model := ActivityEvent{ Id: "5e5ea5c16897e", UserType: "user", UserId: "610fc2f985ee0", UserEmail: "john@appwrite.io", UserName: "John Doe", ResourceParent: "database/ID", ResourceType: "collection", ResourceId: "610fc2f985ee0", Resource: "collections/610fc2f985ee0", Event: "account.sessions.create", UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36", Ip: "127.0.0.1", Mode: "admin", Country: "US", Time: "2020-10-15T06:38:00.000+00:00", ProjectId: "610fc2f985ee0", TeamId: "610fc2f985ee0", Hostname: "appwrite.io", OsCode: "Mac", OsName: "Mac", OsVersion: "Mac", ClientType: "browser", ClientCode: "CM", ClientName: "Chrome Mobile iOS", ClientVersion: "84.0", ClientEngine: "WebKit", ClientEngineVersion: "605.1.15", DeviceName: "smartphone", DeviceBrand: "Google", DeviceModel: "Nexus 5", CountryCode: "US", CountryName: "United States", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ActivityEvent + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.UserType != model.UserType { + t.Errorf("Expected UserType %v, got %v", model.UserType, result.UserType) + } + if result.UserId != model.UserId { + t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) + } + if result.UserEmail != model.UserEmail { + t.Errorf("Expected UserEmail %v, got %v", model.UserEmail, result.UserEmail) + } + if result.UserName != model.UserName { + t.Errorf("Expected UserName %v, got %v", model.UserName, result.UserName) + } + if result.ResourceParent != model.ResourceParent { + t.Errorf("Expected ResourceParent %v, got %v", model.ResourceParent, result.ResourceParent) + } + if result.ResourceType != model.ResourceType { + t.Errorf("Expected ResourceType %v, got %v", model.ResourceType, result.ResourceType) + } + if result.ResourceId != model.ResourceId { + t.Errorf("Expected ResourceId %v, got %v", model.ResourceId, result.ResourceId) + } + if result.Resource != model.Resource { + t.Errorf("Expected Resource %v, got %v", model.Resource, result.Resource) + } + if result.Event != model.Event { + t.Errorf("Expected Event %v, got %v", model.Event, result.Event) + } + if result.UserAgent != model.UserAgent { + t.Errorf("Expected UserAgent %v, got %v", model.UserAgent, result.UserAgent) + } + if result.Ip != model.Ip { + t.Errorf("Expected Ip %v, got %v", model.Ip, result.Ip) + } + if result.Mode != model.Mode { + t.Errorf("Expected Mode %v, got %v", model.Mode, result.Mode) + } + if result.Country != model.Country { + t.Errorf("Expected Country %v, got %v", model.Country, result.Country) + } + if result.Time != model.Time { + t.Errorf("Expected Time %v, got %v", model.Time, result.Time) + } + if result.ProjectId != model.ProjectId { + t.Errorf("Expected ProjectId %v, got %v", model.ProjectId, result.ProjectId) + } + if result.TeamId != model.TeamId { + t.Errorf("Expected TeamId %v, got %v", model.TeamId, result.TeamId) + } + if result.Hostname != model.Hostname { + t.Errorf("Expected Hostname %v, got %v", model.Hostname, result.Hostname) + } + if result.OsCode != model.OsCode { + t.Errorf("Expected OsCode %v, got %v", model.OsCode, result.OsCode) + } + if result.OsName != model.OsName { + t.Errorf("Expected OsName %v, got %v", model.OsName, result.OsName) + } + if result.OsVersion != model.OsVersion { + t.Errorf("Expected OsVersion %v, got %v", model.OsVersion, result.OsVersion) + } + if result.ClientType != model.ClientType { + t.Errorf("Expected ClientType %v, got %v", model.ClientType, result.ClientType) + } + if result.ClientCode != model.ClientCode { + t.Errorf("Expected ClientCode %v, got %v", model.ClientCode, result.ClientCode) + } + if result.ClientName != model.ClientName { + t.Errorf("Expected ClientName %v, got %v", model.ClientName, result.ClientName) + } + if result.ClientVersion != model.ClientVersion { + t.Errorf("Expected ClientVersion %v, got %v", model.ClientVersion, result.ClientVersion) + } + if result.ClientEngine != model.ClientEngine { + t.Errorf("Expected ClientEngine %v, got %v", model.ClientEngine, result.ClientEngine) + } + if result.ClientEngineVersion != model.ClientEngineVersion { + t.Errorf("Expected ClientEngineVersion %v, got %v", model.ClientEngineVersion, result.ClientEngineVersion) + } + if result.DeviceName != model.DeviceName { + t.Errorf("Expected DeviceName %v, got %v", model.DeviceName, result.DeviceName) + } + if result.DeviceBrand != model.DeviceBrand { + t.Errorf("Expected DeviceBrand %v, got %v", model.DeviceBrand, result.DeviceBrand) + } + if result.DeviceModel != model.DeviceModel { + t.Errorf("Expected DeviceModel %v, got %v", model.DeviceModel, result.DeviceModel) + } + if result.CountryCode != model.CountryCode { + t.Errorf("Expected CountryCode %v, got %v", model.CountryCode, result.CountryCode) + } + if result.CountryName != model.CountryName { + t.Errorf("Expected CountryName %v, got %v", model.CountryName, result.CountryName) + }} diff --git a/models/algo_argon2_test.go b/models/algo_argon2_test.go new file mode 100644 index 00000000..6a1fe537 --- /dev/null +++ b/models/algo_argon2_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAlgoArgon2Model(t *testing.T) { + model := AlgoArgon2{ Type: "argon2", MemoryCost: 65536, TimeCost: 4, Threads: 3, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AlgoArgon2 + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.MemoryCost != model.MemoryCost { + t.Errorf("Expected MemoryCost %v, got %v", model.MemoryCost, result.MemoryCost) + } + if result.TimeCost != model.TimeCost { + t.Errorf("Expected TimeCost %v, got %v", model.TimeCost, result.TimeCost) + } + if result.Threads != model.Threads { + t.Errorf("Expected Threads %v, got %v", model.Threads, result.Threads) + }} diff --git a/models/algo_bcrypt_test.go b/models/algo_bcrypt_test.go new file mode 100644 index 00000000..44cc8f6f --- /dev/null +++ b/models/algo_bcrypt_test.go @@ -0,0 +1,23 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAlgoBcryptModel(t *testing.T) { + model := AlgoBcrypt{ Type: "bcrypt", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AlgoBcrypt + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + }} diff --git a/models/algo_md5_test.go b/models/algo_md5_test.go new file mode 100644 index 00000000..8a26cd70 --- /dev/null +++ b/models/algo_md5_test.go @@ -0,0 +1,23 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAlgoMd5Model(t *testing.T) { + model := AlgoMd5{ Type: "md5", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AlgoMd5 + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + }} diff --git a/models/algo_phpass_test.go b/models/algo_phpass_test.go new file mode 100644 index 00000000..3d45b134 --- /dev/null +++ b/models/algo_phpass_test.go @@ -0,0 +1,23 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAlgoPhpassModel(t *testing.T) { + model := AlgoPhpass{ Type: "phpass", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AlgoPhpass + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + }} diff --git a/models/algo_scrypt_modified_test.go b/models/algo_scrypt_modified_test.go new file mode 100644 index 00000000..30d428f3 --- /dev/null +++ b/models/algo_scrypt_modified_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAlgoScryptModifiedModel(t *testing.T) { + model := AlgoScryptModified{ Type: "scryptMod", Salt: "UxLMreBr6tYyjQ==", SaltSeparator: "Bw==", SignerKey: "XyEKE9RcTDeLEsL/RjwPDBv/RqDl8fb3gpYEOQaPihbxf1ZAtSOHCjuAAa7Q3oHpCYhXSN9tizHgVOwn6krflQ==", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AlgoScryptModified + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Salt != model.Salt { + t.Errorf("Expected Salt %v, got %v", model.Salt, result.Salt) + } + if result.SaltSeparator != model.SaltSeparator { + t.Errorf("Expected SaltSeparator %v, got %v", model.SaltSeparator, result.SaltSeparator) + } + if result.SignerKey != model.SignerKey { + t.Errorf("Expected SignerKey %v, got %v", model.SignerKey, result.SignerKey) + }} diff --git a/models/algo_scrypt_test.go b/models/algo_scrypt_test.go new file mode 100644 index 00000000..ce4dbd77 --- /dev/null +++ b/models/algo_scrypt_test.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAlgoScryptModel(t *testing.T) { + model := AlgoScrypt{ Type: "scrypt", CostCpu: 8, CostMemory: 14, CostParallel: 1, Length: 64, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AlgoScrypt + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.CostCpu != model.CostCpu { + t.Errorf("Expected CostCpu %v, got %v", model.CostCpu, result.CostCpu) + } + if result.CostMemory != model.CostMemory { + t.Errorf("Expected CostMemory %v, got %v", model.CostMemory, result.CostMemory) + } + if result.CostParallel != model.CostParallel { + t.Errorf("Expected CostParallel %v, got %v", model.CostParallel, result.CostParallel) + } + if result.Length != model.Length { + t.Errorf("Expected Length %v, got %v", model.Length, result.Length) + }} diff --git a/models/algo_sha_test.go b/models/algo_sha_test.go new file mode 100644 index 00000000..b316161f --- /dev/null +++ b/models/algo_sha_test.go @@ -0,0 +1,23 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAlgoShaModel(t *testing.T) { + model := AlgoSha{ Type: "sha", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AlgoSha + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + }} diff --git a/models/attribute_boolean_test.go b/models/attribute_boolean_test.go new file mode 100644 index 00000000..ad2d8591 --- /dev/null +++ b/models/attribute_boolean_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeBooleanModel(t *testing.T) { + model := AttributeBoolean{ Key: "isEnabled", Type: "boolean", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeBoolean + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/attribute_datetime_test.go b/models/attribute_datetime_test.go new file mode 100644 index 00000000..af0635e0 --- /dev/null +++ b/models/attribute_datetime_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeDatetimeModel(t *testing.T) { + model := AttributeDatetime{ Key: "birthDay", Type: "datetime", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Format: "datetime", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeDatetime + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Format != model.Format { + t.Errorf("Expected Format %v, got %v", model.Format, result.Format) + }} diff --git a/models/attribute_email_test.go b/models/attribute_email_test.go new file mode 100644 index 00000000..f51bd6f6 --- /dev/null +++ b/models/attribute_email_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeEmailModel(t *testing.T) { + model := AttributeEmail{ Key: "userEmail", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Format: "email", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeEmail + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Format != model.Format { + t.Errorf("Expected Format %v, got %v", model.Format, result.Format) + }} diff --git a/models/attribute_enum_test.go b/models/attribute_enum_test.go new file mode 100644 index 00000000..f303d0af --- /dev/null +++ b/models/attribute_enum_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeEnumModel(t *testing.T) { + model := AttributeEnum{ Key: "status", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Elements: []string{"test"}, Format: "enum", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeEnum + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Format != model.Format { + t.Errorf("Expected Format %v, got %v", model.Format, result.Format) + }} diff --git a/models/attribute_float_test.go b/models/attribute_float_test.go new file mode 100644 index 00000000..461efadd --- /dev/null +++ b/models/attribute_float_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeFloatModel(t *testing.T) { + model := AttributeFloat{ Key: "percentageCompleted", Type: "double", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeFloat + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/attribute_integer_test.go b/models/attribute_integer_test.go new file mode 100644 index 00000000..b7e8cc39 --- /dev/null +++ b/models/attribute_integer_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeIntegerModel(t *testing.T) { + model := AttributeInteger{ Key: "count", Type: "integer", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeInteger + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/attribute_ip_test.go b/models/attribute_ip_test.go new file mode 100644 index 00000000..de414b14 --- /dev/null +++ b/models/attribute_ip_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeIpModel(t *testing.T) { + model := AttributeIp{ Key: "ipAddress", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Format: "ip", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeIp + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Format != model.Format { + t.Errorf("Expected Format %v, got %v", model.Format, result.Format) + }} diff --git a/models/attribute_line_test.go b/models/attribute_line_test.go new file mode 100644 index 00000000..99df908a --- /dev/null +++ b/models/attribute_line_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeLineModel(t *testing.T) { + model := AttributeLine{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeLine + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/attribute_list_test.go b/models/attribute_list_test.go new file mode 100644 index 00000000..9d9f1291 --- /dev/null +++ b/models/attribute_list_test.go @@ -0,0 +1,23 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeListModel(t *testing.T) { + model := AttributeList{ Total: 5, Attributes: []map[string]any{}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/attribute_longtext_test.go b/models/attribute_longtext_test.go new file mode 100644 index 00000000..c3bf5f6b --- /dev/null +++ b/models/attribute_longtext_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeLongtextModel(t *testing.T) { + model := AttributeLongtext{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeLongtext + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/attribute_mediumtext_test.go b/models/attribute_mediumtext_test.go new file mode 100644 index 00000000..c1911812 --- /dev/null +++ b/models/attribute_mediumtext_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeMediumtextModel(t *testing.T) { + model := AttributeMediumtext{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeMediumtext + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/attribute_point_test.go b/models/attribute_point_test.go new file mode 100644 index 00000000..a422aaec --- /dev/null +++ b/models/attribute_point_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributePointModel(t *testing.T) { + model := AttributePoint{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributePoint + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/attribute_polygon_test.go b/models/attribute_polygon_test.go new file mode 100644 index 00000000..e5eb862c --- /dev/null +++ b/models/attribute_polygon_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributePolygonModel(t *testing.T) { + model := AttributePolygon{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributePolygon + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/attribute_relationship_test.go b/models/attribute_relationship_test.go new file mode 100644 index 00000000..741d5587 --- /dev/null +++ b/models/attribute_relationship_test.go @@ -0,0 +1,59 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeRelationshipModel(t *testing.T) { + model := AttributeRelationship{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", RelatedCollection: "collection", RelationType: "oneToOne|oneToMany|manyToOne|manyToMany", TwoWay: true, TwoWayKey: "string", OnDelete: "restrict|cascade|setNull", Side: "parent|child", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeRelationship + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.RelatedCollection != model.RelatedCollection { + t.Errorf("Expected RelatedCollection %v, got %v", model.RelatedCollection, result.RelatedCollection) + } + if result.RelationType != model.RelationType { + t.Errorf("Expected RelationType %v, got %v", model.RelationType, result.RelationType) + } + if result.TwoWay != model.TwoWay { + t.Errorf("Expected TwoWay %v, got %v", model.TwoWay, result.TwoWay) + } + if result.TwoWayKey != model.TwoWayKey { + t.Errorf("Expected TwoWayKey %v, got %v", model.TwoWayKey, result.TwoWayKey) + } + if result.OnDelete != model.OnDelete { + t.Errorf("Expected OnDelete %v, got %v", model.OnDelete, result.OnDelete) + } + if result.Side != model.Side { + t.Errorf("Expected Side %v, got %v", model.Side, result.Side) + }} diff --git a/models/attribute_string_test.go b/models/attribute_string_test.go new file mode 100644 index 00000000..59aa30d3 --- /dev/null +++ b/models/attribute_string_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeStringModel(t *testing.T) { + model := AttributeString{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Size: 128, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeString + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Size != model.Size { + t.Errorf("Expected Size %v, got %v", model.Size, result.Size) + }} diff --git a/models/attribute_text_test.go b/models/attribute_text_test.go new file mode 100644 index 00000000..867abc37 --- /dev/null +++ b/models/attribute_text_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeTextModel(t *testing.T) { + model := AttributeText{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeText + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/attribute_url_test.go b/models/attribute_url_test.go new file mode 100644 index 00000000..ac110389 --- /dev/null +++ b/models/attribute_url_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeUrlModel(t *testing.T) { + model := AttributeUrl{ Key: "githubUrl", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Format: "url", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeUrl + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Format != model.Format { + t.Errorf("Expected Format %v, got %v", model.Format, result.Format) + }} diff --git a/models/attribute_varchar_test.go b/models/attribute_varchar_test.go new file mode 100644 index 00000000..bee354aa --- /dev/null +++ b/models/attribute_varchar_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeVarcharModel(t *testing.T) { + model := AttributeVarchar{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Size: 128, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeVarchar + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Size != model.Size { + t.Errorf("Expected Size %v, got %v", model.Size, result.Size) + }} diff --git a/models/backup_archive_list_test.go b/models/backup_archive_list_test.go new file mode 100644 index 00000000..3d4d26dc --- /dev/null +++ b/models/backup_archive_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestBackupArchiveListModel(t *testing.T) { + model := BackupArchiveList{ Total: 5, Archives: []BackupArchive{BackupArchive{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", PolicyId: "did8jx6ws45jana098ab7", Size: 100000, Status: "completed", StartedAt: "2020-10-15T06:38:00.000+00:00", MigrationId: "did8jx6ws45jana098ab7", Services: []string{"test"}, Resources: []string{"test"}, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result BackupArchiveList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/backup_archive_test.go b/models/backup_archive_test.go new file mode 100644 index 00000000..96e8237c --- /dev/null +++ b/models/backup_archive_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestBackupArchiveModel(t *testing.T) { + model := BackupArchive{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", PolicyId: "did8jx6ws45jana098ab7", Size: 100000, Status: "completed", StartedAt: "2020-10-15T06:38:00.000+00:00", MigrationId: "did8jx6ws45jana098ab7", Services: []string{"test"}, Resources: []string{"test"}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result BackupArchive + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.PolicyId != model.PolicyId { + t.Errorf("Expected PolicyId %v, got %v", model.PolicyId, result.PolicyId) + } + if result.Size != model.Size { + t.Errorf("Expected Size %v, got %v", model.Size, result.Size) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.StartedAt != model.StartedAt { + t.Errorf("Expected StartedAt %v, got %v", model.StartedAt, result.StartedAt) + } + if result.MigrationId != model.MigrationId { + t.Errorf("Expected MigrationId %v, got %v", model.MigrationId, result.MigrationId) + }} diff --git a/models/backup_policy_list_test.go b/models/backup_policy_list_test.go new file mode 100644 index 00000000..ed885780 --- /dev/null +++ b/models/backup_policy_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestBackupPolicyListModel(t *testing.T) { + model := BackupPolicyList{ Total: 5, Policies: []BackupPolicy{BackupPolicy{ Id: "5e5ea5c16897e", Name: "Hourly backups", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Services: []string{"test"}, Resources: []string{"test"}, Retention: 7, Schedule: "0 * * * *", Enabled: true, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result BackupPolicyList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/backup_policy_test.go b/models/backup_policy_test.go new file mode 100644 index 00000000..ff82b3cc --- /dev/null +++ b/models/backup_policy_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestBackupPolicyModel(t *testing.T) { + model := BackupPolicy{ Id: "5e5ea5c16897e", Name: "Hourly backups", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Services: []string{"test"}, Resources: []string{"test"}, Retention: 7, Schedule: "0 * * * *", Enabled: true, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result BackupPolicy + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Retention != model.Retention { + t.Errorf("Expected Retention %v, got %v", model.Retention, result.Retention) + } + if result.Schedule != model.Schedule { + t.Errorf("Expected Schedule %v, got %v", model.Schedule, result.Schedule) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + }} diff --git a/models/backup_restoration_list_test.go b/models/backup_restoration_list_test.go new file mode 100644 index 00000000..70290288 --- /dev/null +++ b/models/backup_restoration_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestBackupRestorationListModel(t *testing.T) { + model := BackupRestorationList{ Total: 5, Restorations: []BackupRestoration{BackupRestoration{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", ArchiveId: "did8jx6ws45jana098ab7", PolicyId: "did8jx6ws45jana098ab7", Status: "completed", StartedAt: "2020-10-15T06:38:00.000+00:00", MigrationId: "did8jx6ws45jana098ab7", Services: []string{"test"}, Resources: []string{"test"}, Options: "{databases.database[{oldId, newId, newName}]}", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result BackupRestorationList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/backup_restoration_test.go b/models/backup_restoration_test.go new file mode 100644 index 00000000..ebffb3b1 --- /dev/null +++ b/models/backup_restoration_test.go @@ -0,0 +1,47 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestBackupRestorationModel(t *testing.T) { + model := BackupRestoration{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", ArchiveId: "did8jx6ws45jana098ab7", PolicyId: "did8jx6ws45jana098ab7", Status: "completed", StartedAt: "2020-10-15T06:38:00.000+00:00", MigrationId: "did8jx6ws45jana098ab7", Services: []string{"test"}, Resources: []string{"test"}, Options: "{databases.database[{oldId, newId, newName}]}", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result BackupRestoration + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.ArchiveId != model.ArchiveId { + t.Errorf("Expected ArchiveId %v, got %v", model.ArchiveId, result.ArchiveId) + } + if result.PolicyId != model.PolicyId { + t.Errorf("Expected PolicyId %v, got %v", model.PolicyId, result.PolicyId) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.StartedAt != model.StartedAt { + t.Errorf("Expected StartedAt %v, got %v", model.StartedAt, result.StartedAt) + } + if result.MigrationId != model.MigrationId { + t.Errorf("Expected MigrationId %v, got %v", model.MigrationId, result.MigrationId) + } + if result.Options != model.Options { + t.Errorf("Expected Options %v, got %v", model.Options, result.Options) + }} diff --git a/models/bucket_list_test.go b/models/bucket_list_test.go new file mode 100644 index 00000000..700ee9dd --- /dev/null +++ b/models/bucket_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestBucketListModel(t *testing.T) { + model := BucketList{ Total: 5, Buckets: []Bucket{Bucket{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, FileSecurity: true, Name: "Documents", Enabled: true, MaximumFileSize: 100, AllowedFileExtensions: []string{"test"}, Compression: "gzip", Encryption: true, Antivirus: true, Transformations: true, TotalSize: 128, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result BucketList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/bucket_test.go b/models/bucket_test.go new file mode 100644 index 00000000..c1555b1f --- /dev/null +++ b/models/bucket_test.go @@ -0,0 +1,56 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestBucketModel(t *testing.T) { + model := Bucket{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, FileSecurity: true, Name: "Documents", Enabled: true, MaximumFileSize: 100, AllowedFileExtensions: []string{"test"}, Compression: "gzip", Encryption: true, Antivirus: true, Transformations: true, TotalSize: 128, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Bucket + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.FileSecurity != model.FileSecurity { + t.Errorf("Expected FileSecurity %v, got %v", model.FileSecurity, result.FileSecurity) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.MaximumFileSize != model.MaximumFileSize { + t.Errorf("Expected MaximumFileSize %v, got %v", model.MaximumFileSize, result.MaximumFileSize) + } + if result.Compression != model.Compression { + t.Errorf("Expected Compression %v, got %v", model.Compression, result.Compression) + } + if result.Encryption != model.Encryption { + t.Errorf("Expected Encryption %v, got %v", model.Encryption, result.Encryption) + } + if result.Antivirus != model.Antivirus { + t.Errorf("Expected Antivirus %v, got %v", model.Antivirus, result.Antivirus) + } + if result.Transformations != model.Transformations { + t.Errorf("Expected Transformations %v, got %v", model.Transformations, result.Transformations) + } + if result.TotalSize != model.TotalSize { + t.Errorf("Expected TotalSize %v, got %v", model.TotalSize, result.TotalSize) + }} diff --git a/models/collection_list_test.go b/models/collection_list_test.go new file mode 100644 index 00000000..4479ddce --- /dev/null +++ b/models/collection_list_test.go @@ -0,0 +1,25 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestCollectionListModel(t *testing.T) { + model := CollectionList{ Total: 5, Collections: []Collection{Collection{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, DatabaseId: "5e5ea5c16897e", Name: "My Collection", Enabled: true, DocumentSecurity: true, Attributes: []map[string]any{}, Indexes: []Index{Index{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Attributes: []string{"test"}, Lengths: []int{1}, }, + }, BytesMax: 65535, BytesUsed: 1500, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result CollectionList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/collection_test.go b/models/collection_test.go new file mode 100644 index 00000000..28338c8d --- /dev/null +++ b/models/collection_test.go @@ -0,0 +1,48 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestCollectionModel(t *testing.T) { + model := Collection{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, DatabaseId: "5e5ea5c16897e", Name: "My Collection", Enabled: true, DocumentSecurity: true, Attributes: []map[string]any{}, Indexes: []Index{Index{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Attributes: []string{"test"}, Lengths: []int{1}, }, + }, BytesMax: 65535, BytesUsed: 1500, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Collection + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.DatabaseId != model.DatabaseId { + t.Errorf("Expected DatabaseId %v, got %v", model.DatabaseId, result.DatabaseId) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.DocumentSecurity != model.DocumentSecurity { + t.Errorf("Expected DocumentSecurity %v, got %v", model.DocumentSecurity, result.DocumentSecurity) + } + if result.BytesMax != model.BytesMax { + t.Errorf("Expected BytesMax %v, got %v", model.BytesMax, result.BytesMax) + } + if result.BytesUsed != model.BytesUsed { + t.Errorf("Expected BytesUsed %v, got %v", model.BytesUsed, result.BytesUsed) + }} diff --git a/models/column_boolean_test.go b/models/column_boolean_test.go new file mode 100644 index 00000000..1b755040 --- /dev/null +++ b/models/column_boolean_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnBooleanModel(t *testing.T) { + model := ColumnBoolean{ Key: "isEnabled", Type: "boolean", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnBoolean + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/column_datetime_test.go b/models/column_datetime_test.go new file mode 100644 index 00000000..5dced3b8 --- /dev/null +++ b/models/column_datetime_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnDatetimeModel(t *testing.T) { + model := ColumnDatetime{ Key: "birthDay", Type: "datetime", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Format: "datetime", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnDatetime + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Format != model.Format { + t.Errorf("Expected Format %v, got %v", model.Format, result.Format) + }} diff --git a/models/column_email_test.go b/models/column_email_test.go new file mode 100644 index 00000000..985968b5 --- /dev/null +++ b/models/column_email_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnEmailModel(t *testing.T) { + model := ColumnEmail{ Key: "userEmail", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Format: "email", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnEmail + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Format != model.Format { + t.Errorf("Expected Format %v, got %v", model.Format, result.Format) + }} diff --git a/models/column_enum_test.go b/models/column_enum_test.go new file mode 100644 index 00000000..c1da5a64 --- /dev/null +++ b/models/column_enum_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnEnumModel(t *testing.T) { + model := ColumnEnum{ Key: "status", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Elements: []string{"test"}, Format: "enum", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnEnum + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Format != model.Format { + t.Errorf("Expected Format %v, got %v", model.Format, result.Format) + }} diff --git a/models/column_float_test.go b/models/column_float_test.go new file mode 100644 index 00000000..92435171 --- /dev/null +++ b/models/column_float_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnFloatModel(t *testing.T) { + model := ColumnFloat{ Key: "percentageCompleted", Type: "double", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnFloat + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/column_index_list_test.go b/models/column_index_list_test.go new file mode 100644 index 00000000..4b901dcf --- /dev/null +++ b/models/column_index_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnIndexListModel(t *testing.T) { + model := ColumnIndexList{ Total: 5, Indexes: []ColumnIndex{ColumnIndex{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Columns: []string{"test"}, Lengths: []int{1}, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnIndexList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/column_index_test.go b/models/column_index_test.go new file mode 100644 index 00000000..1e620140 --- /dev/null +++ b/models/column_index_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnIndexModel(t *testing.T) { + model := ColumnIndex{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Columns: []string{"test"}, Lengths: []int{1}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnIndex + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + }} diff --git a/models/column_integer_test.go b/models/column_integer_test.go new file mode 100644 index 00000000..1ef130d7 --- /dev/null +++ b/models/column_integer_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnIntegerModel(t *testing.T) { + model := ColumnInteger{ Key: "count", Type: "integer", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnInteger + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/column_ip_test.go b/models/column_ip_test.go new file mode 100644 index 00000000..8f48cad0 --- /dev/null +++ b/models/column_ip_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnIpModel(t *testing.T) { + model := ColumnIp{ Key: "ipAddress", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Format: "ip", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnIp + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Format != model.Format { + t.Errorf("Expected Format %v, got %v", model.Format, result.Format) + }} diff --git a/models/column_line_test.go b/models/column_line_test.go new file mode 100644 index 00000000..57afa714 --- /dev/null +++ b/models/column_line_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnLineModel(t *testing.T) { + model := ColumnLine{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnLine + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/column_list_test.go b/models/column_list_test.go new file mode 100644 index 00000000..e8711ad4 --- /dev/null +++ b/models/column_list_test.go @@ -0,0 +1,23 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnListModel(t *testing.T) { + model := ColumnList{ Total: 5, Columns: []interface{}{}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/column_longtext_test.go b/models/column_longtext_test.go new file mode 100644 index 00000000..e8ceb65c --- /dev/null +++ b/models/column_longtext_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnLongtextModel(t *testing.T) { + model := ColumnLongtext{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnLongtext + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/column_mediumtext_test.go b/models/column_mediumtext_test.go new file mode 100644 index 00000000..e6185644 --- /dev/null +++ b/models/column_mediumtext_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnMediumtextModel(t *testing.T) { + model := ColumnMediumtext{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnMediumtext + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/column_point_test.go b/models/column_point_test.go new file mode 100644 index 00000000..1f904e58 --- /dev/null +++ b/models/column_point_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnPointModel(t *testing.T) { + model := ColumnPoint{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnPoint + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/column_polygon_test.go b/models/column_polygon_test.go new file mode 100644 index 00000000..272678d9 --- /dev/null +++ b/models/column_polygon_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnPolygonModel(t *testing.T) { + model := ColumnPolygon{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnPolygon + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/column_relationship_test.go b/models/column_relationship_test.go new file mode 100644 index 00000000..59eb2de7 --- /dev/null +++ b/models/column_relationship_test.go @@ -0,0 +1,59 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnRelationshipModel(t *testing.T) { + model := ColumnRelationship{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", RelatedTable: "table", RelationType: "oneToOne|oneToMany|manyToOne|manyToMany", TwoWay: true, TwoWayKey: "string", OnDelete: "restrict|cascade|setNull", Side: "parent|child", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnRelationship + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.RelatedTable != model.RelatedTable { + t.Errorf("Expected RelatedTable %v, got %v", model.RelatedTable, result.RelatedTable) + } + if result.RelationType != model.RelationType { + t.Errorf("Expected RelationType %v, got %v", model.RelationType, result.RelationType) + } + if result.TwoWay != model.TwoWay { + t.Errorf("Expected TwoWay %v, got %v", model.TwoWay, result.TwoWay) + } + if result.TwoWayKey != model.TwoWayKey { + t.Errorf("Expected TwoWayKey %v, got %v", model.TwoWayKey, result.TwoWayKey) + } + if result.OnDelete != model.OnDelete { + t.Errorf("Expected OnDelete %v, got %v", model.OnDelete, result.OnDelete) + } + if result.Side != model.Side { + t.Errorf("Expected Side %v, got %v", model.Side, result.Side) + }} diff --git a/models/column_string_test.go b/models/column_string_test.go new file mode 100644 index 00000000..97f9440e --- /dev/null +++ b/models/column_string_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnStringModel(t *testing.T) { + model := ColumnString{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Size: 128, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnString + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Size != model.Size { + t.Errorf("Expected Size %v, got %v", model.Size, result.Size) + }} diff --git a/models/column_text_test.go b/models/column_text_test.go new file mode 100644 index 00000000..9c0f06fb --- /dev/null +++ b/models/column_text_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnTextModel(t *testing.T) { + model := ColumnText{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnText + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/column_url_test.go b/models/column_url_test.go new file mode 100644 index 00000000..52c9e3b1 --- /dev/null +++ b/models/column_url_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnUrlModel(t *testing.T) { + model := ColumnUrl{ Key: "githubUrl", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Format: "url", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnUrl + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Format != model.Format { + t.Errorf("Expected Format %v, got %v", model.Format, result.Format) + }} diff --git a/models/column_varchar_test.go b/models/column_varchar_test.go new file mode 100644 index 00000000..04747cc8 --- /dev/null +++ b/models/column_varchar_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnVarcharModel(t *testing.T) { + model := ColumnVarchar{ Key: "fullName", Type: "string", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Size: 128, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnVarchar + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Size != model.Size { + t.Errorf("Expected Size %v, got %v", model.Size, result.Size) + }} diff --git a/models/continent_list_test.go b/models/continent_list_test.go new file mode 100644 index 00000000..1655d3bc --- /dev/null +++ b/models/continent_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestContinentListModel(t *testing.T) { + model := ContinentList{ Total: 5, Continents: []Continent{Continent{ Name: "Europe", Code: "EU", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ContinentList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/continent_test.go b/models/continent_test.go new file mode 100644 index 00000000..ca0357be --- /dev/null +++ b/models/continent_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestContinentModel(t *testing.T) { + model := Continent{ Name: "Europe", Code: "EU", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Continent + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Code != model.Code { + t.Errorf("Expected Code %v, got %v", model.Code, result.Code) + }} diff --git a/models/country_list_test.go b/models/country_list_test.go new file mode 100644 index 00000000..494e5df9 --- /dev/null +++ b/models/country_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestCountryListModel(t *testing.T) { + model := CountryList{ Total: 5, Countries: []Country{Country{ Name: "United States", Code: "US", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result CountryList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/country_test.go b/models/country_test.go new file mode 100644 index 00000000..9d9d3ab7 --- /dev/null +++ b/models/country_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestCountryModel(t *testing.T) { + model := Country{ Name: "United States", Code: "US", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Country + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Code != model.Code { + t.Errorf("Expected Code %v, got %v", model.Code, result.Code) + }} diff --git a/models/currency_list_test.go b/models/currency_list_test.go new file mode 100644 index 00000000..80f65b33 --- /dev/null +++ b/models/currency_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestCurrencyListModel(t *testing.T) { + model := CurrencyList{ Total: 5, Currencies: []Currency{Currency{ Symbol: "$", Name: "US dollar", SymbolNative: "$", DecimalDigits: 2, Rounding: 0, Code: "USD", NamePlural: "US dollars", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result CurrencyList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/currency_test.go b/models/currency_test.go new file mode 100644 index 00000000..d06205e1 --- /dev/null +++ b/models/currency_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestCurrencyModel(t *testing.T) { + model := Currency{ Symbol: "$", Name: "US dollar", SymbolNative: "$", DecimalDigits: 2, Rounding: 0, Code: "USD", NamePlural: "US dollars", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Currency + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Symbol != model.Symbol { + t.Errorf("Expected Symbol %v, got %v", model.Symbol, result.Symbol) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.SymbolNative != model.SymbolNative { + t.Errorf("Expected SymbolNative %v, got %v", model.SymbolNative, result.SymbolNative) + } + if result.DecimalDigits != model.DecimalDigits { + t.Errorf("Expected DecimalDigits %v, got %v", model.DecimalDigits, result.DecimalDigits) + } + if result.Rounding != model.Rounding { + t.Errorf("Expected Rounding %v, got %v", model.Rounding, result.Rounding) + } + if result.Code != model.Code { + t.Errorf("Expected Code %v, got %v", model.Code, result.Code) + } + if result.NamePlural != model.NamePlural { + t.Errorf("Expected NamePlural %v, got %v", model.NamePlural, result.NamePlural) + }} diff --git a/models/database_list_test.go b/models/database_list_test.go new file mode 100644 index 00000000..c7c59bbf --- /dev/null +++ b/models/database_list_test.go @@ -0,0 +1,27 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestDatabaseListModel(t *testing.T) { + model := DatabaseList{ Total: 5, Databases: []Database{Database{ Id: "5e5ea5c16897e", Name: "My Database", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Enabled: true, Type: "legacy", Policies: []Index{Index{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Attributes: []string{"test"}, Lengths: []int{1}, }, + }, Archives: []Collection{Collection{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, DatabaseId: "5e5ea5c16897e", Name: "My Collection", Enabled: true, DocumentSecurity: true, Attributes: []map[string]any{}, Indexes: []Index{Index{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Attributes: []string{"test"}, Lengths: []int{1}, }, + }, BytesMax: 65535, BytesUsed: 1500, }, + }, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result DatabaseList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/database_test.go b/models/database_test.go new file mode 100644 index 00000000..5bd00151 --- /dev/null +++ b/models/database_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestDatabaseModel(t *testing.T) { + model := Database{ Id: "5e5ea5c16897e", Name: "My Database", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Enabled: true, Type: "legacy", Policies: []Index{Index{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Attributes: []string{"test"}, Lengths: []int{1}, }, + }, Archives: []Collection{Collection{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, DatabaseId: "5e5ea5c16897e", Name: "My Collection", Enabled: true, DocumentSecurity: true, Attributes: []map[string]any{}, Indexes: []Index{Index{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Attributes: []string{"test"}, Lengths: []int{1}, }, + }, BytesMax: 65535, BytesUsed: 1500, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Database + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + }} diff --git a/models/deployment_list_test.go b/models/deployment_list_test.go new file mode 100644 index 00000000..b98f5b28 --- /dev/null +++ b/models/deployment_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestDeploymentListModel(t *testing.T) { + model := DeploymentList{ Total: 5, Deployments: []Deployment{Deployment{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Type: "vcs", ResourceId: "5e5ea6g16897e", ResourceType: "functions", Entrypoint: "index.js", SourceSize: 128, BuildSize: 128, TotalSize: 128, BuildId: "5e5ea5c16897e", Activate: true, ScreenshotLight: "5e5ea5c16897e", ScreenshotDark: "5e5ea5c16897e", Status: "ready", BuildLogs: "Compiling source files...", BuildDuration: 128, ProviderRepositoryName: "database", ProviderRepositoryOwner: "utopia", ProviderRepositoryUrl: "https://github.com/vermakhushboo/g4-node-function", ProviderCommitHash: "7c3f25d", ProviderCommitAuthorUrl: "https://github.com/vermakhushboo", ProviderCommitAuthor: "Khushboo Verma", ProviderCommitMessage: "Update index.js", ProviderCommitUrl: "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", ProviderBranch: "0.7.x", ProviderBranchUrl: "https://github.com/vermakhushboo/appwrite/tree/0.7.x", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result DeploymentList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/deployment_test.go b/models/deployment_test.go new file mode 100644 index 00000000..1c061fa3 --- /dev/null +++ b/models/deployment_test.go @@ -0,0 +1,101 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestDeploymentModel(t *testing.T) { + model := Deployment{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Type: "vcs", ResourceId: "5e5ea6g16897e", ResourceType: "functions", Entrypoint: "index.js", SourceSize: 128, BuildSize: 128, TotalSize: 128, BuildId: "5e5ea5c16897e", Activate: true, ScreenshotLight: "5e5ea5c16897e", ScreenshotDark: "5e5ea5c16897e", Status: "ready", BuildLogs: "Compiling source files...", BuildDuration: 128, ProviderRepositoryName: "database", ProviderRepositoryOwner: "utopia", ProviderRepositoryUrl: "https://github.com/vermakhushboo/g4-node-function", ProviderCommitHash: "7c3f25d", ProviderCommitAuthorUrl: "https://github.com/vermakhushboo", ProviderCommitAuthor: "Khushboo Verma", ProviderCommitMessage: "Update index.js", ProviderCommitUrl: "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", ProviderBranch: "0.7.x", ProviderBranchUrl: "https://github.com/vermakhushboo/appwrite/tree/0.7.x", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Deployment + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.ResourceId != model.ResourceId { + t.Errorf("Expected ResourceId %v, got %v", model.ResourceId, result.ResourceId) + } + if result.ResourceType != model.ResourceType { + t.Errorf("Expected ResourceType %v, got %v", model.ResourceType, result.ResourceType) + } + if result.Entrypoint != model.Entrypoint { + t.Errorf("Expected Entrypoint %v, got %v", model.Entrypoint, result.Entrypoint) + } + if result.SourceSize != model.SourceSize { + t.Errorf("Expected SourceSize %v, got %v", model.SourceSize, result.SourceSize) + } + if result.BuildSize != model.BuildSize { + t.Errorf("Expected BuildSize %v, got %v", model.BuildSize, result.BuildSize) + } + if result.TotalSize != model.TotalSize { + t.Errorf("Expected TotalSize %v, got %v", model.TotalSize, result.TotalSize) + } + if result.BuildId != model.BuildId { + t.Errorf("Expected BuildId %v, got %v", model.BuildId, result.BuildId) + } + if result.Activate != model.Activate { + t.Errorf("Expected Activate %v, got %v", model.Activate, result.Activate) + } + if result.ScreenshotLight != model.ScreenshotLight { + t.Errorf("Expected ScreenshotLight %v, got %v", model.ScreenshotLight, result.ScreenshotLight) + } + if result.ScreenshotDark != model.ScreenshotDark { + t.Errorf("Expected ScreenshotDark %v, got %v", model.ScreenshotDark, result.ScreenshotDark) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.BuildLogs != model.BuildLogs { + t.Errorf("Expected BuildLogs %v, got %v", model.BuildLogs, result.BuildLogs) + } + if result.BuildDuration != model.BuildDuration { + t.Errorf("Expected BuildDuration %v, got %v", model.BuildDuration, result.BuildDuration) + } + if result.ProviderRepositoryName != model.ProviderRepositoryName { + t.Errorf("Expected ProviderRepositoryName %v, got %v", model.ProviderRepositoryName, result.ProviderRepositoryName) + } + if result.ProviderRepositoryOwner != model.ProviderRepositoryOwner { + t.Errorf("Expected ProviderRepositoryOwner %v, got %v", model.ProviderRepositoryOwner, result.ProviderRepositoryOwner) + } + if result.ProviderRepositoryUrl != model.ProviderRepositoryUrl { + t.Errorf("Expected ProviderRepositoryUrl %v, got %v", model.ProviderRepositoryUrl, result.ProviderRepositoryUrl) + } + if result.ProviderCommitHash != model.ProviderCommitHash { + t.Errorf("Expected ProviderCommitHash %v, got %v", model.ProviderCommitHash, result.ProviderCommitHash) + } + if result.ProviderCommitAuthorUrl != model.ProviderCommitAuthorUrl { + t.Errorf("Expected ProviderCommitAuthorUrl %v, got %v", model.ProviderCommitAuthorUrl, result.ProviderCommitAuthorUrl) + } + if result.ProviderCommitAuthor != model.ProviderCommitAuthor { + t.Errorf("Expected ProviderCommitAuthor %v, got %v", model.ProviderCommitAuthor, result.ProviderCommitAuthor) + } + if result.ProviderCommitMessage != model.ProviderCommitMessage { + t.Errorf("Expected ProviderCommitMessage %v, got %v", model.ProviderCommitMessage, result.ProviderCommitMessage) + } + if result.ProviderCommitUrl != model.ProviderCommitUrl { + t.Errorf("Expected ProviderCommitUrl %v, got %v", model.ProviderCommitUrl, result.ProviderCommitUrl) + } + if result.ProviderBranch != model.ProviderBranch { + t.Errorf("Expected ProviderBranch %v, got %v", model.ProviderBranch, result.ProviderBranch) + } + if result.ProviderBranchUrl != model.ProviderBranchUrl { + t.Errorf("Expected ProviderBranchUrl %v, got %v", model.ProviderBranchUrl, result.ProviderBranchUrl) + }} diff --git a/models/document_list_test.go b/models/document_list_test.go new file mode 100644 index 00000000..6a4935ee --- /dev/null +++ b/models/document_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestDocumentListModel(t *testing.T) { + model := DocumentList{ Total: 5, Documents: []Document{Document{ Id: "5e5ea5c16897e", Sequence: "1", CollectionId: "5e5ea5c15117e", DatabaseId: "5e5ea5c15117e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result DocumentList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/document_test.go b/models/document_test.go new file mode 100644 index 00000000..8394d778 --- /dev/null +++ b/models/document_test.go @@ -0,0 +1,38 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestDocumentModel(t *testing.T) { + model := Document{ Id: "5e5ea5c16897e", Sequence: "1", CollectionId: "5e5ea5c15117e", DatabaseId: "5e5ea5c15117e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Document + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Sequence != model.Sequence { + t.Errorf("Expected Sequence %v, got %v", model.Sequence, result.Sequence) + } + if result.CollectionId != model.CollectionId { + t.Errorf("Expected CollectionId %v, got %v", model.CollectionId, result.CollectionId) + } + if result.DatabaseId != model.DatabaseId { + t.Errorf("Expected DatabaseId %v, got %v", model.DatabaseId, result.DatabaseId) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/execution_list_test.go b/models/execution_list_test.go new file mode 100644 index 00000000..94fc7418 --- /dev/null +++ b/models/execution_list_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestExecutionListModel(t *testing.T) { + model := ExecutionList{ Total: 5, Executions: []Execution{Execution{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, FunctionId: "5e5ea6g16897e", DeploymentId: "5e5ea5c16897e", Trigger: "http", Status: "processing", RequestMethod: "GET", RequestPath: "/articles?id=5", RequestHeaders: []Headers{Headers{ Name: "Content-Type", Value: "application/json", }, + }, ResponseStatusCode: 200, ResponseBody: "string", ResponseHeaders: []Headers{Headers{ Name: "Content-Type", Value: "application/json", }, + }, Logs: "string", Errors: "string", Duration: 0.4, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ExecutionList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/execution_test.go b/models/execution_test.go new file mode 100644 index 00000000..7b3b7102 --- /dev/null +++ b/models/execution_test.go @@ -0,0 +1,64 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestExecutionModel(t *testing.T) { + model := Execution{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, FunctionId: "5e5ea6g16897e", DeploymentId: "5e5ea5c16897e", Trigger: "http", Status: "processing", RequestMethod: "GET", RequestPath: "/articles?id=5", RequestHeaders: []Headers{Headers{ Name: "Content-Type", Value: "application/json", }, + }, ResponseStatusCode: 200, ResponseBody: "string", ResponseHeaders: []Headers{Headers{ Name: "Content-Type", Value: "application/json", }, + }, Logs: "string", Errors: "string", Duration: 0.4, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Execution + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.FunctionId != model.FunctionId { + t.Errorf("Expected FunctionId %v, got %v", model.FunctionId, result.FunctionId) + } + if result.DeploymentId != model.DeploymentId { + t.Errorf("Expected DeploymentId %v, got %v", model.DeploymentId, result.DeploymentId) + } + if result.Trigger != model.Trigger { + t.Errorf("Expected Trigger %v, got %v", model.Trigger, result.Trigger) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.RequestMethod != model.RequestMethod { + t.Errorf("Expected RequestMethod %v, got %v", model.RequestMethod, result.RequestMethod) + } + if result.RequestPath != model.RequestPath { + t.Errorf("Expected RequestPath %v, got %v", model.RequestPath, result.RequestPath) + } + if result.ResponseStatusCode != model.ResponseStatusCode { + t.Errorf("Expected ResponseStatusCode %v, got %v", model.ResponseStatusCode, result.ResponseStatusCode) + } + if result.ResponseBody != model.ResponseBody { + t.Errorf("Expected ResponseBody %v, got %v", model.ResponseBody, result.ResponseBody) + } + if result.Logs != model.Logs { + t.Errorf("Expected Logs %v, got %v", model.Logs, result.Logs) + } + if result.Errors != model.Errors { + t.Errorf("Expected Errors %v, got %v", model.Errors, result.Errors) + } + if result.Duration != model.Duration { + t.Errorf("Expected Duration %v, got %v", model.Duration, result.Duration) + }} diff --git a/models/file_list_test.go b/models/file_list_test.go new file mode 100644 index 00000000..7e77e9d2 --- /dev/null +++ b/models/file_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestFileListModel(t *testing.T) { + model := FileList{ Total: 5, Files: []File{File{ Id: "5e5ea5c16897e", BucketId: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, Name: "Pink.png", Signature: "5d529fd02b544198ae075bd57c1762bb", MimeType: "image/png", SizeOriginal: 17890, ChunksTotal: 17890, ChunksUploaded: 17890, Encryption: true, Compression: "gzip", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result FileList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/file_test.go b/models/file_test.go new file mode 100644 index 00000000..bb9997fe --- /dev/null +++ b/models/file_test.go @@ -0,0 +1,56 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestFileModel(t *testing.T) { + model := File{ Id: "5e5ea5c16897e", BucketId: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, Name: "Pink.png", Signature: "5d529fd02b544198ae075bd57c1762bb", MimeType: "image/png", SizeOriginal: 17890, ChunksTotal: 17890, ChunksUploaded: 17890, Encryption: true, Compression: "gzip", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result File + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.BucketId != model.BucketId { + t.Errorf("Expected BucketId %v, got %v", model.BucketId, result.BucketId) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Signature != model.Signature { + t.Errorf("Expected Signature %v, got %v", model.Signature, result.Signature) + } + if result.MimeType != model.MimeType { + t.Errorf("Expected MimeType %v, got %v", model.MimeType, result.MimeType) + } + if result.SizeOriginal != model.SizeOriginal { + t.Errorf("Expected SizeOriginal %v, got %v", model.SizeOriginal, result.SizeOriginal) + } + if result.ChunksTotal != model.ChunksTotal { + t.Errorf("Expected ChunksTotal %v, got %v", model.ChunksTotal, result.ChunksTotal) + } + if result.ChunksUploaded != model.ChunksUploaded { + t.Errorf("Expected ChunksUploaded %v, got %v", model.ChunksUploaded, result.ChunksUploaded) + } + if result.Encryption != model.Encryption { + t.Errorf("Expected Encryption %v, got %v", model.Encryption, result.Encryption) + } + if result.Compression != model.Compression { + t.Errorf("Expected Compression %v, got %v", model.Compression, result.Compression) + }} diff --git a/models/framework_adapter_test.go b/models/framework_adapter_test.go new file mode 100644 index 00000000..740687eb --- /dev/null +++ b/models/framework_adapter_test.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestFrameworkAdapterModel(t *testing.T) { + model := FrameworkAdapter{ Key: "static", InstallCommand: "npm install", BuildCommand: "npm run build", OutputDirectory: "./dist", FallbackFile: "index.html", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result FrameworkAdapter + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.InstallCommand != model.InstallCommand { + t.Errorf("Expected InstallCommand %v, got %v", model.InstallCommand, result.InstallCommand) + } + if result.BuildCommand != model.BuildCommand { + t.Errorf("Expected BuildCommand %v, got %v", model.BuildCommand, result.BuildCommand) + } + if result.OutputDirectory != model.OutputDirectory { + t.Errorf("Expected OutputDirectory %v, got %v", model.OutputDirectory, result.OutputDirectory) + } + if result.FallbackFile != model.FallbackFile { + t.Errorf("Expected FallbackFile %v, got %v", model.FallbackFile, result.FallbackFile) + }} diff --git a/models/framework_list_test.go b/models/framework_list_test.go new file mode 100644 index 00000000..96bddda3 --- /dev/null +++ b/models/framework_list_test.go @@ -0,0 +1,25 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestFrameworkListModel(t *testing.T) { + model := FrameworkList{ Total: 5, Frameworks: []Framework{Framework{ Key: "sveltekit", Name: "SvelteKit", BuildRuntime: "node-22", Runtimes: []string{"test"}, Adapters: []FrameworkAdapter{FrameworkAdapter{ Key: "static", InstallCommand: "npm install", BuildCommand: "npm run build", OutputDirectory: "./dist", FallbackFile: "index.html", }, + }, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result FrameworkList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/framework_test.go b/models/framework_test.go new file mode 100644 index 00000000..671191d1 --- /dev/null +++ b/models/framework_test.go @@ -0,0 +1,30 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestFrameworkModel(t *testing.T) { + model := Framework{ Key: "sveltekit", Name: "SvelteKit", BuildRuntime: "node-22", Runtimes: []string{"test"}, Adapters: []FrameworkAdapter{FrameworkAdapter{ Key: "static", InstallCommand: "npm install", BuildCommand: "npm run build", OutputDirectory: "./dist", FallbackFile: "index.html", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Framework + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.BuildRuntime != model.BuildRuntime { + t.Errorf("Expected BuildRuntime %v, got %v", model.BuildRuntime, result.BuildRuntime) + }} diff --git a/models/function_list_test.go b/models/function_list_test.go new file mode 100644 index 00000000..118d8f76 --- /dev/null +++ b/models/function_list_test.go @@ -0,0 +1,25 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestFunctionListModel(t *testing.T) { + model := FunctionList{ Total: 5, Functions: []Function{Function{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Execute: []string{"test"}, Name: "My Function", Enabled: true, Live: true, Logging: true, Runtime: "python-3.8", DeploymentRetention: 7, DeploymentId: "5e5ea5c16897e", DeploymentCreatedAt: "2020-10-15T06:38:00.000+00:00", LatestDeploymentId: "5e5ea5c16897e", LatestDeploymentCreatedAt: "2020-10-15T06:38:00.000+00:00", LatestDeploymentStatus: "ready", Scopes: []string{"test"}, Vars: []Variable{Variable{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "API_KEY", Value: "myPa$$word1", Secret: true, ResourceType: "function", ResourceId: "myAwesomeFunction", }, + }, Events: []string{"test"}, Schedule: "5 4 * * *", Timeout: 300, Entrypoint: "index.js", Commands: "npm install", Version: "v2", InstallationId: "6m40at4ejk5h2u9s1hboo", ProviderRepositoryId: "appwrite", ProviderBranch: "main", ProviderRootDirectory: "functions/helloWorld", ProviderSilentMode: true, BuildSpecification: "s-1vcpu-512mb", RuntimeSpecification: "s-1vcpu-512mb", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result FunctionList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/function_test.go b/models/function_test.go new file mode 100644 index 00000000..d4674274 --- /dev/null +++ b/models/function_test.go @@ -0,0 +1,99 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestFunctionModel(t *testing.T) { + model := Function{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Execute: []string{"test"}, Name: "My Function", Enabled: true, Live: true, Logging: true, Runtime: "python-3.8", DeploymentRetention: 7, DeploymentId: "5e5ea5c16897e", DeploymentCreatedAt: "2020-10-15T06:38:00.000+00:00", LatestDeploymentId: "5e5ea5c16897e", LatestDeploymentCreatedAt: "2020-10-15T06:38:00.000+00:00", LatestDeploymentStatus: "ready", Scopes: []string{"test"}, Vars: []Variable{Variable{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "API_KEY", Value: "myPa$$word1", Secret: true, ResourceType: "function", ResourceId: "myAwesomeFunction", }, + }, Events: []string{"test"}, Schedule: "5 4 * * *", Timeout: 300, Entrypoint: "index.js", Commands: "npm install", Version: "v2", InstallationId: "6m40at4ejk5h2u9s1hboo", ProviderRepositoryId: "appwrite", ProviderBranch: "main", ProviderRootDirectory: "functions/helloWorld", ProviderSilentMode: true, BuildSpecification: "s-1vcpu-512mb", RuntimeSpecification: "s-1vcpu-512mb", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Function + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.Live != model.Live { + t.Errorf("Expected Live %v, got %v", model.Live, result.Live) + } + if result.Logging != model.Logging { + t.Errorf("Expected Logging %v, got %v", model.Logging, result.Logging) + } + if result.Runtime != model.Runtime { + t.Errorf("Expected Runtime %v, got %v", model.Runtime, result.Runtime) + } + if result.DeploymentRetention != model.DeploymentRetention { + t.Errorf("Expected DeploymentRetention %v, got %v", model.DeploymentRetention, result.DeploymentRetention) + } + if result.DeploymentId != model.DeploymentId { + t.Errorf("Expected DeploymentId %v, got %v", model.DeploymentId, result.DeploymentId) + } + if result.DeploymentCreatedAt != model.DeploymentCreatedAt { + t.Errorf("Expected DeploymentCreatedAt %v, got %v", model.DeploymentCreatedAt, result.DeploymentCreatedAt) + } + if result.LatestDeploymentId != model.LatestDeploymentId { + t.Errorf("Expected LatestDeploymentId %v, got %v", model.LatestDeploymentId, result.LatestDeploymentId) + } + if result.LatestDeploymentCreatedAt != model.LatestDeploymentCreatedAt { + t.Errorf("Expected LatestDeploymentCreatedAt %v, got %v", model.LatestDeploymentCreatedAt, result.LatestDeploymentCreatedAt) + } + if result.LatestDeploymentStatus != model.LatestDeploymentStatus { + t.Errorf("Expected LatestDeploymentStatus %v, got %v", model.LatestDeploymentStatus, result.LatestDeploymentStatus) + } + if result.Schedule != model.Schedule { + t.Errorf("Expected Schedule %v, got %v", model.Schedule, result.Schedule) + } + if result.Timeout != model.Timeout { + t.Errorf("Expected Timeout %v, got %v", model.Timeout, result.Timeout) + } + if result.Entrypoint != model.Entrypoint { + t.Errorf("Expected Entrypoint %v, got %v", model.Entrypoint, result.Entrypoint) + } + if result.Commands != model.Commands { + t.Errorf("Expected Commands %v, got %v", model.Commands, result.Commands) + } + if result.Version != model.Version { + t.Errorf("Expected Version %v, got %v", model.Version, result.Version) + } + if result.InstallationId != model.InstallationId { + t.Errorf("Expected InstallationId %v, got %v", model.InstallationId, result.InstallationId) + } + if result.ProviderRepositoryId != model.ProviderRepositoryId { + t.Errorf("Expected ProviderRepositoryId %v, got %v", model.ProviderRepositoryId, result.ProviderRepositoryId) + } + if result.ProviderBranch != model.ProviderBranch { + t.Errorf("Expected ProviderBranch %v, got %v", model.ProviderBranch, result.ProviderBranch) + } + if result.ProviderRootDirectory != model.ProviderRootDirectory { + t.Errorf("Expected ProviderRootDirectory %v, got %v", model.ProviderRootDirectory, result.ProviderRootDirectory) + } + if result.ProviderSilentMode != model.ProviderSilentMode { + t.Errorf("Expected ProviderSilentMode %v, got %v", model.ProviderSilentMode, result.ProviderSilentMode) + } + if result.BuildSpecification != model.BuildSpecification { + t.Errorf("Expected BuildSpecification %v, got %v", model.BuildSpecification, result.BuildSpecification) + } + if result.RuntimeSpecification != model.RuntimeSpecification { + t.Errorf("Expected RuntimeSpecification %v, got %v", model.RuntimeSpecification, result.RuntimeSpecification) + }} diff --git a/models/headers_test.go b/models/headers_test.go new file mode 100644 index 00000000..4ac3ea36 --- /dev/null +++ b/models/headers_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestHeadersModel(t *testing.T) { + model := Headers{ Name: "Content-Type", Value: "application/json", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Headers + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Value != model.Value { + t.Errorf("Expected Value %v, got %v", model.Value, result.Value) + }} diff --git a/models/health_antivirus_test.go b/models/health_antivirus_test.go new file mode 100644 index 00000000..894ba511 --- /dev/null +++ b/models/health_antivirus_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestHealthAntivirusModel(t *testing.T) { + model := HealthAntivirus{ Version: "1.0.0", Status: "online", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result HealthAntivirus + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Version != model.Version { + t.Errorf("Expected Version %v, got %v", model.Version, result.Version) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + }} diff --git a/models/health_certificate_test.go b/models/health_certificate_test.go new file mode 100644 index 00000000..dc97ae30 --- /dev/null +++ b/models/health_certificate_test.go @@ -0,0 +1,38 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestHealthCertificateModel(t *testing.T) { + model := HealthCertificate{ Name: "/CN=www.google.com", SubjectSN: "string", IssuerOrganisation: "string", ValidFrom: "1704200998", ValidTo: "1711458597", SignatureTypeSN: "RSA-SHA256", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result HealthCertificate + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.SubjectSN != model.SubjectSN { + t.Errorf("Expected SubjectSN %v, got %v", model.SubjectSN, result.SubjectSN) + } + if result.IssuerOrganisation != model.IssuerOrganisation { + t.Errorf("Expected IssuerOrganisation %v, got %v", model.IssuerOrganisation, result.IssuerOrganisation) + } + if result.ValidFrom != model.ValidFrom { + t.Errorf("Expected ValidFrom %v, got %v", model.ValidFrom, result.ValidFrom) + } + if result.ValidTo != model.ValidTo { + t.Errorf("Expected ValidTo %v, got %v", model.ValidTo, result.ValidTo) + } + if result.SignatureTypeSN != model.SignatureTypeSN { + t.Errorf("Expected SignatureTypeSN %v, got %v", model.SignatureTypeSN, result.SignatureTypeSN) + }} diff --git a/models/health_queue_test.go b/models/health_queue_test.go new file mode 100644 index 00000000..0809dc4d --- /dev/null +++ b/models/health_queue_test.go @@ -0,0 +1,23 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestHealthQueueModel(t *testing.T) { + model := HealthQueue{ Size: 8, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result HealthQueue + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Size != model.Size { + t.Errorf("Expected Size %v, got %v", model.Size, result.Size) + }} diff --git a/models/health_status_list_test.go b/models/health_status_list_test.go new file mode 100644 index 00000000..be7e9b9e --- /dev/null +++ b/models/health_status_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestHealthStatusListModel(t *testing.T) { + model := HealthStatusList{ Total: 5, Statuses: []HealthStatus{HealthStatus{ Name: "database", Ping: 128, Status: "pass", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result HealthStatusList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/health_status_test.go b/models/health_status_test.go new file mode 100644 index 00000000..339c4eff --- /dev/null +++ b/models/health_status_test.go @@ -0,0 +1,29 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestHealthStatusModel(t *testing.T) { + model := HealthStatus{ Name: "database", Ping: 128, Status: "pass", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result HealthStatus + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Ping != model.Ping { + t.Errorf("Expected Ping %v, got %v", model.Ping, result.Ping) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + }} diff --git a/models/health_time_test.go b/models/health_time_test.go new file mode 100644 index 00000000..7a3feac2 --- /dev/null +++ b/models/health_time_test.go @@ -0,0 +1,29 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestHealthTimeModel(t *testing.T) { + model := HealthTime{ RemoteTime: 1639490751, LocalTime: 1639490844, Diff: 93, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result HealthTime + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.RemoteTime != model.RemoteTime { + t.Errorf("Expected RemoteTime %v, got %v", model.RemoteTime, result.RemoteTime) + } + if result.LocalTime != model.LocalTime { + t.Errorf("Expected LocalTime %v, got %v", model.LocalTime, result.LocalTime) + } + if result.Diff != model.Diff { + t.Errorf("Expected Diff %v, got %v", model.Diff, result.Diff) + }} diff --git a/models/identity_list_test.go b/models/identity_list_test.go new file mode 100644 index 00000000..aa8fa9a1 --- /dev/null +++ b/models/identity_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestIdentityListModel(t *testing.T) { + model := IdentityList{ Total: 5, Identities: []Identity{Identity{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5bb8c16897e", Provider: "email", ProviderUid: "5e5bb8c16897e", ProviderEmail: "user@example.com", ProviderAccessToken: "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", ProviderAccessTokenExpiry: "2020-10-15T06:38:00.000+00:00", ProviderRefreshToken: "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result IdentityList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/identity_test.go b/models/identity_test.go new file mode 100644 index 00000000..fb57ff73 --- /dev/null +++ b/models/identity_test.go @@ -0,0 +1,50 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestIdentityModel(t *testing.T) { + model := Identity{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5bb8c16897e", Provider: "email", ProviderUid: "5e5bb8c16897e", ProviderEmail: "user@example.com", ProviderAccessToken: "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", ProviderAccessTokenExpiry: "2020-10-15T06:38:00.000+00:00", ProviderRefreshToken: "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Identity + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.UserId != model.UserId { + t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) + } + if result.Provider != model.Provider { + t.Errorf("Expected Provider %v, got %v", model.Provider, result.Provider) + } + if result.ProviderUid != model.ProviderUid { + t.Errorf("Expected ProviderUid %v, got %v", model.ProviderUid, result.ProviderUid) + } + if result.ProviderEmail != model.ProviderEmail { + t.Errorf("Expected ProviderEmail %v, got %v", model.ProviderEmail, result.ProviderEmail) + } + if result.ProviderAccessToken != model.ProviderAccessToken { + t.Errorf("Expected ProviderAccessToken %v, got %v", model.ProviderAccessToken, result.ProviderAccessToken) + } + if result.ProviderAccessTokenExpiry != model.ProviderAccessTokenExpiry { + t.Errorf("Expected ProviderAccessTokenExpiry %v, got %v", model.ProviderAccessTokenExpiry, result.ProviderAccessTokenExpiry) + } + if result.ProviderRefreshToken != model.ProviderRefreshToken { + t.Errorf("Expected ProviderRefreshToken %v, got %v", model.ProviderRefreshToken, result.ProviderRefreshToken) + }} diff --git a/models/index_list_test.go b/models/index_list_test.go new file mode 100644 index 00000000..d362c193 --- /dev/null +++ b/models/index_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestIndexListModel(t *testing.T) { + model := IndexList{ Total: 5, Indexes: []Index{Index{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Attributes: []string{"test"}, Lengths: []int{1}, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result IndexList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/index_test.go b/models/index_test.go new file mode 100644 index 00000000..5baf84ef --- /dev/null +++ b/models/index_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestIndexModel(t *testing.T) { + model := Index{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Attributes: []string{"test"}, Lengths: []int{1}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Index + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + }} diff --git a/models/jwt_test.go b/models/jwt_test.go new file mode 100644 index 00000000..869f3e39 --- /dev/null +++ b/models/jwt_test.go @@ -0,0 +1,23 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestJwtModel(t *testing.T) { + model := Jwt{ Jwt: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Jwt + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Jwt != model.Jwt { + t.Errorf("Expected Jwt %v, got %v", model.Jwt, result.Jwt) + }} diff --git a/models/language_list_test.go b/models/language_list_test.go new file mode 100644 index 00000000..2c959212 --- /dev/null +++ b/models/language_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestLanguageListModel(t *testing.T) { + model := LanguageList{ Total: 5, Languages: []Language{Language{ Name: "Italian", Code: "it", NativeName: "Italiano", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result LanguageList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/language_test.go b/models/language_test.go new file mode 100644 index 00000000..cfc3246f --- /dev/null +++ b/models/language_test.go @@ -0,0 +1,29 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestLanguageModel(t *testing.T) { + model := Language{ Name: "Italian", Code: "it", NativeName: "Italiano", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Language + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Code != model.Code { + t.Errorf("Expected Code %v, got %v", model.Code, result.Code) + } + if result.NativeName != model.NativeName { + t.Errorf("Expected NativeName %v, got %v", model.NativeName, result.NativeName) + }} diff --git a/models/locale_code_list_test.go b/models/locale_code_list_test.go new file mode 100644 index 00000000..89e3f1e8 --- /dev/null +++ b/models/locale_code_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestLocaleCodeListModel(t *testing.T) { + model := LocaleCodeList{ Total: 5, LocaleCodes: []LocaleCode{LocaleCode{ Code: "en-us", Name: "US", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result LocaleCodeList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/locale_code_test.go b/models/locale_code_test.go new file mode 100644 index 00000000..9475e243 --- /dev/null +++ b/models/locale_code_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestLocaleCodeModel(t *testing.T) { + model := LocaleCode{ Code: "en-us", Name: "US", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result LocaleCode + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Code != model.Code { + t.Errorf("Expected Code %v, got %v", model.Code, result.Code) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + }} diff --git a/models/locale_test.go b/models/locale_test.go new file mode 100644 index 00000000..b37ee423 --- /dev/null +++ b/models/locale_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestLocaleModel(t *testing.T) { + model := Locale{ Ip: "127.0.0.1", CountryCode: "US", Country: "United States", ContinentCode: "NA", Continent: "North America", Eu: true, Currency: "USD", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Locale + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Ip != model.Ip { + t.Errorf("Expected Ip %v, got %v", model.Ip, result.Ip) + } + if result.CountryCode != model.CountryCode { + t.Errorf("Expected CountryCode %v, got %v", model.CountryCode, result.CountryCode) + } + if result.Country != model.Country { + t.Errorf("Expected Country %v, got %v", model.Country, result.Country) + } + if result.ContinentCode != model.ContinentCode { + t.Errorf("Expected ContinentCode %v, got %v", model.ContinentCode, result.ContinentCode) + } + if result.Continent != model.Continent { + t.Errorf("Expected Continent %v, got %v", model.Continent, result.Continent) + } + if result.Eu != model.Eu { + t.Errorf("Expected Eu %v, got %v", model.Eu, result.Eu) + } + if result.Currency != model.Currency { + t.Errorf("Expected Currency %v, got %v", model.Currency, result.Currency) + }} diff --git a/models/log_list_test.go b/models/log_list_test.go new file mode 100644 index 00000000..f5878dfd --- /dev/null +++ b/models/log_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestLogListModel(t *testing.T) { + model := LogList{ Total: 5, Logs: []Log{Log{ Event: "account.sessions.create", UserId: "610fc2f985ee0", UserEmail: "john@appwrite.io", UserName: "John Doe", Mode: "admin", Ip: "127.0.0.1", Time: "2020-10-15T06:38:00.000+00:00", OsCode: "Mac", OsName: "Mac", OsVersion: "Mac", ClientType: "browser", ClientCode: "CM", ClientName: "Chrome Mobile iOS", ClientVersion: "84.0", ClientEngine: "WebKit", ClientEngineVersion: "605.1.15", DeviceName: "smartphone", DeviceBrand: "Google", DeviceModel: "Nexus 5", CountryCode: "US", CountryName: "United States", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result LogList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/log_test.go b/models/log_test.go new file mode 100644 index 00000000..e8d07527 --- /dev/null +++ b/models/log_test.go @@ -0,0 +1,83 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestLogModel(t *testing.T) { + model := Log{ Event: "account.sessions.create", UserId: "610fc2f985ee0", UserEmail: "john@appwrite.io", UserName: "John Doe", Mode: "admin", Ip: "127.0.0.1", Time: "2020-10-15T06:38:00.000+00:00", OsCode: "Mac", OsName: "Mac", OsVersion: "Mac", ClientType: "browser", ClientCode: "CM", ClientName: "Chrome Mobile iOS", ClientVersion: "84.0", ClientEngine: "WebKit", ClientEngineVersion: "605.1.15", DeviceName: "smartphone", DeviceBrand: "Google", DeviceModel: "Nexus 5", CountryCode: "US", CountryName: "United States", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Log + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Event != model.Event { + t.Errorf("Expected Event %v, got %v", model.Event, result.Event) + } + if result.UserId != model.UserId { + t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) + } + if result.UserEmail != model.UserEmail { + t.Errorf("Expected UserEmail %v, got %v", model.UserEmail, result.UserEmail) + } + if result.UserName != model.UserName { + t.Errorf("Expected UserName %v, got %v", model.UserName, result.UserName) + } + if result.Mode != model.Mode { + t.Errorf("Expected Mode %v, got %v", model.Mode, result.Mode) + } + if result.Ip != model.Ip { + t.Errorf("Expected Ip %v, got %v", model.Ip, result.Ip) + } + if result.Time != model.Time { + t.Errorf("Expected Time %v, got %v", model.Time, result.Time) + } + if result.OsCode != model.OsCode { + t.Errorf("Expected OsCode %v, got %v", model.OsCode, result.OsCode) + } + if result.OsName != model.OsName { + t.Errorf("Expected OsName %v, got %v", model.OsName, result.OsName) + } + if result.OsVersion != model.OsVersion { + t.Errorf("Expected OsVersion %v, got %v", model.OsVersion, result.OsVersion) + } + if result.ClientType != model.ClientType { + t.Errorf("Expected ClientType %v, got %v", model.ClientType, result.ClientType) + } + if result.ClientCode != model.ClientCode { + t.Errorf("Expected ClientCode %v, got %v", model.ClientCode, result.ClientCode) + } + if result.ClientName != model.ClientName { + t.Errorf("Expected ClientName %v, got %v", model.ClientName, result.ClientName) + } + if result.ClientVersion != model.ClientVersion { + t.Errorf("Expected ClientVersion %v, got %v", model.ClientVersion, result.ClientVersion) + } + if result.ClientEngine != model.ClientEngine { + t.Errorf("Expected ClientEngine %v, got %v", model.ClientEngine, result.ClientEngine) + } + if result.ClientEngineVersion != model.ClientEngineVersion { + t.Errorf("Expected ClientEngineVersion %v, got %v", model.ClientEngineVersion, result.ClientEngineVersion) + } + if result.DeviceName != model.DeviceName { + t.Errorf("Expected DeviceName %v, got %v", model.DeviceName, result.DeviceName) + } + if result.DeviceBrand != model.DeviceBrand { + t.Errorf("Expected DeviceBrand %v, got %v", model.DeviceBrand, result.DeviceBrand) + } + if result.DeviceModel != model.DeviceModel { + t.Errorf("Expected DeviceModel %v, got %v", model.DeviceModel, result.DeviceModel) + } + if result.CountryCode != model.CountryCode { + t.Errorf("Expected CountryCode %v, got %v", model.CountryCode, result.CountryCode) + } + if result.CountryName != model.CountryName { + t.Errorf("Expected CountryName %v, got %v", model.CountryName, result.CountryName) + }} diff --git a/models/membership_list_test.go b/models/membership_list_test.go new file mode 100644 index 00000000..2973da02 --- /dev/null +++ b/models/membership_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestMembershipListModel(t *testing.T) { + model := MembershipList{ Total: 5, Memberships: []Membership{Membership{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5ea5c16897e", UserName: "John Doe", UserEmail: "john@appwrite.io", TeamId: "5e5ea5c16897e", TeamName: "VIP", Invited: "2020-10-15T06:38:00.000+00:00", Joined: "2020-10-15T06:38:00.000+00:00", Confirm: true, Mfa: true, Roles: []string{"test"}, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result MembershipList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/membership_test.go b/models/membership_test.go new file mode 100644 index 00000000..3c62e3e2 --- /dev/null +++ b/models/membership_test.go @@ -0,0 +1,56 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestMembershipModel(t *testing.T) { + model := Membership{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5ea5c16897e", UserName: "John Doe", UserEmail: "john@appwrite.io", TeamId: "5e5ea5c16897e", TeamName: "VIP", Invited: "2020-10-15T06:38:00.000+00:00", Joined: "2020-10-15T06:38:00.000+00:00", Confirm: true, Mfa: true, Roles: []string{"test"}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Membership + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.UserId != model.UserId { + t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) + } + if result.UserName != model.UserName { + t.Errorf("Expected UserName %v, got %v", model.UserName, result.UserName) + } + if result.UserEmail != model.UserEmail { + t.Errorf("Expected UserEmail %v, got %v", model.UserEmail, result.UserEmail) + } + if result.TeamId != model.TeamId { + t.Errorf("Expected TeamId %v, got %v", model.TeamId, result.TeamId) + } + if result.TeamName != model.TeamName { + t.Errorf("Expected TeamName %v, got %v", model.TeamName, result.TeamName) + } + if result.Invited != model.Invited { + t.Errorf("Expected Invited %v, got %v", model.Invited, result.Invited) + } + if result.Joined != model.Joined { + t.Errorf("Expected Joined %v, got %v", model.Joined, result.Joined) + } + if result.Confirm != model.Confirm { + t.Errorf("Expected Confirm %v, got %v", model.Confirm, result.Confirm) + } + if result.Mfa != model.Mfa { + t.Errorf("Expected Mfa %v, got %v", model.Mfa, result.Mfa) + }} diff --git a/models/message_list_test.go b/models/message_list_test.go new file mode 100644 index 00000000..28dbe442 --- /dev/null +++ b/models/message_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestMessageListModel(t *testing.T) { + model := MessageList{ Total: 5, Messages: []Message{Message{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", ProviderType: "email", Topics: []string{"test"}, Users: []string{"test"}, Targets: []string{"test"}, DeliveredTotal: 1, Data: map[string]interface{}{}, Status: "processing", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result MessageList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/message_test.go b/models/message_test.go new file mode 100644 index 00000000..09333f45 --- /dev/null +++ b/models/message_test.go @@ -0,0 +1,38 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestMessageModel(t *testing.T) { + model := Message{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", ProviderType: "email", Topics: []string{"test"}, Users: []string{"test"}, Targets: []string{"test"}, DeliveredTotal: 1, Data: map[string]interface{}{}, Status: "processing", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Message + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.ProviderType != model.ProviderType { + t.Errorf("Expected ProviderType %v, got %v", model.ProviderType, result.ProviderType) + } + if result.DeliveredTotal != model.DeliveredTotal { + t.Errorf("Expected DeliveredTotal %v, got %v", model.DeliveredTotal, result.DeliveredTotal) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + }} diff --git a/models/mfa_challenge_test.go b/models/mfa_challenge_test.go new file mode 100644 index 00000000..a0e636c5 --- /dev/null +++ b/models/mfa_challenge_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestMfaChallengeModel(t *testing.T) { + model := MfaChallenge{ Id: "bb8ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5ea5c168bb8", Expire: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result MfaChallenge + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UserId != model.UserId { + t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) + } + if result.Expire != model.Expire { + t.Errorf("Expected Expire %v, got %v", model.Expire, result.Expire) + }} diff --git a/models/mfa_factors_test.go b/models/mfa_factors_test.go new file mode 100644 index 00000000..7ab40c07 --- /dev/null +++ b/models/mfa_factors_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestMfaFactorsModel(t *testing.T) { + model := MfaFactors{ Totp: true, Phone: true, Email: true, RecoveryCode: true, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result MfaFactors + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Totp != model.Totp { + t.Errorf("Expected Totp %v, got %v", model.Totp, result.Totp) + } + if result.Phone != model.Phone { + t.Errorf("Expected Phone %v, got %v", model.Phone, result.Phone) + } + if result.Email != model.Email { + t.Errorf("Expected Email %v, got %v", model.Email, result.Email) + } + if result.RecoveryCode != model.RecoveryCode { + t.Errorf("Expected RecoveryCode %v, got %v", model.RecoveryCode, result.RecoveryCode) + }} diff --git a/models/mfa_recovery_codes_test.go b/models/mfa_recovery_codes_test.go new file mode 100644 index 00000000..fb668dcc --- /dev/null +++ b/models/mfa_recovery_codes_test.go @@ -0,0 +1,20 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestMfaRecoveryCodesModel(t *testing.T) { + model := MfaRecoveryCodes{ RecoveryCodes: []string{"test"}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result MfaRecoveryCodes + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + }} diff --git a/models/mfa_type_test.go b/models/mfa_type_test.go new file mode 100644 index 00000000..72960677 --- /dev/null +++ b/models/mfa_type_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestMfaTypeModel(t *testing.T) { + model := MfaType{ Secret: "[SHARED_SECRET]", Uri: "otpauth://totp/appwrite:user@example.com?secret=[SHARED_SECRET]&issuer=appwrite", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result MfaType + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Secret != model.Secret { + t.Errorf("Expected Secret %v, got %v", model.Secret, result.Secret) + } + if result.Uri != model.Uri { + t.Errorf("Expected Uri %v, got %v", model.Uri, result.Uri) + }} diff --git a/models/phone_list_test.go b/models/phone_list_test.go new file mode 100644 index 00000000..a7be9cff --- /dev/null +++ b/models/phone_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPhoneListModel(t *testing.T) { + model := PhoneList{ Total: 5, Phones: []Phone{Phone{ Code: "+1", CountryCode: "US", CountryName: "United States", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PhoneList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/phone_test.go b/models/phone_test.go new file mode 100644 index 00000000..51eee27d --- /dev/null +++ b/models/phone_test.go @@ -0,0 +1,29 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPhoneModel(t *testing.T) { + model := Phone{ Code: "+1", CountryCode: "US", CountryName: "United States", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Phone + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Code != model.Code { + t.Errorf("Expected Code %v, got %v", model.Code, result.Code) + } + if result.CountryCode != model.CountryCode { + t.Errorf("Expected CountryCode %v, got %v", model.CountryCode, result.CountryCode) + } + if result.CountryName != model.CountryName { + t.Errorf("Expected CountryName %v, got %v", model.CountryName, result.CountryName) + }} diff --git a/models/preferences_test.go b/models/preferences_test.go new file mode 100644 index 00000000..744eac25 --- /dev/null +++ b/models/preferences_test.go @@ -0,0 +1,20 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPreferencesModel(t *testing.T) { + model := Preferences{ } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Preferences + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + }} diff --git a/models/provider_list_test.go b/models/provider_list_test.go new file mode 100644 index 00000000..b96ab193 --- /dev/null +++ b/models/provider_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestProviderListModel(t *testing.T) { + model := ProviderList{ Total: 5, Providers: []Provider{Provider{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "Mailgun", Provider: "mailgun", Enabled: true, Type: "sms", Credentials: map[string]interface{}{}, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ProviderList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/provider_test.go b/models/provider_test.go new file mode 100644 index 00000000..f09028fe --- /dev/null +++ b/models/provider_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestProviderModel(t *testing.T) { + model := Provider{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "Mailgun", Provider: "mailgun", Enabled: true, Type: "sms", Credentials: map[string]interface{}{}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Provider + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Provider != model.Provider { + t.Errorf("Expected Provider %v, got %v", model.Provider, result.Provider) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + }} diff --git a/models/resource_token_list_test.go b/models/resource_token_list_test.go new file mode 100644 index 00000000..44a07074 --- /dev/null +++ b/models/resource_token_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestResourceTokenListModel(t *testing.T) { + model := ResourceTokenList{ Total: 5, Tokens: []ResourceToken{ResourceToken{ Id: "bb8ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", ResourceId: "5e5ea5c168bb8:5e5ea5c168bb8", ResourceType: "files", Expire: "2020-10-15T06:38:00.000+00:00", Secret: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", AccessedAt: "2020-10-15T06:38:00.000+00:00", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ResourceTokenList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/resource_token_test.go b/models/resource_token_test.go new file mode 100644 index 00000000..0cc001d5 --- /dev/null +++ b/models/resource_token_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestResourceTokenModel(t *testing.T) { + model := ResourceToken{ Id: "bb8ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", ResourceId: "5e5ea5c168bb8:5e5ea5c168bb8", ResourceType: "files", Expire: "2020-10-15T06:38:00.000+00:00", Secret: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", AccessedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ResourceToken + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.ResourceId != model.ResourceId { + t.Errorf("Expected ResourceId %v, got %v", model.ResourceId, result.ResourceId) + } + if result.ResourceType != model.ResourceType { + t.Errorf("Expected ResourceType %v, got %v", model.ResourceType, result.ResourceType) + } + if result.Expire != model.Expire { + t.Errorf("Expected Expire %v, got %v", model.Expire, result.Expire) + } + if result.Secret != model.Secret { + t.Errorf("Expected Secret %v, got %v", model.Secret, result.Secret) + } + if result.AccessedAt != model.AccessedAt { + t.Errorf("Expected AccessedAt %v, got %v", model.AccessedAt, result.AccessedAt) + }} diff --git a/models/row_list_test.go b/models/row_list_test.go new file mode 100644 index 00000000..cbf53303 --- /dev/null +++ b/models/row_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestRowListModel(t *testing.T) { + model := RowList{ Total: 5, Rows: []Row{Row{ Id: "5e5ea5c16897e", Sequence: "1", TableId: "5e5ea5c15117e", DatabaseId: "5e5ea5c15117e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result RowList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/row_test.go b/models/row_test.go new file mode 100644 index 00000000..92c328a5 --- /dev/null +++ b/models/row_test.go @@ -0,0 +1,38 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestRowModel(t *testing.T) { + model := Row{ Id: "5e5ea5c16897e", Sequence: "1", TableId: "5e5ea5c15117e", DatabaseId: "5e5ea5c15117e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Row + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Sequence != model.Sequence { + t.Errorf("Expected Sequence %v, got %v", model.Sequence, result.Sequence) + } + if result.TableId != model.TableId { + t.Errorf("Expected TableId %v, got %v", model.TableId, result.TableId) + } + if result.DatabaseId != model.DatabaseId { + t.Errorf("Expected DatabaseId %v, got %v", model.DatabaseId, result.DatabaseId) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/runtime_list_test.go b/models/runtime_list_test.go new file mode 100644 index 00000000..0c691759 --- /dev/null +++ b/models/runtime_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestRuntimeListModel(t *testing.T) { + model := RuntimeList{ Total: 5, Runtimes: []Runtime{Runtime{ Id: "python-3.8", Key: "python", Name: "Python", Version: "3.8", Base: "python:3.8-alpine", Image: "appwrite\\/runtime-for-python:3.8", Logo: "python.png", Supports: []string{"test"}, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result RuntimeList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/runtime_test.go b/models/runtime_test.go new file mode 100644 index 00000000..2387ac63 --- /dev/null +++ b/models/runtime_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestRuntimeModel(t *testing.T) { + model := Runtime{ Id: "python-3.8", Key: "python", Name: "Python", Version: "3.8", Base: "python:3.8-alpine", Image: "appwrite\\/runtime-for-python:3.8", Logo: "python.png", Supports: []string{"test"}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Runtime + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Version != model.Version { + t.Errorf("Expected Version %v, got %v", model.Version, result.Version) + } + if result.Base != model.Base { + t.Errorf("Expected Base %v, got %v", model.Base, result.Base) + } + if result.Image != model.Image { + t.Errorf("Expected Image %v, got %v", model.Image, result.Image) + } + if result.Logo != model.Logo { + t.Errorf("Expected Logo %v, got %v", model.Logo, result.Logo) + }} diff --git a/models/session_list_test.go b/models/session_list_test.go new file mode 100644 index 00000000..c7a8f793 --- /dev/null +++ b/models/session_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestSessionListModel(t *testing.T) { + model := SessionList{ Total: 5, Sessions: []Session{Session{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5bb8c16897e", Expire: "2020-10-15T06:38:00.000+00:00", Provider: "email", ProviderUid: "user@example.com", ProviderAccessToken: "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", ProviderAccessTokenExpiry: "2020-10-15T06:38:00.000+00:00", ProviderRefreshToken: "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", Ip: "127.0.0.1", OsCode: "Mac", OsName: "Mac", OsVersion: "Mac", ClientType: "browser", ClientCode: "CM", ClientName: "Chrome Mobile iOS", ClientVersion: "84.0", ClientEngine: "WebKit", ClientEngineVersion: "605.1.15", DeviceName: "smartphone", DeviceBrand: "Google", DeviceModel: "Nexus 5", CountryCode: "US", CountryName: "United States", Current: true, Factors: []string{"test"}, Secret: "5e5bb8c16897e", MfaUpdatedAt: "2020-10-15T06:38:00.000+00:00", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result SessionList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/session_test.go b/models/session_test.go new file mode 100644 index 00000000..0cb299f6 --- /dev/null +++ b/models/session_test.go @@ -0,0 +1,104 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestSessionModel(t *testing.T) { + model := Session{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5bb8c16897e", Expire: "2020-10-15T06:38:00.000+00:00", Provider: "email", ProviderUid: "user@example.com", ProviderAccessToken: "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", ProviderAccessTokenExpiry: "2020-10-15T06:38:00.000+00:00", ProviderRefreshToken: "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", Ip: "127.0.0.1", OsCode: "Mac", OsName: "Mac", OsVersion: "Mac", ClientType: "browser", ClientCode: "CM", ClientName: "Chrome Mobile iOS", ClientVersion: "84.0", ClientEngine: "WebKit", ClientEngineVersion: "605.1.15", DeviceName: "smartphone", DeviceBrand: "Google", DeviceModel: "Nexus 5", CountryCode: "US", CountryName: "United States", Current: true, Factors: []string{"test"}, Secret: "5e5bb8c16897e", MfaUpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Session + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.UserId != model.UserId { + t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) + } + if result.Expire != model.Expire { + t.Errorf("Expected Expire %v, got %v", model.Expire, result.Expire) + } + if result.Provider != model.Provider { + t.Errorf("Expected Provider %v, got %v", model.Provider, result.Provider) + } + if result.ProviderUid != model.ProviderUid { + t.Errorf("Expected ProviderUid %v, got %v", model.ProviderUid, result.ProviderUid) + } + if result.ProviderAccessToken != model.ProviderAccessToken { + t.Errorf("Expected ProviderAccessToken %v, got %v", model.ProviderAccessToken, result.ProviderAccessToken) + } + if result.ProviderAccessTokenExpiry != model.ProviderAccessTokenExpiry { + t.Errorf("Expected ProviderAccessTokenExpiry %v, got %v", model.ProviderAccessTokenExpiry, result.ProviderAccessTokenExpiry) + } + if result.ProviderRefreshToken != model.ProviderRefreshToken { + t.Errorf("Expected ProviderRefreshToken %v, got %v", model.ProviderRefreshToken, result.ProviderRefreshToken) + } + if result.Ip != model.Ip { + t.Errorf("Expected Ip %v, got %v", model.Ip, result.Ip) + } + if result.OsCode != model.OsCode { + t.Errorf("Expected OsCode %v, got %v", model.OsCode, result.OsCode) + } + if result.OsName != model.OsName { + t.Errorf("Expected OsName %v, got %v", model.OsName, result.OsName) + } + if result.OsVersion != model.OsVersion { + t.Errorf("Expected OsVersion %v, got %v", model.OsVersion, result.OsVersion) + } + if result.ClientType != model.ClientType { + t.Errorf("Expected ClientType %v, got %v", model.ClientType, result.ClientType) + } + if result.ClientCode != model.ClientCode { + t.Errorf("Expected ClientCode %v, got %v", model.ClientCode, result.ClientCode) + } + if result.ClientName != model.ClientName { + t.Errorf("Expected ClientName %v, got %v", model.ClientName, result.ClientName) + } + if result.ClientVersion != model.ClientVersion { + t.Errorf("Expected ClientVersion %v, got %v", model.ClientVersion, result.ClientVersion) + } + if result.ClientEngine != model.ClientEngine { + t.Errorf("Expected ClientEngine %v, got %v", model.ClientEngine, result.ClientEngine) + } + if result.ClientEngineVersion != model.ClientEngineVersion { + t.Errorf("Expected ClientEngineVersion %v, got %v", model.ClientEngineVersion, result.ClientEngineVersion) + } + if result.DeviceName != model.DeviceName { + t.Errorf("Expected DeviceName %v, got %v", model.DeviceName, result.DeviceName) + } + if result.DeviceBrand != model.DeviceBrand { + t.Errorf("Expected DeviceBrand %v, got %v", model.DeviceBrand, result.DeviceBrand) + } + if result.DeviceModel != model.DeviceModel { + t.Errorf("Expected DeviceModel %v, got %v", model.DeviceModel, result.DeviceModel) + } + if result.CountryCode != model.CountryCode { + t.Errorf("Expected CountryCode %v, got %v", model.CountryCode, result.CountryCode) + } + if result.CountryName != model.CountryName { + t.Errorf("Expected CountryName %v, got %v", model.CountryName, result.CountryName) + } + if result.Current != model.Current { + t.Errorf("Expected Current %v, got %v", model.Current, result.Current) + } + if result.Secret != model.Secret { + t.Errorf("Expected Secret %v, got %v", model.Secret, result.Secret) + } + if result.MfaUpdatedAt != model.MfaUpdatedAt { + t.Errorf("Expected MfaUpdatedAt %v, got %v", model.MfaUpdatedAt, result.MfaUpdatedAt) + }} diff --git a/models/site_list_test.go b/models/site_list_test.go new file mode 100644 index 00000000..a7c44422 --- /dev/null +++ b/models/site_list_test.go @@ -0,0 +1,25 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestSiteListModel(t *testing.T) { + model := SiteList{ Total: 5, Sites: []Site{Site{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "My Site", Enabled: true, Live: true, Logging: true, Framework: "react", DeploymentRetention: 7, DeploymentId: "5e5ea5c16897e", DeploymentCreatedAt: "2020-10-15T06:38:00.000+00:00", DeploymentScreenshotLight: "5e5ea5c16897e", DeploymentScreenshotDark: "5e5ea5c16897e", LatestDeploymentId: "5e5ea5c16897e", LatestDeploymentCreatedAt: "2020-10-15T06:38:00.000+00:00", LatestDeploymentStatus: "ready", Vars: []Variable{Variable{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "API_KEY", Value: "myPa$$word1", Secret: true, ResourceType: "function", ResourceId: "myAwesomeFunction", }, + }, Timeout: 300, InstallCommand: "npm install", BuildCommand: "npm run build", StartCommand: "node custom-server.mjs", OutputDirectory: "build", InstallationId: "6m40at4ejk5h2u9s1hboo", ProviderRepositoryId: "appwrite", ProviderBranch: "main", ProviderRootDirectory: "sites/helloWorld", ProviderSilentMode: true, BuildSpecification: "s-1vcpu-512mb", RuntimeSpecification: "s-1vcpu-512mb", BuildRuntime: "node-22", Adapter: "static", FallbackFile: "index.html", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result SiteList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/site_test.go b/models/site_test.go new file mode 100644 index 00000000..661ae432 --- /dev/null +++ b/models/site_test.go @@ -0,0 +1,114 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestSiteModel(t *testing.T) { + model := Site{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "My Site", Enabled: true, Live: true, Logging: true, Framework: "react", DeploymentRetention: 7, DeploymentId: "5e5ea5c16897e", DeploymentCreatedAt: "2020-10-15T06:38:00.000+00:00", DeploymentScreenshotLight: "5e5ea5c16897e", DeploymentScreenshotDark: "5e5ea5c16897e", LatestDeploymentId: "5e5ea5c16897e", LatestDeploymentCreatedAt: "2020-10-15T06:38:00.000+00:00", LatestDeploymentStatus: "ready", Vars: []Variable{Variable{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "API_KEY", Value: "myPa$$word1", Secret: true, ResourceType: "function", ResourceId: "myAwesomeFunction", }, + }, Timeout: 300, InstallCommand: "npm install", BuildCommand: "npm run build", StartCommand: "node custom-server.mjs", OutputDirectory: "build", InstallationId: "6m40at4ejk5h2u9s1hboo", ProviderRepositoryId: "appwrite", ProviderBranch: "main", ProviderRootDirectory: "sites/helloWorld", ProviderSilentMode: true, BuildSpecification: "s-1vcpu-512mb", RuntimeSpecification: "s-1vcpu-512mb", BuildRuntime: "node-22", Adapter: "static", FallbackFile: "index.html", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Site + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.Live != model.Live { + t.Errorf("Expected Live %v, got %v", model.Live, result.Live) + } + if result.Logging != model.Logging { + t.Errorf("Expected Logging %v, got %v", model.Logging, result.Logging) + } + if result.Framework != model.Framework { + t.Errorf("Expected Framework %v, got %v", model.Framework, result.Framework) + } + if result.DeploymentRetention != model.DeploymentRetention { + t.Errorf("Expected DeploymentRetention %v, got %v", model.DeploymentRetention, result.DeploymentRetention) + } + if result.DeploymentId != model.DeploymentId { + t.Errorf("Expected DeploymentId %v, got %v", model.DeploymentId, result.DeploymentId) + } + if result.DeploymentCreatedAt != model.DeploymentCreatedAt { + t.Errorf("Expected DeploymentCreatedAt %v, got %v", model.DeploymentCreatedAt, result.DeploymentCreatedAt) + } + if result.DeploymentScreenshotLight != model.DeploymentScreenshotLight { + t.Errorf("Expected DeploymentScreenshotLight %v, got %v", model.DeploymentScreenshotLight, result.DeploymentScreenshotLight) + } + if result.DeploymentScreenshotDark != model.DeploymentScreenshotDark { + t.Errorf("Expected DeploymentScreenshotDark %v, got %v", model.DeploymentScreenshotDark, result.DeploymentScreenshotDark) + } + if result.LatestDeploymentId != model.LatestDeploymentId { + t.Errorf("Expected LatestDeploymentId %v, got %v", model.LatestDeploymentId, result.LatestDeploymentId) + } + if result.LatestDeploymentCreatedAt != model.LatestDeploymentCreatedAt { + t.Errorf("Expected LatestDeploymentCreatedAt %v, got %v", model.LatestDeploymentCreatedAt, result.LatestDeploymentCreatedAt) + } + if result.LatestDeploymentStatus != model.LatestDeploymentStatus { + t.Errorf("Expected LatestDeploymentStatus %v, got %v", model.LatestDeploymentStatus, result.LatestDeploymentStatus) + } + if result.Timeout != model.Timeout { + t.Errorf("Expected Timeout %v, got %v", model.Timeout, result.Timeout) + } + if result.InstallCommand != model.InstallCommand { + t.Errorf("Expected InstallCommand %v, got %v", model.InstallCommand, result.InstallCommand) + } + if result.BuildCommand != model.BuildCommand { + t.Errorf("Expected BuildCommand %v, got %v", model.BuildCommand, result.BuildCommand) + } + if result.StartCommand != model.StartCommand { + t.Errorf("Expected StartCommand %v, got %v", model.StartCommand, result.StartCommand) + } + if result.OutputDirectory != model.OutputDirectory { + t.Errorf("Expected OutputDirectory %v, got %v", model.OutputDirectory, result.OutputDirectory) + } + if result.InstallationId != model.InstallationId { + t.Errorf("Expected InstallationId %v, got %v", model.InstallationId, result.InstallationId) + } + if result.ProviderRepositoryId != model.ProviderRepositoryId { + t.Errorf("Expected ProviderRepositoryId %v, got %v", model.ProviderRepositoryId, result.ProviderRepositoryId) + } + if result.ProviderBranch != model.ProviderBranch { + t.Errorf("Expected ProviderBranch %v, got %v", model.ProviderBranch, result.ProviderBranch) + } + if result.ProviderRootDirectory != model.ProviderRootDirectory { + t.Errorf("Expected ProviderRootDirectory %v, got %v", model.ProviderRootDirectory, result.ProviderRootDirectory) + } + if result.ProviderSilentMode != model.ProviderSilentMode { + t.Errorf("Expected ProviderSilentMode %v, got %v", model.ProviderSilentMode, result.ProviderSilentMode) + } + if result.BuildSpecification != model.BuildSpecification { + t.Errorf("Expected BuildSpecification %v, got %v", model.BuildSpecification, result.BuildSpecification) + } + if result.RuntimeSpecification != model.RuntimeSpecification { + t.Errorf("Expected RuntimeSpecification %v, got %v", model.RuntimeSpecification, result.RuntimeSpecification) + } + if result.BuildRuntime != model.BuildRuntime { + t.Errorf("Expected BuildRuntime %v, got %v", model.BuildRuntime, result.BuildRuntime) + } + if result.Adapter != model.Adapter { + t.Errorf("Expected Adapter %v, got %v", model.Adapter, result.Adapter) + } + if result.FallbackFile != model.FallbackFile { + t.Errorf("Expected FallbackFile %v, got %v", model.FallbackFile, result.FallbackFile) + }} diff --git a/models/specification_list_test.go b/models/specification_list_test.go new file mode 100644 index 00000000..0d106f20 --- /dev/null +++ b/models/specification_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestSpecificationListModel(t *testing.T) { + model := SpecificationList{ Total: 5, Specifications: []Specification{Specification{ Memory: 512, Cpus: 1, Enabled: true, Slug: "s-1vcpu-512mb", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result SpecificationList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/specification_test.go b/models/specification_test.go new file mode 100644 index 00000000..d86d825c --- /dev/null +++ b/models/specification_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestSpecificationModel(t *testing.T) { + model := Specification{ Memory: 512, Cpus: 1, Enabled: true, Slug: "s-1vcpu-512mb", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Specification + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Memory != model.Memory { + t.Errorf("Expected Memory %v, got %v", model.Memory, result.Memory) + } + if result.Cpus != model.Cpus { + t.Errorf("Expected Cpus %v, got %v", model.Cpus, result.Cpus) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.Slug != model.Slug { + t.Errorf("Expected Slug %v, got %v", model.Slug, result.Slug) + }} diff --git a/models/subscriber_list_test.go b/models/subscriber_list_test.go new file mode 100644 index 00000000..4bdf6ab8 --- /dev/null +++ b/models/subscriber_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestSubscriberListModel(t *testing.T) { + model := SubscriberList{ Total: 5, Subscribers: []Subscriber{Subscriber{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", TargetId: "259125845563242502", Target: Target{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "Apple iPhone 12", UserId: "259125845563242502", ProviderType: "email", Identifier: "token", Expired: true, }, UserId: "5e5ea5c16897e", UserName: "Aegon Targaryen", TopicId: "259125845563242502", ProviderType: "email", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result SubscriberList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/subscriber_test.go b/models/subscriber_test.go new file mode 100644 index 00000000..79d397ba --- /dev/null +++ b/models/subscriber_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestSubscriberModel(t *testing.T) { + model := Subscriber{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", TargetId: "259125845563242502", Target: Target{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "Apple iPhone 12", UserId: "259125845563242502", ProviderType: "email", Identifier: "token", Expired: true, }, UserId: "5e5ea5c16897e", UserName: "Aegon Targaryen", TopicId: "259125845563242502", ProviderType: "email", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Subscriber + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.TargetId != model.TargetId { + t.Errorf("Expected TargetId %v, got %v", model.TargetId, result.TargetId) + } + if result.UserId != model.UserId { + t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) + } + if result.UserName != model.UserName { + t.Errorf("Expected UserName %v, got %v", model.UserName, result.UserName) + } + if result.TopicId != model.TopicId { + t.Errorf("Expected TopicId %v, got %v", model.TopicId, result.TopicId) + } + if result.ProviderType != model.ProviderType { + t.Errorf("Expected ProviderType %v, got %v", model.ProviderType, result.ProviderType) + }} diff --git a/models/table_list_test.go b/models/table_list_test.go new file mode 100644 index 00000000..296ef225 --- /dev/null +++ b/models/table_list_test.go @@ -0,0 +1,25 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestTableListModel(t *testing.T) { + model := TableList{ Total: 5, Tables: []Table{Table{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, DatabaseId: "5e5ea5c16897e", Name: "My Table", Enabled: true, RowSecurity: true, Columns: []interface{}{}, Indexes: []ColumnIndex{ColumnIndex{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Columns: []string{"test"}, Lengths: []int{1}, }, + }, BytesMax: 65535, BytesUsed: 1500, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result TableList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/table_test.go b/models/table_test.go new file mode 100644 index 00000000..663ef690 --- /dev/null +++ b/models/table_test.go @@ -0,0 +1,48 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestTableModel(t *testing.T) { + model := Table{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, DatabaseId: "5e5ea5c16897e", Name: "My Table", Enabled: true, RowSecurity: true, Columns: []interface{}{}, Indexes: []ColumnIndex{ColumnIndex{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "index1", Type: "primary", Status: "available", Error: "string", Columns: []string{"test"}, Lengths: []int{1}, }, + }, BytesMax: 65535, BytesUsed: 1500, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Table + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.DatabaseId != model.DatabaseId { + t.Errorf("Expected DatabaseId %v, got %v", model.DatabaseId, result.DatabaseId) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.RowSecurity != model.RowSecurity { + t.Errorf("Expected RowSecurity %v, got %v", model.RowSecurity, result.RowSecurity) + } + if result.BytesMax != model.BytesMax { + t.Errorf("Expected BytesMax %v, got %v", model.BytesMax, result.BytesMax) + } + if result.BytesUsed != model.BytesUsed { + t.Errorf("Expected BytesUsed %v, got %v", model.BytesUsed, result.BytesUsed) + }} diff --git a/models/target_list_test.go b/models/target_list_test.go new file mode 100644 index 00000000..37554b4a --- /dev/null +++ b/models/target_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestTargetListModel(t *testing.T) { + model := TargetList{ Total: 5, Targets: []Target{Target{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "Apple iPhone 12", UserId: "259125845563242502", ProviderType: "email", Identifier: "token", Expired: true, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result TargetList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/target_test.go b/models/target_test.go new file mode 100644 index 00000000..90cfb076 --- /dev/null +++ b/models/target_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestTargetModel(t *testing.T) { + model := Target{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "Apple iPhone 12", UserId: "259125845563242502", ProviderType: "email", Identifier: "token", Expired: true, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Target + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.UserId != model.UserId { + t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) + } + if result.ProviderType != model.ProviderType { + t.Errorf("Expected ProviderType %v, got %v", model.ProviderType, result.ProviderType) + } + if result.Identifier != model.Identifier { + t.Errorf("Expected Identifier %v, got %v", model.Identifier, result.Identifier) + } + if result.Expired != model.Expired { + t.Errorf("Expected Expired %v, got %v", model.Expired, result.Expired) + }} diff --git a/models/team_list_test.go b/models/team_list_test.go new file mode 100644 index 00000000..4afb8455 --- /dev/null +++ b/models/team_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestTeamListModel(t *testing.T) { + model := TeamList{ Total: 5, Teams: []Team{Team{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "VIP", Total: 7, Prefs: Preferences{ }, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result TeamList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/team_test.go b/models/team_test.go new file mode 100644 index 00000000..4699d56f --- /dev/null +++ b/models/team_test.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestTeamModel(t *testing.T) { + model := Team{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "VIP", Total: 7, Prefs: Preferences{ }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Team + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/token_test.go b/models/token_test.go new file mode 100644 index 00000000..ef39f0bb --- /dev/null +++ b/models/token_test.go @@ -0,0 +1,38 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestTokenModel(t *testing.T) { + model := Token{ Id: "bb8ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5ea5c168bb8", Secret: "string", Expire: "2020-10-15T06:38:00.000+00:00", Phrase: "Golden Fox", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Token + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UserId != model.UserId { + t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) + } + if result.Secret != model.Secret { + t.Errorf("Expected Secret %v, got %v", model.Secret, result.Secret) + } + if result.Expire != model.Expire { + t.Errorf("Expected Expire %v, got %v", model.Expire, result.Expire) + } + if result.Phrase != model.Phrase { + t.Errorf("Expected Phrase %v, got %v", model.Phrase, result.Phrase) + }} diff --git a/models/topic_list_test.go b/models/topic_list_test.go new file mode 100644 index 00000000..470e2284 --- /dev/null +++ b/models/topic_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestTopicListModel(t *testing.T) { + model := TopicList{ Total: 5, Topics: []Topic{Topic{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "events", EmailTotal: 100, SmsTotal: 100, PushTotal: 100, Subscribe: []string{"test"}, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result TopicList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/topic_test.go b/models/topic_test.go new file mode 100644 index 00000000..c911ccaf --- /dev/null +++ b/models/topic_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestTopicModel(t *testing.T) { + model := Topic{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "events", EmailTotal: 100, SmsTotal: 100, PushTotal: 100, Subscribe: []string{"test"}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Topic + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.EmailTotal != model.EmailTotal { + t.Errorf("Expected EmailTotal %v, got %v", model.EmailTotal, result.EmailTotal) + } + if result.SmsTotal != model.SmsTotal { + t.Errorf("Expected SmsTotal %v, got %v", model.SmsTotal, result.SmsTotal) + } + if result.PushTotal != model.PushTotal { + t.Errorf("Expected PushTotal %v, got %v", model.PushTotal, result.PushTotal) + }} diff --git a/models/transaction_list_test.go b/models/transaction_list_test.go new file mode 100644 index 00000000..aea72278 --- /dev/null +++ b/models/transaction_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestTransactionListModel(t *testing.T) { + model := TransactionList{ Total: 5, Transactions: []Transaction{Transaction{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Status: "pending", Operations: 5, ExpiresAt: "2020-10-15T06:38:00.000+00:00", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result TransactionList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/transaction_test.go b/models/transaction_test.go new file mode 100644 index 00000000..ffe0c9a4 --- /dev/null +++ b/models/transaction_test.go @@ -0,0 +1,38 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestTransactionModel(t *testing.T) { + model := Transaction{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Status: "pending", Operations: 5, ExpiresAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Transaction + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Operations != model.Operations { + t.Errorf("Expected Operations %v, got %v", model.Operations, result.Operations) + } + if result.ExpiresAt != model.ExpiresAt { + t.Errorf("Expected ExpiresAt %v, got %v", model.ExpiresAt, result.ExpiresAt) + }} diff --git a/models/user_list_test.go b/models/user_list_test.go new file mode 100644 index 00000000..fa6248b0 --- /dev/null +++ b/models/user_list_test.go @@ -0,0 +1,25 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestUserListModel(t *testing.T) { + model := UserList{ Total: 5, Users: []User{User{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "John Doe", Registration: "2020-10-15T06:38:00.000+00:00", Status: true, Labels: []string{"test"}, PasswordUpdate: "2020-10-15T06:38:00.000+00:00", Email: "john@appwrite.io", Phone: "+4930901820", EmailVerification: true, PhoneVerification: true, Mfa: true, Prefs: Preferences{ }, Targets: []Target{Target{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "Apple iPhone 12", UserId: "259125845563242502", ProviderType: "email", Identifier: "token", Expired: true, }, + }, AccessedAt: "2020-10-15T06:38:00.000+00:00", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result UserList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/user_test.go b/models/user_test.go new file mode 100644 index 00000000..4917e1f5 --- /dev/null +++ b/models/user_test.go @@ -0,0 +1,60 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestUserModel(t *testing.T) { + model := User{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "John Doe", Registration: "2020-10-15T06:38:00.000+00:00", Status: true, Labels: []string{"test"}, PasswordUpdate: "2020-10-15T06:38:00.000+00:00", Email: "john@appwrite.io", Phone: "+4930901820", EmailVerification: true, PhoneVerification: true, Mfa: true, Prefs: Preferences{ }, Targets: []Target{Target{ Id: "259125845563242502", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "Apple iPhone 12", UserId: "259125845563242502", ProviderType: "email", Identifier: "token", Expired: true, }, + }, AccessedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result User + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Registration != model.Registration { + t.Errorf("Expected Registration %v, got %v", model.Registration, result.Registration) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.PasswordUpdate != model.PasswordUpdate { + t.Errorf("Expected PasswordUpdate %v, got %v", model.PasswordUpdate, result.PasswordUpdate) + } + if result.Email != model.Email { + t.Errorf("Expected Email %v, got %v", model.Email, result.Email) + } + if result.Phone != model.Phone { + t.Errorf("Expected Phone %v, got %v", model.Phone, result.Phone) + } + if result.EmailVerification != model.EmailVerification { + t.Errorf("Expected EmailVerification %v, got %v", model.EmailVerification, result.EmailVerification) + } + if result.PhoneVerification != model.PhoneVerification { + t.Errorf("Expected PhoneVerification %v, got %v", model.PhoneVerification, result.PhoneVerification) + } + if result.Mfa != model.Mfa { + t.Errorf("Expected Mfa %v, got %v", model.Mfa, result.Mfa) + } + if result.AccessedAt != model.AccessedAt { + t.Errorf("Expected AccessedAt %v, got %v", model.AccessedAt, result.AccessedAt) + }} diff --git a/models/variable_list_test.go b/models/variable_list_test.go new file mode 100644 index 00000000..5ea53ca6 --- /dev/null +++ b/models/variable_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestVariableListModel(t *testing.T) { + model := VariableList{ Total: 5, Variables: []Variable{Variable{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "API_KEY", Value: "myPa$$word1", Secret: true, ResourceType: "function", ResourceId: "myAwesomeFunction", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result VariableList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/variable_test.go b/models/variable_test.go new file mode 100644 index 00000000..daeec8d3 --- /dev/null +++ b/models/variable_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestVariableModel(t *testing.T) { + model := Variable{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Key: "API_KEY", Value: "myPa$$word1", Secret: true, ResourceType: "function", ResourceId: "myAwesomeFunction", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Variable + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Value != model.Value { + t.Errorf("Expected Value %v, got %v", model.Value, result.Value) + } + if result.Secret != model.Secret { + t.Errorf("Expected Secret %v, got %v", model.Secret, result.Secret) + } + if result.ResourceType != model.ResourceType { + t.Errorf("Expected ResourceType %v, got %v", model.ResourceType, result.ResourceType) + } + if result.ResourceId != model.ResourceId { + t.Errorf("Expected ResourceId %v, got %v", model.ResourceId, result.ResourceId) + }} diff --git a/models/webhook_list_test.go b/models/webhook_list_test.go new file mode 100644 index 00000000..6135451c --- /dev/null +++ b/models/webhook_list_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestWebhookListModel(t *testing.T) { + model := WebhookList{ Total: 5, Webhooks: []Webhook{Webhook{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "My Webhook", Url: "https://example.com/webhook", Events: []string{"test"}, Security: true, HttpUser: "username", HttpPass: "password", SignatureKey: "ad3d581ca230e2b7059c545e5a", Enabled: true, Logs: "Failed to connect to remote server.", Attempts: 10, }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result WebhookList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/webhook_test.go b/models/webhook_test.go new file mode 100644 index 00000000..ea599948 --- /dev/null +++ b/models/webhook_test.go @@ -0,0 +1,56 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestWebhookModel(t *testing.T) { + model := Webhook{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "My Webhook", Url: "https://example.com/webhook", Events: []string{"test"}, Security: true, HttpUser: "username", HttpPass: "password", SignatureKey: "ad3d581ca230e2b7059c545e5a", Enabled: true, Logs: "Failed to connect to remote server.", Attempts: 10, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Webhook + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Url != model.Url { + t.Errorf("Expected Url %v, got %v", model.Url, result.Url) + } + if result.Security != model.Security { + t.Errorf("Expected Security %v, got %v", model.Security, result.Security) + } + if result.HttpUser != model.HttpUser { + t.Errorf("Expected HttpUser %v, got %v", model.HttpUser, result.HttpUser) + } + if result.HttpPass != model.HttpPass { + t.Errorf("Expected HttpPass %v, got %v", model.HttpPass, result.HttpPass) + } + if result.SignatureKey != model.SignatureKey { + t.Errorf("Expected SignatureKey %v, got %v", model.SignatureKey, result.SignatureKey) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.Logs != model.Logs { + t.Errorf("Expected Logs %v, got %v", model.Logs, result.Logs) + } + if result.Attempts != model.Attempts { + t.Errorf("Expected Attempts %v, got %v", model.Attempts, result.Attempts) + }} diff --git a/operator/operator_test.go b/operator/operator_test.go new file mode 100644 index 00000000..49b96b4a --- /dev/null +++ b/operator/operator_test.go @@ -0,0 +1,113 @@ +package operator + +import ( + "encoding/json" + "testing" +) + +func TestIncrement(t *testing.T) { + q := Increment(1) + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "increment" { + t.Errorf("Expected increment, got %s", data["method"]) + } + values := data["values"].([]interface{}) + if values[0].(float64) != 1 { + t.Errorf("Expected [1], got %v", values[0]) + } +} + +func TestDecrement(t *testing.T) { + q := Decrement(1, 0) + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "decrement" { + t.Errorf("Expected decrement, got %s", data["method"]) + } + values := data["values"].([]interface{}) + if values[0].(float64) != 1 { + t.Errorf("Expected decrement amount to be 1, got %v", values[0]) + } + if values[1].(float64) != 0 { + t.Errorf("Expected default value to be 0, got %v", values[1]) + } +} + +func TestMultiply(t *testing.T) { + q := Multiply(2) + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "multiply" { + t.Errorf("Expected multiply, got %s", data["method"]) + } + values := data["values"].([]interface{}) + if values[0].(float64) != 2 { + t.Errorf("Expected [2], got %v", values) + } +} + +func TestDivide(t *testing.T) { + q := Divide(2) + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "divide" { + t.Errorf("Expected divide, got %s", data["method"]) + } +} + +func TestArrayAppend(t *testing.T) { + q := ArrayAppend([]interface{}{"a", "b"}) + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "arrayAppend" { + t.Errorf("Expected arrayAppend, got %s", data["method"]) + } + values := data["values"].([]interface{}) + if values[0] != "a" || values[1] != "b" { + t.Errorf("Expected [a, b], got %v", values) + } +} + +func TestArrayRemove(t *testing.T) { + q := ArrayRemove("item") + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "arrayRemove" { + t.Errorf("Expected arrayRemove, got %s", data["method"]) + } + values := data["values"].([]interface{}) + if values[0] != "item" { + t.Errorf("Expected [item], got %v", values) + } +} + +func TestStringConcat(t *testing.T) { + q := StringConcat("suffix") + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "stringConcat" { + t.Errorf("Expected stringConcat, got %s", data["method"]) + } +} diff --git a/permission/permission_test.go b/permission/permission_test.go new file mode 100644 index 00000000..12d26032 --- /dev/null +++ b/permission/permission_test.go @@ -0,0 +1,35 @@ +package permission + +import ( + "testing" +) + +func TestRead(t *testing.T) { + if Read("any") != "read(\"any\")" { + t.Errorf("Expected read(\"any\"), got %s", Read("any")) + } +} + +func TestWrite(t *testing.T) { + if Write("any") != "write(\"any\")" { + t.Errorf("Expected write(\"any\"), got %s", Write("any")) + } +} + +func TestCreate(t *testing.T) { + if Create("any") != "create(\"any\")" { + t.Errorf("Expected create(\"any\"), got %s", Create("any")) + } +} + +func TestUpdate(t *testing.T) { + if Update("any") != "update(\"any\")" { + t.Errorf("Expected update(\"any\"), got %s", Update("any")) + } +} + +func TestDelete(t *testing.T) { + if Delete("any") != "delete(\"any\")" { + t.Errorf("Expected delete(\"any\"), got %s", Delete("any")) + } +} diff --git a/project/project.go b/project/project.go index e887c917..9f5d3b89 100644 --- a/project/project.go +++ b/project/project.go @@ -3,8 +3,8 @@ package project import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/project/project_test.go b/project/project_test.go new file mode 100644 index 00000000..f186f04a --- /dev/null +++ b/project/project_test.go @@ -0,0 +1,181 @@ +package project + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestProject(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test ListVariables", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "variables": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListVariables() + if err != nil { + t.Errorf("Method ListVariables failed: %v", err) + } + }) + + t.Run("Test CreateVariable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateVariable("", "", "") + if err != nil { + t.Errorf("Method CreateVariable failed: %v", err) + } + }) + + t.Run("Test GetVariable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetVariable("") + if err != nil { + t.Errorf("Method GetVariable failed: %v", err) + } + }) + + t.Run("Test UpdateVariable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateVariable("") + if err != nil { + t.Errorf("Method UpdateVariable failed: %v", err) + } + }) + + t.Run("Test DeleteVariable", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteVariable("") + if err != nil { + t.Errorf("Method DeleteVariable failed: %v", err) + } + }) +} diff --git a/query/query_test.go b/query/query_test.go new file mode 100644 index 00000000..9df38df9 --- /dev/null +++ b/query/query_test.go @@ -0,0 +1,126 @@ +package query + +import ( + "encoding/json" + "testing" +) + +func TestEqual(t *testing.T) { + q := Equal("attr", "val") + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "equal" { + t.Errorf("Expected equal, got %v", data["method"]) + } + if data["attribute"] != "attr" { + t.Errorf("Expected attr, got %v", data["attribute"]) + } + values := data["values"].([]interface{}) + if values[0] != "val" { + t.Errorf("Expected val, got %v", values[0]) + } +} + +func TestNotEqual(t *testing.T) { + q := NotEqual("attr", 123) + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "notEqual" { + t.Errorf("Expected notEqual, got %v", data["method"]) + } + values := data["values"].([]interface{}) + if values[0].(float64) != 123 { + t.Errorf("Expected 123, got %v", values[0]) + } +} + +func TestBetween(t *testing.T) { + q := Between("attr", 1, 10) + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "between" { + t.Errorf("Expected between, got %v", data["method"]) + } + values := data["values"].([]interface{}) + if values[0].(float64) != 1 { + t.Errorf("Expected 1, got %v", values[0]) + } + if values[1].(float64) != 10 { + t.Errorf("Expected 10, got %v", values[1]) + } +} + +func TestSelect(t *testing.T) { + q := Select([]interface{}{"attr1", "attr2"}) + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "select" { + t.Errorf("Expected select, got %v", data["method"]) + } + values := data["values"].([]interface{}) + if values[0] != "attr1" || values[1] != "attr2" { + t.Errorf("Expected [attr1, attr2], got %v", values) + } +} + +func TestOrderAsc(t *testing.T) { + q := OrderAsc("attr") + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "orderAsc" { + t.Errorf("Expected orderAsc, got %v", data["method"]) + } + if data["attribute"] != "attr" { + t.Errorf("Expected attr, got %v", data["attribute"]) + } +} + +func TestLimit(t *testing.T) { + q := Limit(25) + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "limit" { + t.Errorf("Expected limit, got %v", data["method"]) + } + values := data["values"].([]interface{}) + if values[0].(float64) != 25 { + t.Errorf("Expected 25, got %v", values[0]) + } +} + +func TestOr(t *testing.T) { + q1 := Equal("name", "Alice") + q2 := Equal("name", "Bob") + q := Or([]string{q1, q2}) + + var data map[string]interface{} + if err := json.Unmarshal([]byte(q), &data); err != nil { + t.Fatal(err) + } + + if data["method"] != "or" { + t.Errorf("Expected or, got %v", data["method"]) + } + values := data["values"].([]interface{}) + if len(values) != 2 { + t.Errorf("Expected 2 subqueries, got %d", len(values)) + } +} diff --git a/role/role_test.go b/role/role_test.go new file mode 100644 index 00000000..2f0fd3f2 --- /dev/null +++ b/role/role_test.go @@ -0,0 +1,56 @@ +package role + +import ( + "testing" +) + +func TestAny(t *testing.T) { + if Any() != "any" { + t.Errorf("Expected any, got %s", Any()) + } +} + +func TestUser(t *testing.T) { + if User("custom", "") != "user:custom" { + t.Errorf("Expected user:custom, got %s", User("custom", "")) + } + if User("custom", "status") != "user:custom/status" { + t.Errorf("Expected user:custom/status, got %s", User("custom", "status")) + } +} + +func TestUsers(t *testing.T) { + if Users("") != "users" { + t.Errorf("Expected users, got %s", Users("")) + } + if Users("status") != "users/status" { + t.Errorf("Expected users/status, got %s", Users("status")) + } +} + +func TestGuests(t *testing.T) { + if Guests() != "guests" { + t.Errorf("Expected guests, got %s", Guests()) + } +} + +func TestTeam(t *testing.T) { + if Team("custom", "") != "team:custom" { + t.Errorf("Expected team:custom, got %s", Team("custom", "")) + } + if Team("custom", "owner") != "team:custom/owner" { + t.Errorf("Expected team:custom/owner, got %s", Team("custom", "owner")) + } +} + +func TestMember(t *testing.T) { + if Member("custom") != "member:custom" { + t.Errorf("Expected member:custom, got %s", Member("custom")) + } +} + +func TestLabel(t *testing.T) { + if Label("admin") != "label:admin" { + t.Errorf("Expected label:admin, got %s", Label("admin")) + } +} diff --git a/sites/sites.go b/sites/sites.go index b5fc27e3..3efc0ebf 100644 --- a/sites/sites.go +++ b/sites/sites.go @@ -3,9 +3,9 @@ package sites import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" - "github.com/appwrite/sdk-for-go/file" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" + "github.com/appwrite/sdk-for-go/v2/file" "net/url" "fmt" "strings" diff --git a/sites/sites_test.go b/sites/sites_test.go new file mode 100644 index 00000000..a5ce6862 --- /dev/null +++ b/sites/sites_test.go @@ -0,0 +1,1196 @@ +package sites + +import ( + "net/http" + "net/http/httptest" + "testing" + "os" + + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/file") + +func TestSites(t *testing.T) { + tmpFile, err := os.CreateTemp("", "test") + if err != nil { + t.Fatal(err) + } + defer os.Remove(tmpFile.Name()) + _, _ = tmpFile.WriteString("test content") + _ = tmpFile.Close() + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test List", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "sites": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Site", + "enabled": true, + "live": true, + "logging": true, + "framework": "react", + "deploymentRetention": 7, + "deploymentId": "5e5ea5c16897e", + "deploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "deploymentScreenshotLight": "5e5ea5c16897e", + "deploymentScreenshotDark": "5e5ea5c16897e", + "latestDeploymentId": "5e5ea5c16897e", + "latestDeploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentStatus": "ready", + "vars": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ], + "timeout": 300, + "installCommand": "npm install", + "buildCommand": "npm run build", + "startCommand": "node custom-server.mjs", + "outputDirectory": "build", + "installationId": "6m40at4ejk5h2u9s1hboo", + "providerRepositoryId": "appwrite", + "providerBranch": "main", + "providerRootDirectory": "sites/helloWorld", + "providerSilentMode": true, + "buildSpecification": "s-1vcpu-512mb", + "runtimeSpecification": "s-1vcpu-512mb", + "buildRuntime": "node-22", + "adapter": "static", + "fallbackFile": "index.html" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.List() + if err != nil { + t.Errorf("Method List failed: %v", err) + } + }) + + t.Run("Test Create", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Site", + "enabled": true, + "live": true, + "logging": true, + "framework": "react", + "deploymentRetention": 7, + "deploymentId": "5e5ea5c16897e", + "deploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "deploymentScreenshotLight": "5e5ea5c16897e", + "deploymentScreenshotDark": "5e5ea5c16897e", + "latestDeploymentId": "5e5ea5c16897e", + "latestDeploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentStatus": "ready", + "vars": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ], + "timeout": 300, + "installCommand": "npm install", + "buildCommand": "npm run build", + "startCommand": "node custom-server.mjs", + "outputDirectory": "build", + "installationId": "6m40at4ejk5h2u9s1hboo", + "providerRepositoryId": "appwrite", + "providerBranch": "main", + "providerRootDirectory": "sites/helloWorld", + "providerSilentMode": true, + "buildSpecification": "s-1vcpu-512mb", + "runtimeSpecification": "s-1vcpu-512mb", + "buildRuntime": "node-22", + "adapter": "static", + "fallbackFile": "index.html" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Create("", "", "analog", "node-14.5") + if err != nil { + t.Errorf("Method Create failed: %v", err) + } + }) + + t.Run("Test ListFrameworks", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "frameworks": [ + { + "key": "sveltekit", + "name": "SvelteKit", + "buildRuntime": "node-22", + "runtimes": [], + "adapters": [ + { + "key": "static", + "installCommand": "npm install", + "buildCommand": "npm run build", + "outputDirectory": "./dist", + "fallbackFile": "index.html" + } + ] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListFrameworks() + if err != nil { + t.Errorf("Method ListFrameworks failed: %v", err) + } + }) + + t.Run("Test ListSpecifications", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "specifications": [ + { + "memory": 512, + "cpus": 1, + "enabled": true, + "slug": "s-1vcpu-512mb" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListSpecifications() + if err != nil { + t.Errorf("Method ListSpecifications failed: %v", err) + } + }) + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Site", + "enabled": true, + "live": true, + "logging": true, + "framework": "react", + "deploymentRetention": 7, + "deploymentId": "5e5ea5c16897e", + "deploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "deploymentScreenshotLight": "5e5ea5c16897e", + "deploymentScreenshotDark": "5e5ea5c16897e", + "latestDeploymentId": "5e5ea5c16897e", + "latestDeploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentStatus": "ready", + "vars": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ], + "timeout": 300, + "installCommand": "npm install", + "buildCommand": "npm run build", + "startCommand": "node custom-server.mjs", + "outputDirectory": "build", + "installationId": "6m40at4ejk5h2u9s1hboo", + "providerRepositoryId": "appwrite", + "providerBranch": "main", + "providerRootDirectory": "sites/helloWorld", + "providerSilentMode": true, + "buildSpecification": "s-1vcpu-512mb", + "runtimeSpecification": "s-1vcpu-512mb", + "buildRuntime": "node-22", + "adapter": "static", + "fallbackFile": "index.html" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get("") + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test Update", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Site", + "enabled": true, + "live": true, + "logging": true, + "framework": "react", + "deploymentRetention": 7, + "deploymentId": "5e5ea5c16897e", + "deploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "deploymentScreenshotLight": "5e5ea5c16897e", + "deploymentScreenshotDark": "5e5ea5c16897e", + "latestDeploymentId": "5e5ea5c16897e", + "latestDeploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentStatus": "ready", + "vars": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ], + "timeout": 300, + "installCommand": "npm install", + "buildCommand": "npm run build", + "startCommand": "node custom-server.mjs", + "outputDirectory": "build", + "installationId": "6m40at4ejk5h2u9s1hboo", + "providerRepositoryId": "appwrite", + "providerBranch": "main", + "providerRootDirectory": "sites/helloWorld", + "providerSilentMode": true, + "buildSpecification": "s-1vcpu-512mb", + "runtimeSpecification": "s-1vcpu-512mb", + "buildRuntime": "node-22", + "adapter": "static", + "fallbackFile": "index.html" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Update("", "", "analog") + if err != nil { + t.Errorf("Method Update failed: %v", err) + } + }) + + t.Run("Test Delete", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Delete("") + if err != nil { + t.Errorf("Method Delete failed: %v", err) + } + }) + + t.Run("Test UpdateSiteDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Site", + "enabled": true, + "live": true, + "logging": true, + "framework": "react", + "deploymentRetention": 7, + "deploymentId": "5e5ea5c16897e", + "deploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "deploymentScreenshotLight": "5e5ea5c16897e", + "deploymentScreenshotDark": "5e5ea5c16897e", + "latestDeploymentId": "5e5ea5c16897e", + "latestDeploymentCreatedAt": "2020-10-15T06:38:00.000+00:00", + "latestDeploymentStatus": "ready", + "vars": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ], + "timeout": 300, + "installCommand": "npm install", + "buildCommand": "npm run build", + "startCommand": "node custom-server.mjs", + "outputDirectory": "build", + "installationId": "6m40at4ejk5h2u9s1hboo", + "providerRepositoryId": "appwrite", + "providerBranch": "main", + "providerRootDirectory": "sites/helloWorld", + "providerSilentMode": true, + "buildSpecification": "s-1vcpu-512mb", + "runtimeSpecification": "s-1vcpu-512mb", + "buildRuntime": "node-22", + "adapter": "static", + "fallbackFile": "index.html" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSiteDeployment("", "") + if err != nil { + t.Errorf("Method UpdateSiteDeployment failed: %v", err) + } + }) + + t.Run("Test ListDeployments", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "deployments": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListDeployments("") + if err != nil { + t.Errorf("Method ListDeployments failed: %v", err) + } + }) + + t.Run("Test CreateDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == "GET" && "POST" != "GET" { + // Handle file upload resume check + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"chunksUploaded": 0}`)) + return + } + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateDeployment("", file.NewInputFile(tmpFile.Name(), "test.txt")) + if err != nil { + t.Errorf("Method CreateDeployment failed: %v", err) + } + }) + + t.Run("Test CreateDuplicateDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateDuplicateDeployment("", "") + if err != nil { + t.Errorf("Method CreateDuplicateDeployment failed: %v", err) + } + }) + + t.Run("Test CreateTemplateDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTemplateDeployment("", "", "", "", "branch", "") + if err != nil { + t.Errorf("Method CreateTemplateDeployment failed: %v", err) + } + }) + + t.Run("Test CreateVcsDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateVcsDeployment("", "branch", "") + if err != nil { + t.Errorf("Method CreateVcsDeployment failed: %v", err) + } + }) + + t.Run("Test GetDeployment", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetDeployment("", "") + if err != nil { + t.Errorf("Method GetDeployment failed: %v", err) + } + }) + + t.Run("Test DeleteDeployment", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteDeployment("", "") + if err != nil { + t.Errorf("Method DeleteDeployment failed: %v", err) + } + }) + + t.Run("Test GetDeploymentDownload", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetDeploymentDownload("", "") + if err != nil { + t.Errorf("Method GetDeploymentDownload failed: %v", err) + } + }) + + t.Run("Test UpdateDeploymentStatus", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "type": "vcs", + "resourceId": "5e5ea6g16897e", + "resourceType": "functions", + "entrypoint": "index.js", + "sourceSize": 128, + "buildSize": 128, + "totalSize": 128, + "buildId": "5e5ea5c16897e", + "activate": true, + "screenshotLight": "5e5ea5c16897e", + "screenshotDark": "5e5ea5c16897e", + "status": "ready", + "buildLogs": "Compiling source files...", + "buildDuration": 128, + "providerRepositoryName": "database", + "providerRepositoryOwner": "utopia", + "providerRepositoryUrl": "https://github.com/vermakhushboo/g4-node-function", + "providerCommitHash": "7c3f25d", + "providerCommitAuthorUrl": "https://github.com/vermakhushboo", + "providerCommitAuthor": "Khushboo Verma", + "providerCommitMessage": "Update index.js", + "providerCommitUrl": "https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb", + "providerBranch": "0.7.x", + "providerBranchUrl": "https://github.com/vermakhushboo/appwrite/tree/0.7.x" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateDeploymentStatus("", "") + if err != nil { + t.Errorf("Method UpdateDeploymentStatus failed: %v", err) + } + }) + + t.Run("Test ListLogs", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "executions": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "functionId": "5e5ea6g16897e", + "deploymentId": "5e5ea5c16897e", + "trigger": "http", + "status": "processing", + "requestMethod": "GET", + "requestPath": "/articles?id=5", + "requestHeaders": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "responseStatusCode": 200, + "responseBody": "string", + "responseHeaders": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "logs": "string", + "errors": "string", + "duration": 0.4 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListLogs("") + if err != nil { + t.Errorf("Method ListLogs failed: %v", err) + } + }) + + t.Run("Test GetLog", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "functionId": "5e5ea6g16897e", + "deploymentId": "5e5ea5c16897e", + "trigger": "http", + "status": "processing", + "requestMethod": "GET", + "requestPath": "/articles?id=5", + "requestHeaders": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "responseStatusCode": 200, + "responseBody": "string", + "responseHeaders": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "logs": "string", + "errors": "string", + "duration": 0.4 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetLog("", "") + if err != nil { + t.Errorf("Method GetLog failed: %v", err) + } + }) + + t.Run("Test DeleteLog", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteLog("", "") + if err != nil { + t.Errorf("Method DeleteLog failed: %v", err) + } + }) + + t.Run("Test ListVariables", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "variables": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListVariables("") + if err != nil { + t.Errorf("Method ListVariables failed: %v", err) + } + }) + + t.Run("Test CreateVariable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateVariable("", "", "") + if err != nil { + t.Errorf("Method CreateVariable failed: %v", err) + } + }) + + t.Run("Test GetVariable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetVariable("", "") + if err != nil { + t.Errorf("Method GetVariable failed: %v", err) + } + }) + + t.Run("Test UpdateVariable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "API_KEY", + "value": "myPa$$word1", + "secret": true, + "resourceType": "function", + "resourceId": "myAwesomeFunction" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateVariable("", "", "") + if err != nil { + t.Errorf("Method UpdateVariable failed: %v", err) + } + }) + + t.Run("Test DeleteVariable", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteVariable("", "") + if err != nil { + t.Errorf("Method DeleteVariable failed: %v", err) + } + }) +} diff --git a/storage/storage.go b/storage/storage.go index d7d2ffe3..c35248ce 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -3,9 +3,9 @@ package storage import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" - "github.com/appwrite/sdk-for-go/file" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" + "github.com/appwrite/sdk-for-go/v2/file" "net/url" "fmt" "strings" diff --git a/storage/storage_test.go b/storage/storage_test.go new file mode 100644 index 00000000..8f6556dc --- /dev/null +++ b/storage/storage_test.go @@ -0,0 +1,469 @@ +package storage + +import ( + "net/http" + "net/http/httptest" + "testing" + "os" + + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/file") + +func TestStorage(t *testing.T) { + tmpFile, err := os.CreateTemp("", "test") + if err != nil { + t.Fatal(err) + } + defer os.Remove(tmpFile.Name()) + _, _ = tmpFile.WriteString("test content") + _ = tmpFile.Close() + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test ListBuckets", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "buckets": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "fileSecurity": true, + "name": "Documents", + "enabled": true, + "maximumFileSize": 100, + "allowedFileExtensions": [], + "compression": "gzip", + "encryption": true, + "antivirus": true, + "transformations": true, + "totalSize": 128 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListBuckets() + if err != nil { + t.Errorf("Method ListBuckets failed: %v", err) + } + }) + + t.Run("Test CreateBucket", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "fileSecurity": true, + "name": "Documents", + "enabled": true, + "maximumFileSize": 100, + "allowedFileExtensions": [], + "compression": "gzip", + "encryption": true, + "antivirus": true, + "transformations": true, + "totalSize": 128 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateBucket("", "") + if err != nil { + t.Errorf("Method CreateBucket failed: %v", err) + } + }) + + t.Run("Test GetBucket", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "fileSecurity": true, + "name": "Documents", + "enabled": true, + "maximumFileSize": 100, + "allowedFileExtensions": [], + "compression": "gzip", + "encryption": true, + "antivirus": true, + "transformations": true, + "totalSize": 128 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetBucket("") + if err != nil { + t.Errorf("Method GetBucket failed: %v", err) + } + }) + + t.Run("Test UpdateBucket", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "fileSecurity": true, + "name": "Documents", + "enabled": true, + "maximumFileSize": 100, + "allowedFileExtensions": [], + "compression": "gzip", + "encryption": true, + "antivirus": true, + "transformations": true, + "totalSize": 128 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateBucket("", "") + if err != nil { + t.Errorf("Method UpdateBucket failed: %v", err) + } + }) + + t.Run("Test DeleteBucket", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteBucket("") + if err != nil { + t.Errorf("Method DeleteBucket failed: %v", err) + } + }) + + t.Run("Test ListFiles", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "files": [ + { + "$id": "5e5ea5c16897e", + "bucketId": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "name": "Pink.png", + "signature": "5d529fd02b544198ae075bd57c1762bb", + "mimeType": "image/png", + "sizeOriginal": 17890, + "chunksTotal": 17890, + "chunksUploaded": 17890, + "encryption": true, + "compression": "gzip" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListFiles("") + if err != nil { + t.Errorf("Method ListFiles failed: %v", err) + } + }) + + t.Run("Test CreateFile", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "bucketId": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "name": "Pink.png", + "signature": "5d529fd02b544198ae075bd57c1762bb", + "mimeType": "image/png", + "sizeOriginal": 17890, + "chunksTotal": 17890, + "chunksUploaded": 17890, + "encryption": true, + "compression": "gzip" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == "GET" && "POST" != "GET" { + // Handle file upload resume check + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"chunksUploaded": 0}`)) + return + } + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateFile("", "", file.NewInputFile(tmpFile.Name(), "test.txt")) + if err != nil { + t.Errorf("Method CreateFile failed: %v", err) + } + }) + + t.Run("Test GetFile", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "bucketId": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "name": "Pink.png", + "signature": "5d529fd02b544198ae075bd57c1762bb", + "mimeType": "image/png", + "sizeOriginal": 17890, + "chunksTotal": 17890, + "chunksUploaded": 17890, + "encryption": true, + "compression": "gzip" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetFile("", "") + if err != nil { + t.Errorf("Method GetFile failed: %v", err) + } + }) + + t.Run("Test UpdateFile", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "bucketId": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "name": "Pink.png", + "signature": "5d529fd02b544198ae075bd57c1762bb", + "mimeType": "image/png", + "sizeOriginal": 17890, + "chunksTotal": 17890, + "chunksUploaded": 17890, + "encryption": true, + "compression": "gzip" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateFile("", "") + if err != nil { + t.Errorf("Method UpdateFile failed: %v", err) + } + }) + + t.Run("Test DeleteFile", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteFile("", "") + if err != nil { + t.Errorf("Method DeleteFile failed: %v", err) + } + }) + + t.Run("Test GetFileDownload", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetFileDownload("", "") + if err != nil { + t.Errorf("Method GetFileDownload failed: %v", err) + } + }) + + t.Run("Test GetFilePreview", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetFilePreview("", "") + if err != nil { + t.Errorf("Method GetFilePreview failed: %v", err) + } + }) + + t.Run("Test GetFileView", func(t *testing.T) { + mockData := []byte("image_data") + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "image/png") + w.WriteHeader(http.StatusOK) + _, _ = w.Write(mockData) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetFileView("", "") + if err != nil { + t.Errorf("Method GetFileView failed: %v", err) + } + }) +} diff --git a/tablesdb/tables_db.go b/tablesdb/tables_db.go index a13243a9..bbac17d5 100644 --- a/tablesdb/tables_db.go +++ b/tablesdb/tables_db.go @@ -3,8 +3,8 @@ package tablesdb import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/tablesdb/tables_db_test.go b/tablesdb/tables_db_test.go new file mode 100644 index 00000000..1cd255f0 --- /dev/null +++ b/tablesdb/tables_db_test.go @@ -0,0 +1,2487 @@ +package tablesdb + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestTablesDB(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test List", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "databases": [ + { + "$id": "5e5ea5c16897e", + "name": "My Database", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "enabled": true, + "type": "legacy", + "policies": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "archives": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 + } + ] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.List() + if err != nil { + t.Errorf("Method List failed: %v", err) + } + }) + + t.Run("Test Create", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "name": "My Database", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "enabled": true, + "type": "legacy", + "policies": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "archives": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Create("", "") + if err != nil { + t.Errorf("Method Create failed: %v", err) + } + }) + + t.Run("Test ListTransactions", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "transactions": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "status": "pending", + "operations": 5, + "expiresAt": "2020-10-15T06:38:00.000+00:00" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListTransactions() + if err != nil { + t.Errorf("Method ListTransactions failed: %v", err) + } + }) + + t.Run("Test CreateTransaction", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "status": "pending", + "operations": 5, + "expiresAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTransaction() + if err != nil { + t.Errorf("Method CreateTransaction failed: %v", err) + } + }) + + t.Run("Test GetTransaction", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "status": "pending", + "operations": 5, + "expiresAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetTransaction("") + if err != nil { + t.Errorf("Method GetTransaction failed: %v", err) + } + }) + + t.Run("Test UpdateTransaction", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "status": "pending", + "operations": 5, + "expiresAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateTransaction("") + if err != nil { + t.Errorf("Method UpdateTransaction failed: %v", err) + } + }) + + t.Run("Test DeleteTransaction", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteTransaction("") + if err != nil { + t.Errorf("Method DeleteTransaction failed: %v", err) + } + }) + + t.Run("Test CreateOperations", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "status": "pending", + "operations": 5, + "expiresAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateOperations("") + if err != nil { + t.Errorf("Method CreateOperations failed: %v", err) + } + }) + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "name": "My Database", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "enabled": true, + "type": "legacy", + "policies": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "archives": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get("") + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test Update", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "name": "My Database", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "enabled": true, + "type": "legacy", + "policies": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "archives": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Collection", + "enabled": true, + "documentSecurity": true, + "attributes": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "attributes": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Update("") + if err != nil { + t.Errorf("Method Update failed: %v", err) + } + }) + + t.Run("Test Delete", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Delete("") + if err != nil { + t.Errorf("Method Delete failed: %v", err) + } + }) + + t.Run("Test ListTables", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "tables": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Table", + "enabled": true, + "rowSecurity": true, + "columns": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "columns": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListTables("") + if err != nil { + t.Errorf("Method ListTables failed: %v", err) + } + }) + + t.Run("Test CreateTable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Table", + "enabled": true, + "rowSecurity": true, + "columns": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "columns": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTable("", "", "") + if err != nil { + t.Errorf("Method CreateTable failed: %v", err) + } + }) + + t.Run("Test GetTable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Table", + "enabled": true, + "rowSecurity": true, + "columns": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "columns": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetTable("", "") + if err != nil { + t.Errorf("Method GetTable failed: %v", err) + } + }) + + t.Run("Test UpdateTable", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "databaseId": "5e5ea5c16897e", + "name": "My Table", + "enabled": true, + "rowSecurity": true, + "columns": [], + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "columns": [], + "lengths": [] + } + ], + "bytesMax": 65535, + "bytesUsed": 1500 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateTable("", "") + if err != nil { + t.Errorf("Method UpdateTable failed: %v", err) + } + }) + + t.Run("Test DeleteTable", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteTable("", "") + if err != nil { + t.Errorf("Method DeleteTable failed: %v", err) + } + }) + + t.Run("Test ListColumns", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "columns": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListColumns("", "") + if err != nil { + t.Errorf("Method ListColumns failed: %v", err) + } + }) + + t.Run("Test CreateBooleanColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "isEnabled", + "type": "boolean", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateBooleanColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateBooleanColumn failed: %v", err) + } + }) + + t.Run("Test UpdateBooleanColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "isEnabled", + "type": "boolean", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateBooleanColumn("", "", "", true, true) + if err != nil { + t.Errorf("Method UpdateBooleanColumn failed: %v", err) + } + }) + + t.Run("Test CreateDatetimeColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "birthDay", + "type": "datetime", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "datetime" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateDatetimeColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateDatetimeColumn failed: %v", err) + } + }) + + t.Run("Test UpdateDatetimeColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "birthDay", + "type": "datetime", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "datetime" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateDatetimeColumn("", "", "", true, "2020-10-15T06:38:00.000+00:00") + if err != nil { + t.Errorf("Method UpdateDatetimeColumn failed: %v", err) + } + }) + + t.Run("Test CreateEmailColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "userEmail", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "email" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateEmailColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateEmailColumn failed: %v", err) + } + }) + + t.Run("Test UpdateEmailColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "userEmail", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "email" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateEmailColumn("", "", "", true, "email@example.com") + if err != nil { + t.Errorf("Method UpdateEmailColumn failed: %v", err) + } + }) + + t.Run("Test CreateEnumColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "status", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "elements": [], + "format": "enum" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateEnumColumn("", "", "", []string{}, true) + if err != nil { + t.Errorf("Method CreateEnumColumn failed: %v", err) + } + }) + + t.Run("Test UpdateEnumColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "status", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "elements": [], + "format": "enum" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateEnumColumn("", "", "", []string{}, true, "") + if err != nil { + t.Errorf("Method UpdateEnumColumn failed: %v", err) + } + }) + + t.Run("Test CreateFloatColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "percentageCompleted", + "type": "double", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateFloatColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateFloatColumn failed: %v", err) + } + }) + + t.Run("Test UpdateFloatColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "percentageCompleted", + "type": "double", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateFloatColumn("", "", "", true, 1.0) + if err != nil { + t.Errorf("Method UpdateFloatColumn failed: %v", err) + } + }) + + t.Run("Test CreateIntegerColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "count", + "type": "integer", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateIntegerColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateIntegerColumn failed: %v", err) + } + }) + + t.Run("Test UpdateIntegerColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "count", + "type": "integer", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateIntegerColumn("", "", "", true, 1) + if err != nil { + t.Errorf("Method UpdateIntegerColumn failed: %v", err) + } + }) + + t.Run("Test CreateIpColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "ipAddress", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "ip" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateIpColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateIpColumn failed: %v", err) + } + }) + + t.Run("Test UpdateIpColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "ipAddress", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "ip" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateIpColumn("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateIpColumn failed: %v", err) + } + }) + + t.Run("Test CreateLineColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateLineColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateLineColumn failed: %v", err) + } + }) + + t.Run("Test UpdateLineColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateLineColumn("", "", "", true) + if err != nil { + t.Errorf("Method UpdateLineColumn failed: %v", err) + } + }) + + t.Run("Test CreateLongtextColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateLongtextColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateLongtextColumn failed: %v", err) + } + }) + + t.Run("Test UpdateLongtextColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateLongtextColumn("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateLongtextColumn failed: %v", err) + } + }) + + t.Run("Test CreateMediumtextColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMediumtextColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateMediumtextColumn failed: %v", err) + } + }) + + t.Run("Test UpdateMediumtextColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMediumtextColumn("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateMediumtextColumn failed: %v", err) + } + }) + + t.Run("Test CreatePointColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreatePointColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreatePointColumn failed: %v", err) + } + }) + + t.Run("Test UpdatePointColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePointColumn("", "", "", true) + if err != nil { + t.Errorf("Method UpdatePointColumn failed: %v", err) + } + }) + + t.Run("Test CreatePolygonColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreatePolygonColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreatePolygonColumn failed: %v", err) + } + }) + + t.Run("Test UpdatePolygonColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePolygonColumn("", "", "", true) + if err != nil { + t.Errorf("Method UpdatePolygonColumn failed: %v", err) + } + }) + + t.Run("Test CreateRelationshipColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "relatedTable": "table", + "relationType": "oneToOne|oneToMany|manyToOne|manyToMany", + "twoWay": true, + "twoWayKey": "string", + "onDelete": "restrict|cascade|setNull", + "side": "parent|child" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateRelationshipColumn("", "", "", "oneToOne") + if err != nil { + t.Errorf("Method CreateRelationshipColumn failed: %v", err) + } + }) + + t.Run("Test CreateStringColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "size": 128 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateStringColumn("", "", "", 1, true) + if err != nil { + t.Errorf("Method CreateStringColumn failed: %v", err) + } + }) + + t.Run("Test UpdateStringColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "size": 128 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateStringColumn("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateStringColumn failed: %v", err) + } + }) + + t.Run("Test CreateTextColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTextColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateTextColumn failed: %v", err) + } + }) + + t.Run("Test UpdateTextColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateTextColumn("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateTextColumn failed: %v", err) + } + }) + + t.Run("Test CreateUrlColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "githubUrl", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "url" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateUrlColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateUrlColumn failed: %v", err) + } + }) + + t.Run("Test UpdateUrlColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "githubUrl", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "format": "url" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateUrlColumn("", "", "", true, "https://example.com") + if err != nil { + t.Errorf("Method UpdateUrlColumn failed: %v", err) + } + }) + + t.Run("Test CreateVarcharColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "size": 128 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateVarcharColumn("", "", "", 1, true) + if err != nil { + t.Errorf("Method CreateVarcharColumn failed: %v", err) + } + }) + + t.Run("Test UpdateVarcharColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "size": 128 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateVarcharColumn("", "", "", true, "") + if err != nil { + t.Errorf("Method UpdateVarcharColumn failed: %v", err) + } + }) + + t.Run("Test GetColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "isEnabled", + "type": "boolean", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetColumn("", "", "") + if err != nil { + t.Errorf("Method GetColumn failed: %v", err) + } + }) + + t.Run("Test DeleteColumn", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteColumn("", "", "") + if err != nil { + t.Errorf("Method DeleteColumn failed: %v", err) + } + }) + + t.Run("Test UpdateRelationshipColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "fullName", + "type": "string", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "relatedTable": "table", + "relationType": "oneToOne|oneToMany|manyToOne|manyToMany", + "twoWay": true, + "twoWayKey": "string", + "onDelete": "restrict|cascade|setNull", + "side": "parent|child" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateRelationshipColumn("", "", "") + if err != nil { + t.Errorf("Method UpdateRelationshipColumn failed: %v", err) + } + }) + + t.Run("Test ListIndexes", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "indexes": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "columns": [], + "lengths": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListIndexes("", "") + if err != nil { + t.Errorf("Method ListIndexes failed: %v", err) + } + }) + + t.Run("Test CreateIndex", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "columns": [], + "lengths": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateIndex("", "", "", "key", []string{}) + if err != nil { + t.Errorf("Method CreateIndex failed: %v", err) + } + }) + + t.Run("Test GetIndex", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "key": "index1", + "type": "primary", + "status": "available", + "error": "string", + "columns": [], + "lengths": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetIndex("", "", "") + if err != nil { + t.Errorf("Method GetIndex failed: %v", err) + } + }) + + t.Run("Test DeleteIndex", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteIndex("", "", "") + if err != nil { + t.Errorf("Method DeleteIndex failed: %v", err) + } + }) + + t.Run("Test ListRows", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "rows": [ + { + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$tableId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListRows("", "") + if err != nil { + t.Errorf("Method ListRows failed: %v", err) + } + }) + + t.Run("Test CreateRow", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$tableId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateRow("", "", "", map[string]interface{}{}) + if err != nil { + t.Errorf("Method CreateRow failed: %v", err) + } + }) + + t.Run("Test CreateRows", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "rows": [ + { + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$tableId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateRows("", "", []interface{}{}) + if err != nil { + t.Errorf("Method CreateRows failed: %v", err) + } + }) + + t.Run("Test UpsertRows", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "rows": [ + { + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$tableId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpsertRows("", "", []interface{}{}) + if err != nil { + t.Errorf("Method UpsertRows failed: %v", err) + } + }) + + t.Run("Test UpdateRows", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "rows": [ + { + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$tableId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateRows("", "") + if err != nil { + t.Errorf("Method UpdateRows failed: %v", err) + } + }) + + t.Run("Test DeleteRows", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "rows": [ + { + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$tableId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteRows("", "") + if err != nil { + t.Errorf("Method DeleteRows failed: %v", err) + } + }) + + t.Run("Test GetRow", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$tableId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetRow("", "", "") + if err != nil { + t.Errorf("Method GetRow failed: %v", err) + } + }) + + t.Run("Test UpsertRow", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$tableId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpsertRow("", "", "") + if err != nil { + t.Errorf("Method UpsertRow failed: %v", err) + } + }) + + t.Run("Test UpdateRow", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$tableId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateRow("", "", "") + if err != nil { + t.Errorf("Method UpdateRow failed: %v", err) + } + }) + + t.Run("Test DeleteRow", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteRow("", "", "") + if err != nil { + t.Errorf("Method DeleteRow failed: %v", err) + } + }) + + t.Run("Test DecrementRowColumn", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$tableId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DecrementRowColumn("", "", "", "") + if err != nil { + t.Errorf("Method DecrementRowColumn failed: %v", err) + } + }) + + t.Run("Test IncrementRowColumn", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$tableId": "5e5ea5c15117e", + "$databaseId": "5e5ea5c15117e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.IncrementRowColumn("", "", "", "") + if err != nil { + t.Errorf("Method IncrementRowColumn failed: %v", err) + } + }) +} diff --git a/teams/teams.go b/teams/teams.go index b6020f1a..6c550a59 100644 --- a/teams/teams.go +++ b/teams/teams.go @@ -3,8 +3,8 @@ package teams import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/teams/teams_test.go b/teams/teams_test.go new file mode 100644 index 00000000..d70df847 --- /dev/null +++ b/teams/teams_test.go @@ -0,0 +1,448 @@ +package teams + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestTeams(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test List", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "teams": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "VIP", + "total": 7, + "prefs": { + } + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.List() + if err != nil { + t.Errorf("Method List failed: %v", err) + } + }) + + t.Run("Test Create", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "VIP", + "total": 7, + "prefs": { + } +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Create("", "") + if err != nil { + t.Errorf("Method Create failed: %v", err) + } + }) + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "VIP", + "total": 7, + "prefs": { + } +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get("") + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test UpdateName", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "VIP", + "total": 7, + "prefs": { + } +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateName("", "") + if err != nil { + t.Errorf("Method UpdateName failed: %v", err) + } + }) + + t.Run("Test Delete", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Delete("") + if err != nil { + t.Errorf("Method Delete failed: %v", err) + } + }) + + t.Run("Test ListMemberships", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "memberships": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c16897e", + "userName": "John Doe", + "userEmail": "john@appwrite.io", + "teamId": "5e5ea5c16897e", + "teamName": "VIP", + "invited": "2020-10-15T06:38:00.000+00:00", + "joined": "2020-10-15T06:38:00.000+00:00", + "confirm": true, + "mfa": true, + "roles": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListMemberships("") + if err != nil { + t.Errorf("Method ListMemberships failed: %v", err) + } + }) + + t.Run("Test CreateMembership", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c16897e", + "userName": "John Doe", + "userEmail": "john@appwrite.io", + "teamId": "5e5ea5c16897e", + "teamName": "VIP", + "invited": "2020-10-15T06:38:00.000+00:00", + "joined": "2020-10-15T06:38:00.000+00:00", + "confirm": true, + "mfa": true, + "roles": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMembership("", []string{}) + if err != nil { + t.Errorf("Method CreateMembership failed: %v", err) + } + }) + + t.Run("Test GetMembership", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c16897e", + "userName": "John Doe", + "userEmail": "john@appwrite.io", + "teamId": "5e5ea5c16897e", + "teamName": "VIP", + "invited": "2020-10-15T06:38:00.000+00:00", + "joined": "2020-10-15T06:38:00.000+00:00", + "confirm": true, + "mfa": true, + "roles": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetMembership("", "") + if err != nil { + t.Errorf("Method GetMembership failed: %v", err) + } + }) + + t.Run("Test UpdateMembership", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c16897e", + "userName": "John Doe", + "userEmail": "john@appwrite.io", + "teamId": "5e5ea5c16897e", + "teamName": "VIP", + "invited": "2020-10-15T06:38:00.000+00:00", + "joined": "2020-10-15T06:38:00.000+00:00", + "confirm": true, + "mfa": true, + "roles": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMembership("", "", []string{}) + if err != nil { + t.Errorf("Method UpdateMembership failed: %v", err) + } + }) + + t.Run("Test DeleteMembership", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteMembership("", "") + if err != nil { + t.Errorf("Method DeleteMembership failed: %v", err) + } + }) + + t.Run("Test UpdateMembershipStatus", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c16897e", + "userName": "John Doe", + "userEmail": "john@appwrite.io", + "teamId": "5e5ea5c16897e", + "teamName": "VIP", + "invited": "2020-10-15T06:38:00.000+00:00", + "joined": "2020-10-15T06:38:00.000+00:00", + "confirm": true, + "mfa": true, + "roles": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMembershipStatus("", "", "", "") + if err != nil { + t.Errorf("Method UpdateMembershipStatus failed: %v", err) + } + }) + + t.Run("Test GetPrefs", func(t *testing.T) { + mockResponse := ` +{ +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetPrefs("") + if err != nil { + t.Errorf("Method GetPrefs failed: %v", err) + } + }) + + t.Run("Test UpdatePrefs", func(t *testing.T) { + mockResponse := ` +{ +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePrefs("", map[string]interface{}{}) + if err != nil { + t.Errorf("Method UpdatePrefs failed: %v", err) + } + }) +} diff --git a/tokens/tokens.go b/tokens/tokens.go index df2dadbf..6c4730c0 100644 --- a/tokens/tokens.go +++ b/tokens/tokens.go @@ -3,8 +3,8 @@ package tokens import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/tokens/tokens_test.go b/tokens/tokens_test.go new file mode 100644 index 00000000..18694f0e --- /dev/null +++ b/tokens/tokens_test.go @@ -0,0 +1,177 @@ +package tokens + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestTokens(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test List", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "tokens": [ + { + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceId": "5e5ea5c168bb8:5e5ea5c168bb8", + "resourceType": "files", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", + "accessedAt": "2020-10-15T06:38:00.000+00:00" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.List("", "") + if err != nil { + t.Errorf("Method List failed: %v", err) + } + }) + + t.Run("Test CreateFileToken", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceId": "5e5ea5c168bb8:5e5ea5c168bb8", + "resourceType": "files", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateFileToken("", "") + if err != nil { + t.Errorf("Method CreateFileToken failed: %v", err) + } + }) + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceId": "5e5ea5c168bb8:5e5ea5c168bb8", + "resourceType": "files", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get("") + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test Update", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceId": "5e5ea5c168bb8:5e5ea5c168bb8", + "resourceType": "files", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Update("") + if err != nil { + t.Errorf("Method Update failed: %v", err) + } + }) + + t.Run("Test Delete", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Delete("") + if err != nil { + t.Errorf("Method Delete failed: %v", err) + } + }) +} diff --git a/users/users.go b/users/users.go index a15070df..ace8dcfa 100644 --- a/users/users.go +++ b/users/users.go @@ -3,8 +3,8 @@ package users import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/users/users_test.go b/users/users_test.go new file mode 100644 index 00000000..1c9e7482 --- /dev/null +++ b/users/users_test.go @@ -0,0 +1,2023 @@ +package users + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestUsers(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test List", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "users": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.List() + if err != nil { + t.Errorf("Method List failed: %v", err) + } + }) + + t.Run("Test Create", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Create("") + if err != nil { + t.Errorf("Method Create failed: %v", err) + } + }) + + t.Run("Test CreateArgon2User", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateArgon2User("", "email@example.com", "password") + if err != nil { + t.Errorf("Method CreateArgon2User failed: %v", err) + } + }) + + t.Run("Test CreateBcryptUser", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateBcryptUser("", "email@example.com", "password") + if err != nil { + t.Errorf("Method CreateBcryptUser failed: %v", err) + } + }) + + t.Run("Test ListIdentities", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "identities": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "provider": "email", + "providerUid": "5e5bb8c16897e", + "providerEmail": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListIdentities() + if err != nil { + t.Errorf("Method ListIdentities failed: %v", err) + } + }) + + t.Run("Test DeleteIdentity", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteIdentity("") + if err != nil { + t.Errorf("Method DeleteIdentity failed: %v", err) + } + }) + + t.Run("Test CreateMD5User", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMD5User("", "email@example.com", "password") + if err != nil { + t.Errorf("Method CreateMD5User failed: %v", err) + } + }) + + t.Run("Test CreatePHPassUser", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreatePHPassUser("", "email@example.com", "password") + if err != nil { + t.Errorf("Method CreatePHPassUser failed: %v", err) + } + }) + + t.Run("Test CreateScryptUser", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateScryptUser("", "email@example.com", "password", "", 1, 1, 1, 1) + if err != nil { + t.Errorf("Method CreateScryptUser failed: %v", err) + } + }) + + t.Run("Test CreateScryptModifiedUser", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateScryptModifiedUser("", "email@example.com", "password", "", "", "") + if err != nil { + t.Errorf("Method CreateScryptModifiedUser failed: %v", err) + } + }) + + t.Run("Test CreateSHAUser", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateSHAUser("", "email@example.com", "password") + if err != nil { + t.Errorf("Method CreateSHAUser failed: %v", err) + } + }) + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get("") + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test Delete", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Delete("") + if err != nil { + t.Errorf("Method Delete failed: %v", err) + } + }) + + t.Run("Test UpdateEmail", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateEmail("", "email@example.com") + if err != nil { + t.Errorf("Method UpdateEmail failed: %v", err) + } + }) + + t.Run("Test UpdateImpersonator", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateImpersonator("", true) + if err != nil { + t.Errorf("Method UpdateImpersonator failed: %v", err) + } + }) + + t.Run("Test CreateJWT", func(t *testing.T) { + mockResponse := ` +{ + "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateJWT("") + if err != nil { + t.Errorf("Method CreateJWT failed: %v", err) + } + }) + + t.Run("Test UpdateLabels", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateLabels("", []string{}) + if err != nil { + t.Errorf("Method UpdateLabels failed: %v", err) + } + }) + + t.Run("Test ListLogs", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "logs": [ + { + "event": "account.sessions.create", + "userId": "610fc2f985ee0", + "userEmail": "john@appwrite.io", + "userName": "John Doe", + "mode": "admin", + "ip": "127.0.0.1", + "time": "2020-10-15T06:38:00.000+00:00", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListLogs("") + if err != nil { + t.Errorf("Method ListLogs failed: %v", err) + } + }) + + t.Run("Test ListMemberships", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "memberships": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c16897e", + "userName": "John Doe", + "userEmail": "john@appwrite.io", + "teamId": "5e5ea5c16897e", + "teamName": "VIP", + "invited": "2020-10-15T06:38:00.000+00:00", + "joined": "2020-10-15T06:38:00.000+00:00", + "confirm": true, + "mfa": true, + "roles": [] + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListMemberships("") + if err != nil { + t.Errorf("Method ListMemberships failed: %v", err) + } + }) + + t.Run("Test UpdateMfa", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMfa("", true) + if err != nil { + t.Errorf("Method UpdateMfa failed: %v", err) + } + }) + + t.Run("Test UpdateMFA", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMFA("", true) + if err != nil { + t.Errorf("Method UpdateMFA failed: %v", err) + } + }) + + t.Run("Test DeleteMfaAuthenticator", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteMfaAuthenticator("", "totp") + if err != nil { + t.Errorf("Method DeleteMfaAuthenticator failed: %v", err) + } + }) + + t.Run("Test DeleteMFAAuthenticator", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteMFAAuthenticator("", "totp") + if err != nil { + t.Errorf("Method DeleteMFAAuthenticator failed: %v", err) + } + }) + + t.Run("Test ListMfaFactors", func(t *testing.T) { + mockResponse := ` +{ + "totp": true, + "phone": true, + "email": true, + "recoveryCode": true +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListMfaFactors("") + if err != nil { + t.Errorf("Method ListMfaFactors failed: %v", err) + } + }) + + t.Run("Test ListMFAFactors", func(t *testing.T) { + mockResponse := ` +{ + "totp": true, + "phone": true, + "email": true, + "recoveryCode": true +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListMFAFactors("") + if err != nil { + t.Errorf("Method ListMFAFactors failed: %v", err) + } + }) + + t.Run("Test GetMfaRecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetMfaRecoveryCodes("") + if err != nil { + t.Errorf("Method GetMfaRecoveryCodes failed: %v", err) + } + }) + + t.Run("Test GetMFARecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetMFARecoveryCodes("") + if err != nil { + t.Errorf("Method GetMFARecoveryCodes failed: %v", err) + } + }) + + t.Run("Test UpdateMfaRecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMfaRecoveryCodes("") + if err != nil { + t.Errorf("Method UpdateMfaRecoveryCodes failed: %v", err) + } + }) + + t.Run("Test UpdateMFARecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMFARecoveryCodes("") + if err != nil { + t.Errorf("Method UpdateMFARecoveryCodes failed: %v", err) + } + }) + + t.Run("Test CreateMfaRecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMfaRecoveryCodes("") + if err != nil { + t.Errorf("Method CreateMfaRecoveryCodes failed: %v", err) + } + }) + + t.Run("Test CreateMFARecoveryCodes", func(t *testing.T) { + mockResponse := ` +{ + "recoveryCodes": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateMFARecoveryCodes("") + if err != nil { + t.Errorf("Method CreateMFARecoveryCodes failed: %v", err) + } + }) + + t.Run("Test UpdateName", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateName("", "") + if err != nil { + t.Errorf("Method UpdateName failed: %v", err) + } + }) + + t.Run("Test UpdatePassword", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePassword("", "") + if err != nil { + t.Errorf("Method UpdatePassword failed: %v", err) + } + }) + + t.Run("Test UpdatePhone", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePhone("", "+12065550100") + if err != nil { + t.Errorf("Method UpdatePhone failed: %v", err) + } + }) + + t.Run("Test GetPrefs", func(t *testing.T) { + mockResponse := ` +{ +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetPrefs("") + if err != nil { + t.Errorf("Method GetPrefs failed: %v", err) + } + }) + + t.Run("Test UpdatePrefs", func(t *testing.T) { + mockResponse := ` +{ +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePrefs("", map[string]interface{}{}) + if err != nil { + t.Errorf("Method UpdatePrefs failed: %v", err) + } + }) + + t.Run("Test ListSessions", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "sessions": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListSessions("") + if err != nil { + t.Errorf("Method ListSessions failed: %v", err) + } + }) + + t.Run("Test CreateSession", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5bb8c16897e", + "expire": "2020-10-15T06:38:00.000+00:00", + "provider": "email", + "providerUid": "user@example.com", + "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", + "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", + "ip": "127.0.0.1", + "osCode": "Mac", + "osName": "Mac", + "osVersion": "Mac", + "clientType": "browser", + "clientCode": "CM", + "clientName": "Chrome Mobile iOS", + "clientVersion": "84.0", + "clientEngine": "WebKit", + "clientEngineVersion": "605.1.15", + "deviceName": "smartphone", + "deviceBrand": "Google", + "deviceModel": "Nexus 5", + "countryCode": "US", + "countryName": "United States", + "current": true, + "factors": [], + "secret": "5e5bb8c16897e", + "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateSession("") + if err != nil { + t.Errorf("Method CreateSession failed: %v", err) + } + }) + + t.Run("Test DeleteSessions", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteSessions("") + if err != nil { + t.Errorf("Method DeleteSessions failed: %v", err) + } + }) + + t.Run("Test DeleteSession", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteSession("", "") + if err != nil { + t.Errorf("Method DeleteSession failed: %v", err) + } + }) + + t.Run("Test UpdateStatus", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateStatus("", true) + if err != nil { + t.Errorf("Method UpdateStatus failed: %v", err) + } + }) + + t.Run("Test ListTargets", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListTargets("") + if err != nil { + t.Errorf("Method ListTargets failed: %v", err) + } + }) + + t.Run("Test CreateTarget", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateTarget("", "", "email", "") + if err != nil { + t.Errorf("Method CreateTarget failed: %v", err) + } + }) + + t.Run("Test GetTarget", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetTarget("", "") + if err != nil { + t.Errorf("Method GetTarget failed: %v", err) + } + }) + + t.Run("Test UpdateTarget", func(t *testing.T) { + mockResponse := ` +{ + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateTarget("", "") + if err != nil { + t.Errorf("Method UpdateTarget failed: %v", err) + } + }) + + t.Run("Test DeleteTarget", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteTarget("", "") + if err != nil { + t.Errorf("Method DeleteTarget failed: %v", err) + } + }) + + t.Run("Test CreateToken", func(t *testing.T) { + mockResponse := ` +{ + "$id": "bb8ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c168bb8", + "secret": "string", + "expire": "2020-10-15T06:38:00.000+00:00", + "phrase": "Golden Fox" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateToken("") + if err != nil { + t.Errorf("Method CreateToken failed: %v", err) + } + }) + + t.Run("Test UpdateEmailVerification", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateEmailVerification("", true) + if err != nil { + t.Errorf("Method UpdateEmailVerification failed: %v", err) + } + }) + + t.Run("Test UpdatePhoneVerification", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": { + }, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Apple iPhone 12", + "userId": "259125845563242502", + "providerType": "email", + "identifier": "token", + "expired": true + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePhoneVerification("", true) + if err != nil { + t.Errorf("Method UpdatePhoneVerification failed: %v", err) + } + }) +} diff --git a/webhooks/webhooks.go b/webhooks/webhooks.go index d36bd35f..0f3ddc9a 100644 --- a/webhooks/webhooks.go +++ b/webhooks/webhooks.go @@ -3,8 +3,8 @@ package webhooks import ( "encoding/json" "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/v2/client" + "github.com/appwrite/sdk-for-go/v2/models" "strings" ) diff --git a/webhooks/webhooks_test.go b/webhooks/webhooks_test.go new file mode 100644 index 00000000..e0a48a98 --- /dev/null +++ b/webhooks/webhooks_test.go @@ -0,0 +1,239 @@ +package webhooks + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v2/client" +) + +func TestWebhooks(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test List", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "security": true, + "httpUser": "username", + "httpPass": "password", + "signatureKey": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.List() + if err != nil { + t.Errorf("Method List failed: %v", err) + } + }) + + t.Run("Test Create", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "security": true, + "httpUser": "username", + "httpPass": "password", + "signatureKey": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Create("", "", "", []string{}) + if err != nil { + t.Errorf("Method Create failed: %v", err) + } + }) + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "security": true, + "httpUser": "username", + "httpPass": "password", + "signatureKey": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get("") + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test Update", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "security": true, + "httpUser": "username", + "httpPass": "password", + "signatureKey": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Update("", "", "", []string{}) + if err != nil { + t.Errorf("Method Update failed: %v", err) + } + }) + + t.Run("Test Delete", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Delete("") + if err != nil { + t.Errorf("Method Delete failed: %v", err) + } + }) + + t.Run("Test UpdateSignature", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "security": true, + "httpUser": "username", + "httpPass": "password", + "signatureKey": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSignature("") + if err != nil { + t.Errorf("Method UpdateSignature failed: %v", err) + } + }) +}