-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathallowedUri_integration_test.go
116 lines (100 loc) · 2.42 KB
/
allowedUri_integration_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
// +build integration move to top
package mysqldb
import (
"fmt"
"testing"
odb "github.com/Ulbora/GoAuth2/oauth2database"
lg "github.com/Ulbora/Level_Logger"
db "github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/dbinterface_mysql"
)
var dbAui db.Database
var odbAui odb.Oauth2DB
var cidAui int64
var idAui int64
func TestMySQLOauthDBi_ConnectAllowURI(t *testing.T) {
var mydb mdb.MyDB
mydb.Host = "localhost:3306"
mydb.User = "admin"
mydb.Password = "admin"
mydb.Database = "ulbora_oauth2_server"
dbAui = &mydb
var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbAui
odbAui = &moadb
dbAui.Connect()
}
func TestMySQLOauthDBi_AddClientInAlowedUri(t *testing.T) {
var c odb.Client
c.Secret = "12345"
c.Name = "tester"
c.Email = "[email protected]"
c.WebSite = "www.bob.com"
c.Enabled = true
c.Paid = false
fmt.Println("before db add")
res, id := odbAui.AddClient(&c, nil)
fmt.Println("res: ", res)
fmt.Println("id: ", id)
if !res || id == 0 {
t.Fail()
} else {
cidAui = id
}
}
func TestMySQLOauthDBi_AddClientAllowedURI(t *testing.T) {
var ur odb.ClientAllowedURI
ur.ClientID = cidAui
ur.URI = "someuri"
res, id := odbAui.AddClientAllowedURI(&ur)
if !res || id <= 0 {
t.Fail()
} else {
idAui = id
}
}
func TestMySQLOauthDBi_UpdateClientAllowedURI(t *testing.T) {
var ur odb.ClientAllowedURI
ur.ID = idAui
ur.URI = "someuri2"
res := odbAui.UpdateClientAllowedURI(&ur)
if !res {
t.Fail()
}
}
func TestMySQLOauthDBi_GetClientAllowedURIByID(t *testing.T) {
res := odbAui.GetClientAllowedURIByID(idAui)
fmt.Println("allowed uri res by id: ", res)
if res == nil || (*res).ClientID != cidAui || (*res).URI != "someuri2" {
t.Fail()
}
}
func TestMySQLOauthDBi_GetClientAllowedURIList(t *testing.T) {
res := odbAui.GetClientAllowedURIList(cidAui)
fmt.Println("allowed uri list res: ", res)
if res == nil || (*res)[0].ClientID != cidAui {
t.Fail()
}
}
func TestMySQLOauthDBi_GetClientAllowedURI(t *testing.T) {
res := odbAui.GetClientAllowedURI(cidAui, "someuri2")
fmt.Println("allowed uri res: ", res)
if res == nil || (*res).ClientID != cidAui || (*res).URI != "someuri2" {
t.Fail()
}
}
func TestMySQLOauthDBi_DeleteClientAllowedURI(t *testing.T) {
res := odbAui.DeleteClientAllowedURI(idAui)
fmt.Println("allowed uri delete: ", res)
if !res {
t.Fail()
}
}
func TestMySQLOauthDBi_DeleteClientInAllowedURI(t *testing.T) {
suc := odbAui.DeleteClient(cidAui)
if !suc {
t.Fail()
}
}