-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathallowedUri_test.go
112 lines (93 loc) · 2.34 KB
/
allowedUri_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
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 dbAu db.Database
var odbAu odb.Oauth2DB
var cidAu int64
var idAu int64
func TestMySQLOauthDB_ConnectAllowURI(t *testing.T) {
var mydb mdb.MyDBMock
mydb.Host = "localhost:3306"
mydb.User = "admin"
mydb.Password = "admin"
mydb.Database = "ulbora_oauth2_server"
dbAu = &mydb
var mTestRow db.DbRow
mTestRow.Row = []string{}
mydb.MockTestRow = &mTestRow
mydb.MockInsertSuccess1 = true
mydb.MockInsertID1 = 1
mydb.MockUpdateSuccess1 = true
var getRow db.DbRow
getRow.Row = []string{"1", "someuri2", "2"}
mydb.MockRow1 = &getRow
mydb.MockRow2 = &getRow
var rows [][]string
row1 := []string{"1", "tester5", "2"}
rows = append(rows, row1)
var dbrows db.DbRows
dbrows.Rows = rows
mydb.MockRows1 = &dbrows
mydb.MockDeleteSuccess1 = true
var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbAu
odbAu = &moadb
dbAu.Connect()
}
func TestMySQLOauthDB_AddClientAllowedURI(t *testing.T) {
cidAu = 2
var ur odb.ClientAllowedURI
ur.ClientID = cidAu
ur.URI = "someuri"
res, id := odbAu.AddClientAllowedURI(&ur)
if !res || id <= 0 {
t.Fail()
} else {
idAu = id
}
}
func TestMySQLOauthDB_UpdateClientAllowedURI(t *testing.T) {
var ur odb.ClientAllowedURI
ur.ID = idAu
ur.URI = "someuri2"
res := odbAu.UpdateClientAllowedURI(&ur)
if !res {
t.Fail()
}
}
func TestMySQLOauthDB_GetClientAllowedURIByID(t *testing.T) {
res := odbAu.GetClientAllowedURIByID(idAu)
fmt.Println("allowed uri res by id: ", res)
if res == nil || (*res).ClientID != cidAu || (*res).URI != "someuri2" {
t.Fail()
}
}
func TestMySQLOauthDB_GetClientAllowedURIList(t *testing.T) {
res := odbAu.GetClientAllowedURIList(cidAu)
fmt.Println("allowed uri list res: ", res)
if res == nil || (*res)[0].ClientID != cidAu {
t.Fail()
}
}
func TestMySQLOauthDB_GetClientAllowedURI(t *testing.T) {
res := odbAu.GetClientAllowedURI(cidAu, "someuri2")
fmt.Println("allowed uri res: ", res)
if res == nil || (*res).ClientID != cidAu || (*res).URI != "someuri2" {
t.Fail()
}
}
func TestMySQLOauthDB_DeleteClientAllowedURI(t *testing.T) {
res := odbAu.DeleteClientAllowedURI(idAu)
fmt.Println("allowed uri delete: ", res)
if !res {
t.Fail()
}
}