-
Notifications
You must be signed in to change notification settings - Fork 42
/
basic_test.go
101 lines (84 loc) · 2.72 KB
/
basic_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
package upx
import (
"fmt"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoginAndLogout(t *testing.T) {
b, err := Upx("login", BUCKET_1, USERNAME, PASSWORD)
assert.NoError(t, err)
assert.Equal(t, string(b), fmt.Sprintf("Welcome to %s, %s!\n", BUCKET_1, USERNAME))
b, err = Upx("login", BUCKET_2, USERNAME, PASSWORD)
assert.NoError(t, err)
assert.Equal(t, string(b), fmt.Sprintf("Welcome to %s, %s!\n", BUCKET_2, USERNAME))
b, err = Upx("logout")
assert.NoError(t, err)
assert.Equal(t, string(b), fmt.Sprintf("Goodbye %s/%s ~~\n", USERNAME, BUCKET_2))
b, err = Upx("logout")
assert.NoError(t, err)
assert.Equal(t, string(b), fmt.Sprintf("Goodbye %s/%s ~~\n", USERNAME, BUCKET_1))
}
func TestGetInfo(t *testing.T) {
SetUp()
defer TearDown()
pwd, _ := Upx("pwd")
b, err := Upx("info")
assert.NoError(t, err)
s := []string{
"ServiceName: " + BUCKET_1,
"Operator: " + USERNAME,
"CurrentDir: " + strings.TrimRight(string(pwd), "\n"),
"Usage: ",
}
assert.Equal(t, strings.HasPrefix(string(b), strings.Join(s, "\n")), true)
}
func TestSessionsAndSwitch(t *testing.T) {
SetUp()
defer TearDown()
b, err := Upx("sessions")
assert.NoError(t, err)
assert.Equal(t, string(b), fmt.Sprintf("> %s\n", BUCKET_1))
Upx("login", BUCKET_2, USERNAME, PASSWORD)
b, err = Upx("sessions")
assert.NoError(t, err)
assert.Equal(t, string(b), fmt.Sprintf(" %s\n> %s\n", BUCKET_1, BUCKET_2))
Upx("switch", BUCKET_1)
b, err = Upx("sessions")
assert.NoError(t, err)
assert.Equal(t, string(b), fmt.Sprintf("> %s\n %s\n", BUCKET_1, BUCKET_2))
pwd, _ := Upx("pwd")
b, err = Upx("info")
assert.NoError(t, err)
s := []string{
"ServiceName: " + BUCKET_1,
"Operator: " + USERNAME,
"CurrentDir: " + strings.TrimRight(string(pwd), "\n"),
"Usage: ",
}
assert.Equal(t, strings.HasPrefix(string(b), strings.Join(s, "\n")), true)
}
// TODO
func TestAuth(t *testing.T) {
}
func TestPurge(t *testing.T) {
SetUp()
defer TearDown()
b, err := Upx("purge", fmt.Sprintf("http://%s.b0.upaiyun.com/test.jpg", BUCKET_1))
assert.NoError(t, err)
assert.Equal(t, len(b), 0)
_, err = Upx("purge", "http://www.baidu.com")
if !assert.Error(t, err) {
assert.Fail(t, "purge not has return error")
}
assert.Equal(t, err.Error(), "Purge failed urls:\nhttp://www.baidu.com\ntoo many fails\n")
fd, _ := os.Create("list")
fd.WriteString(fmt.Sprintf("http://%s.b0.upaiyun.com/test.jpg\n", BUCKET_1))
fd.WriteString(fmt.Sprintf("http://%s.b0.upaiyun.com/测试.jpg\n", BUCKET_1))
fd.WriteString(fmt.Sprintf("http://%s.b0.upaiyun.com/%%E5%%8F%%88%%E6%%8B%%8D%%E4%%BA%%91.jpg\n", BUCKET_1))
fd.Close()
b, err = Upx("purge", "--list", "list")
assert.NoError(t, err)
assert.Equal(t, len(b), 0)
}