-
Notifications
You must be signed in to change notification settings - Fork 2
/
common_test.go
86 lines (77 loc) · 1.83 KB
/
common_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
package neugo
import (
"flag"
"github.com/stretchr/testify/assert"
"net/http"
"strings"
"testing"
)
func TestUse(t *testing.T) {
a := assert.New(t)
session := NewSession()
s1 := Use(session).WithAuth("test", "test")
ctx, ok := s1.(*useCtx)
a.True(ok)
a.Equal("test", ctx.Username)
a.Equal("test", ctx.Password)
emptyClient := &http.Client{}
s2 := Use(emptyClient).WithToken("test")
ctx, ok = s2.(*useCtx)
a.True(ok)
a.NotNil(ctx.Client.Jar)
a.Equal("test", ctx.Token)
a.Equal(true, ctx.UseToken)
s3 := Use(session)
s3.WithToken("test")
s3.WithAuth("test", "test")
ctx, ok = s3.(*useCtx)
a.True(ok)
a.Equal(false, ctx.UseToken)
a.Equal("test", ctx.Username)
a.Equal("test", ctx.Password)
}
func TestAll(t *testing.T) {
a := assert.New(t)
session := NewSession()
if !flag.Parsed() {
flag.Parse()
}
argList := flag.Args()
if len(argList) < 2 {
a.Fail("should provide account to continue tests.")
return
}
username := argList[0]
password := argList[1]
err := Use(session).WithAuth(username, password).Login(CAS)
if err != nil && strings.Contains(err.Error(), "timeout") {
a.Nil(err)
}
err = Use(session).WithAuth(username, password).Login(WebVPN)
if err != nil && strings.Contains(err.Error(), "timeout") {
a.Nil(err)
}
_, err = Use(session).WithAuth(username, password).DebugLogin(CAS)
if err != nil && strings.Contains(err.Error(), "timeout") {
a.Nil(err)
}
// about
{
token := About(session).Token(CAS)
a.NotEmpty(token)
session := NewSession()
err = Use(session).WithToken(token).Login(CAS)
if err != nil && strings.Contains(err.Error(), "timeout") {
a.Nil(err)
}
}
{
token := About(session).Token(WebVPN)
a.NotEmpty(token)
session := NewSession()
err = Use(session).WithToken(token).Login(WebVPN)
if err != nil && strings.Contains(err.Error(), "timeout") {
a.Nil(err)
}
}
}