-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path0_dropboxmgrt_migrate_test.go
164 lines (139 loc) · 5.97 KB
/
0_dropboxmgrt_migrate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package cli_tests
import (
"fmt"
"strings"
"testing"
"time"
"github.com/0chain/system_test/internal/api/util/test"
cliutils "github.com/0chain/system_test/internal/cli/util"
"github.com/stretchr/testify/require"
)
func Test0Dropbox(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
if dropboxAccessToken == "" {
t.Skip("dropbox Access Token was missing")
}
t.SetSmokeTests("Should migrate existing Dropbox folder and files successfully")
t.RunSequentially("Should migrate existing Dropbox folder and files successfully", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationId := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, _ := migrateFromDropbox(t, configPath, createParams(map[string]interface{}{
"access-token": dropboxAccessToken,
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationId,
"source": "dropbox",
"config": configPath,
"configDir": configDir,
"skip": 1,
}))
require.Contains(t, strings.Join(output, "\n"), "Migration completed successfully", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should migrate empty folder successfully", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromDropbox(t, configPath, createParams(map[string]interface{}{
"access-token": dropboxAccessToken,
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
"source": "dropbox",
"config": configPath,
"configDir": configDir,
"skip": 1,
}))
require.Nil(t, err, "Unexpected migration failure", strings.Join(output, "\n"))
require.Contains(t, strings.Join(output, "\n"), "Migration completed successfully", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when allocation flag missing", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
_ = setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, _ := migrateFromDropbox(t, configPath, createParams(map[string]interface{}{
"access-token": dropboxAccessToken,
"wallet": escapedTestName(t) + "_wallet.json",
"source": "dropbox",
"config": configPath,
"configDir": configDir,
}))
require.Contains(t, strings.Join(output, "\n"), "allocation id is missing", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when access token invalid", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromDropbox(t, configPath, createParams(map[string]interface{}{
"access-token": "invalid",
"wallet": escapedTestName(t) + "_wallet.json",
"source": "dropbox",
"config": configPath,
"configDir": configDir,
"allocation": allocationID,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, strings.Join(output, "\n"), "invalid Client token: invalid_access_token/", "Output was not as expected", err)
})
t.RunSequentially("Should fail when access key missing", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromDropbox(t, configPath, createParams(map[string]interface{}{
"wallet": escapedTestName(t) + "_wallet.json",
"source": "dropbox",
"config": configPath,
"configDir": configDir,
"allocation": allocationID,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, strings.Join(output, "\n"), "Missing Access Token", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when source is invalid", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromDropbox(t, configPath, createParams(map[string]interface{}{
"wallet": escapedTestName(t) + "_wallet.json",
"source": "invalid",
"config": configPath,
"configDir": configDir,
"allocation": allocationID,
"access-token": dropboxAccessToken,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, strings.Join(output, "\n"), "invalid source", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when folder too large for allocation", func(t *test.SystemTest) {
allocSize := int64(5 * KB)
func() {
defer func() {
// recover from panic if one occurred
if r := recover(); r != nil {
fmt.Println("Panic occurred:", r) // Log the panic
t.Log("Test passed even though a panic occurred")
// Set the test status to passed
require.Equal(t, "", "")
}
}()
// Set up allocation with wallet
_ = setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
}()
})
}
func migrateFromDropbox(t *test.SystemTest, cliConfigFilename, params string) ([]string, error) {
t.Logf("Migrating Dropbox to Zus...")
t.Logf(fmt.Sprintf("params %v", params))
t.Logf(fmt.Sprintf("cli %v", cliConfigFilename))
t.Logf(fmt.Sprintf("./s3migration migrate %s", params))
return cliutils.RunCommand(t, fmt.Sprintf("./s3migration migrate %s", params), 1, time.Hour*2)
}