|
| 1 | +/* |
| 2 | + * -------------------------------------------------------------------------------- |
| 3 | + * <copyright company="Aspose" file="storage_test.go"> |
| 4 | + * Copyright (c) 2021 Aspose.Tasks Cloud |
| 5 | + * </copyright> |
| 6 | + * <summary> |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in all |
| 15 | + * copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | + * SOFTWARE. |
| 24 | + * </summary> |
| 25 | + * -------------------------------------------------------------------------------- |
| 26 | + */ |
| 27 | + |
| 28 | +// Example of how to work with storage. |
| 29 | +package api_test |
| 30 | + |
| 31 | +import ( |
| 32 | + "github.com/aspose-tasks-cloud/aspose-tasks-cloud-go/api/requests" |
| 33 | + "github.com/stretchr/testify/assert" |
| 34 | + "testing" |
| 35 | +) |
| 36 | + |
| 37 | +// Test for get disc usage. |
| 38 | +func Test_Storage_GetDiscUsage(t *testing.T) { |
| 39 | + config := ReadConfiguration(t) |
| 40 | + client, ctx := PrepareTest(t, config) |
| 41 | + |
| 42 | + opts := &requests.GetDiscUsageOpts{} |
| 43 | + result, response, err := client.TasksApi.GetDiscUsage(ctx, opts) |
| 44 | + if err != nil { |
| 45 | + t.Error(err) |
| 46 | + } |
| 47 | + assert.Equal(t, 200, response.StatusCode) |
| 48 | + assert.Less(t, int64(0), result.TotalSize) |
| 49 | +} |
| 50 | + |
| 51 | +// Test for get file versions. |
| 52 | +func Test_Storage_GetFileVersions(t *testing.T) { |
| 53 | + localFileName := "Home_move_plan.mpp" |
| 54 | + remoteFileName := CreateRandomGuid() + localFileName |
| 55 | + client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName) |
| 56 | + |
| 57 | + opts := &requests.GetFileVersionsOpts{ |
| 58 | + Path: remoteBaseTestDataFolder + "/" + remoteFileName, |
| 59 | + } |
| 60 | + result, response, err := client.TasksApi.GetFileVersions(ctx, opts) |
| 61 | + if err != nil { |
| 62 | + t.Error(err) |
| 63 | + } |
| 64 | + assert.Equal(t, 200, response.StatusCode) |
| 65 | + isUploadedFileFound := false |
| 66 | + for _, fv := range result.Value { |
| 67 | + if fv.Name == remoteFileName { |
| 68 | + isUploadedFileFound = true |
| 69 | + break |
| 70 | + } |
| 71 | + } |
| 72 | + assert.True(t, isUploadedFileFound) |
| 73 | + t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) }) |
| 74 | +} |
| 75 | + |
| 76 | +// Test for object exists check. |
| 77 | +func Test_Storage_ObjectExists(t *testing.T) { |
| 78 | + localFileName := "Home_move_plan.mpp" |
| 79 | + remoteFileName := CreateRandomGuid() + localFileName |
| 80 | + client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName) |
| 81 | + |
| 82 | + opts := &requests.ObjectExistsOpts{ |
| 83 | + Path: remoteBaseTestDataFolder + "/" + remoteFileName, |
| 84 | + } |
| 85 | + result, response, err := client.TasksApi.ObjectExists(ctx, opts) |
| 86 | + if err != nil { |
| 87 | + t.Error(err) |
| 88 | + } |
| 89 | + assert.Equal(t, 200, response.StatusCode) |
| 90 | + assert.True(t, result.Exists) |
| 91 | + t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) }) |
| 92 | +} |
| 93 | + |
| 94 | +// Test for storage exists check. |
| 95 | +func Test_Storage_StorageExists(t *testing.T) { |
| 96 | + config := ReadConfiguration(t) |
| 97 | + client, ctx := PrepareTest(t, config) |
| 98 | + |
| 99 | + opts := &requests.StorageExistsOpts{} |
| 100 | + |
| 101 | + result, response, err := client.TasksApi.StorageExists(ctx, opts) |
| 102 | + if err != nil { |
| 103 | + t.Error(err) |
| 104 | + } |
| 105 | + assert.Equal(t, 200, response.StatusCode) |
| 106 | + assert.True(t, result.Exists) |
| 107 | +} |
0 commit comments