-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_testscript.sh
executable file
·196 lines (173 loc) · 7.88 KB
/
upload_testscript.sh
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
estatus=0
cmdPath='./gcscmd'
testCases() {
echo "_/_/_/_/_/_/_/_/_/_/_/_/_/ 对象上传 开始 _/_/_/_/_/_/_/_/_/_/_/_/_/"
echo '对象上传 => 上传文件-当前目录 => 在当前目录上传文件 => gcscmd put ./aaa.mp4 cs://bbb start'
echo '数据准备'
echo '1、创建新桶'
bucketName="bucket-upload-"$(date "+%Y%m%d%H%M%S")"-"$RANDOM
$cmdPath mb cs://$bucketName
echo '2、添加对象,10MB'
testDataFileName="testdata_"$(date "+%Y%m%d%H%M%S")"-"$RANDOM".dat"
#echo $testDataFileName
dd if=/dev/urandom of=$testDataFileName bs=10240 count=1024
# 设置当前目录
dataPath=''$testDataFileName
execCmd '对象上传' '上传文件-当前目录' '在当前目录上传文件' 'gcscmd put '$dataPath' cs://'$bucketName 'put '$dataPath' cs://'$bucketName ''
echo '3、数据清理'
rm -rf $testDataFileName
echo '对象上传 => 上传文件-当前目录 => 在当前目录上传文件 => gcscmd put ./aaa.mp4 cs://bbb end'
echo ''
echo '对象上传 => 上传文件-当前目录 => 绝对路径上传文件 => gcscmd put /home/pz/aaa.mp4 cs://bbb start'
echo '数据准备'
echo '1、添加对象,10MB'
testDataFileName="testdata_"$(date "+%Y%m%d%H%M%S")"-"$RANDOM".dat"
#echo $testDataFileName
# 设置绝对路径
dataPath=$(pwd)'/'$testDataFileName
dd if=/dev/urandom of=$dataPath bs=10240 count=1024
execCmd '对象上传' '上传文件-当前目录' '绝对路径上传文件' 'gcscmd put '$dataPath' cs://'$bucketName 'put '$dataPath' cs://'$bucketName ''
echo '2、数据清理'
rm -rf $dataPath
echo '对象上传 => 上传文件-当前目录 => 绝对路径上传文件 => gcscmd put /home/pz/aaa.mp4 cs://bbb end'
echo ''
echo '对象上传 => 上传文件-当前目录 => 相对路径上传文件 => gcscmd put ../pz/aaa.mp4 cs://bbb start'
echo '数据准备'
echo '1、添加对象,10MB'
testDataFileName="testdata_"$(date "+%Y%m%d%H%M%S")"-"$RANDOM".dat"
#echo $testDataFileName
# 设置相对路径
dataPath='tmp/'$testDataFileName
dd if=/dev/urandom of=$dataPath bs=10240 count=1024
execCmd '对象上传' '上传文件-当前目录' '相对路径上传文件' 'gcscmd put '$dataPath' cs://'$bucketName 'put '$dataPath' cs://'$bucketName ''
echo '2、数据清理'
rm -rf $dataPath
echo '对象上传 => 上传文件-当前目录 => 相对路径上传文件 => gcscmd put ../pz/aaa.mp4 cs://bbb end'
echo ''
echo '对象上传 => 上传文件-当前目录 => 错误上传-任意方式上传到不存在的桶 => gcscmd put ./aaa.mp4 cs://不存在的桶名 start'
echo '数据准备'
echo '1、创建新桶'
wrongBucketName="bucket-upload-"$(date "+%Y%m%d%H%M%S")"-"$RANDOM
echo '2、添加对象,10MB'
testDataFileName="testdata_"$(date "+%Y%m%d%H%M%S")"-"$RANDOM".dat"
#echo $testDataFileName
dd if=/dev/urandom of=$testDataFileName bs=10240 count=1024
# 设置当前目录
dataPath=''$testDataFileName
execCmdFail '对象上传' '上传文件-当前目录' '错误上传-任意方式上传到不存在的桶' 'gcscmd put '$dataPath' cs://'$wrongBucketName 'put '$dataPath' cs://'$wrongBucketName ''
echo '3、数据清理'
rm -rf $testDataFileName
echo '对象上传 => 上传文件-当前目录 => 错误上传-任意方式上传到不存在的桶 => gcscmd put ./aaa.mp4 cs://不存在的桶名 end'
echo ''
# 不考虑空目录的情况,若上传空目录会报错:Uploading folder is empty, or uploading data is invalid in the folder
# echo '对象上传 => 上传目录 => 正确上传目录-空目录上传 => gcscmd put ./aaaa cs://bbb start'
# echo '数据准备'
# # 1、添加目录
# testDataFolderName="testfolder_"$(date "+%Y%m%d%H%M%S")"-"$RANDOM
# #echo $testDataFolderName
# mkdir $testDataFolderName
# $cmdPath put $testDataFolderName cs://$bucketName
# # 设置对象名称
# dataPath=''$testDataFolderName
# execCmdFail '对象上传' '上传文件-当前目录' '正确上传目录-空目录上传' 'gcscmd put '$dataPath' cs://'$bucketName 'put '$dataPath' cs://'$bucketName ''
# echo '2、数据清理'
# rm -rf $dataPath
# echo '对象上传 => 上传目录 => 正确上传目录-空目录上传 => gcscmd put ./aaaa cs://bbb end'
# echo ''
echo '对象上传 => 上传目录 => 正确上传目录-目录有文件上传 => gcscmd put ./aaaa cs://bbb start'
echo '数据准备'
# 1、添加目录
testDataFolderName="testfolder_"$(date "+%Y%m%d%H%M%S")"-"$RANDOM
#echo $testDataFolderName
mkdir $testDataFolderName
# $cmdPath put $testDataFolderName cs://$bucketName
echo '2、添加对象,10MB'
testDataFileName="testdata_"$(date "+%Y%m%d%H%M%S")"-"$RANDOM".dat"
#echo $testDataFileName
# 设置相对路径
dataPath=$testDataFolderName'/'$testDataFileName
dd if=/dev/urandom of=$dataPath bs=10240 count=1024
execCmd '对象上传' '上传文件-当前目录' '正确上传目录-目录有文件上传' 'gcscmd put '$testDataFolderName' cs://'$bucketName 'put '$testDataFolderName' cs://'$bucketName ''
echo '3、数据清理'
rm -rf $testDataFolderName
echo '对象上传 => 上传目录 => 正确上传目录-目录有文件上传 => gcscmd put ./aaaa cs://bbb end'
echo ''
# 目前暂时不使用--carfile参数
# # 对象上传 => 上传carfile => 正确上传car文件 => gcscmd put ./aaa.car cs://bbb --carfile
# echo '数据准备'
# echo '1、添加对象,10MB'
# testDataFileName="testdata_"$(date "+%Y%m%d%H%M%S")"-"$RANDOM".dat"
# #echo $testDataFileName
# dd if=/dev/urandom of=$testDataFileName bs=10240 count=1024
# # 2、生成CAR文件(测试环境需要安装car命令行程序)
# carFilename=$(echo ${testDataFileName/.dat/.car})
# car c --version 1 -f $carFilename $testDataFileName
# # 设置当前目录
# dataPath=''$carFilename
# execCmd '对象上传' '上传carfile' '正确上传car文件' 'gcscmd put '$dataPath' cs://'$bucketName' --carfile' 'put '$dataPath' cs://'$bucketName' --carfile' ''
# # echo '3、数据清理'
# # rm -rf $testDataFileName
# # rm -rf $dataPath
#
# # 对象上传 => 上传carfile => 重复上传-上传已经存在的car文件 => gcscmd put ./aaa.car cs://bbb --carfile
# execCmd '对象上传' '上传carfile' '重复上传-上传已经存在的car文件' 'gcscmd put '$dataPath' cs://'$bucketName' --carfile' 'put '$dataPath' cs://'$bucketName' --carfile' ''
# 对象上传测试数据清理
$cmdPath rb cs://$bucketName --force
# rm -rf $testDataFileName
echo "_/_/_/_/_/_/_/_/_/_/_/_/_/ 对象上传 结束 _/_/_/_/_/_/_/_/_/_/_/_/_/"
echo ''
}
execCmd() {
testModule=$1
testFunction=$2
testCase=$3
testDescription=$4
testCmd=$5
testExpectation=$6
testFail=$7
# echo $testModule"=>"$testFunction"=>"$testCase"=>"$testDescription
cmdStr=$cmdPath' '$testCmd
echo 'executing '$cmdStr
eval $cmdStr
exitCode=$?
echo ''
if [ $exitCode -eq 0 ]; then
echo -e "\033[32mSuccess: $cmdStr test pass. \033[0m"
else
echo -e "\033[31mFailure: $cmdStr test fail. \033[0m"
estatus=$(($etatus + 1))
fi
echo "exitcode:"$exitCode
echo ""
}
execCmdFail() {
testModule=$1
testFunction=$2
testCase=$3
testDescription=$4
testCmd=$5
testExpectation=$6
testFail=$7
# echo $testModule"=>"$testFunction"=>"$testCase"=>"$testDescription
cmdStr=$cmdPath' '$testCmd
echo 'executing '$cmdStr
eval $cmdStr
exitCode=$?
echo ''
if [ $exitCode -eq 0 ]; then
echo -e "\033[31mFailure: $cmdStr test should be prompt error message. \033[0m"
estatus=$(($etatus + 1))
else
echo -e "\033[32mSuccess: $cmdStr test pass, return error message and exit code is not equal zero. \033[0m"
# estatus=$?
fi
echo "exitcode:"$exitCode
echo ""
}
echo "===========================Chainstorage cli Test start=========================="
echo ''
testCases
echo "===========================Chainstorage cli Test end============================="
echo "Test status code:"$estatus
exit $estatus