-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclient3_test.go
187 lines (156 loc) · 3.88 KB
/
client3_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
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
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 dbb3 db.Database
var odbb3 odb.Oauth2DB
var cid3 int64
var cid23 int64
func TestMySQLDB3_Connect(t *testing.T) {
//var db db.Database
var mydb mdb.MyDBMock
mydb.Host = "localhost:3306"
mydb.User = "admin"
mydb.Password = "admin"
mydb.Database = "ulbora_oauth2_server"
var mTestRow db.DbRow
mTestRow.Row = []string{"e"}
mydb.MockTestRow = &mTestRow
mydb.MockInsertSuccess1 = true
mydb.MockInsertID1 = 2
mydb.MockInsertSuccess2 = true
mydb.MockInsertID2 = 4
mydb.MockInsertSuccess3 = true
mydb.MockInsertID3 = 4
mydb.MockInsertSuccess4 = false
mydb.MockInsertID4 = 4
mydb.MockUpdateSuccess1 = true
var mGetRow db.DbRow
mGetRow.Row = []string{"1", "1235", "tester5", "some site", "some email", "true", "false"}
mydb.MockRow1 = &mGetRow
var rows [][]string
row1 := []string{"1", "1235", "tester5", "some site", "some email", "true", "false"}
rows = append(rows, row1)
var dbrows db.DbRows
dbrows.Rows = rows
mydb.MockRows1 = &dbrows
mydb.MockRows2 = &dbrows
//mGetRows.Rows[0] = []string{"1", "1235", "tester5", "some site", "some email", "true", "false"}
mydb.MockDeleteSuccess1 = true
mydb.MockDeleteSuccess2 = false
mydb.MockDeleteSuccess3 = false
mydb.MockDeleteSuccess4 = true
dbb3 = &mydb
var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbb3
odbb3 = &moadb
dbb3.Connect()
}
// func TestMySQLDB_AddClientNullUri(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 := odbb.AddClient(&c, nil)
// fmt.Println("res: ", res)
// fmt.Println("id: ", id)
// if res || id == 0 {
// t.Fail()
// } else {
// cid = id
// }
// }
// func TestMySQLDB3_AddClient(t *testing.T) {
// var c odb.Client
// c.Secret = "1234567"
// c.Name = "tester"
// c.Email = "[email protected]"
// c.WebSite = "www.bob.com"
// c.Enabled = true
// c.Paid = false
// var uis []odb.ClientRedirectURI
// var u1 odb.ClientRedirectURI
// u1.URI = "addSomething"
// uis = append(uis, u1)
// var u2 odb.ClientRedirectURI
// u2.URI = "addSomething2"
// uis = append(uis, u2)
// fmt.Println("before db add")
// res, id := odbb_2.AddClient(&c, &uis)
// cid_2 = id
// fmt.Println("res: ", res)
// fmt.Println("id: ", id)
// if !res || id == 0 {
// t.Fail()
// }
// }
// func TestMySQLDB_UpdateClient(t *testing.T) {
// var c odb.Client
// c.Secret = "555555"
// c.Name = "tester5"
// c.Email = "[email protected]"
// c.WebSite = "www.bob.com"
// c.Enabled = false
// c.Paid = false
// c.ClientID = cid
// suc := odbb.UpdateClient(&c)
// if !suc {
// t.Fail()
// }
// }
// func TestMySQLDB_GetClient(t *testing.T) {
// c := odbb.GetClient(cid)
// fmt.Println("client found: ", c)
// if c.Name != "tester5" {
// t.Fail()
// }
// }
// func TestMySQLDB_GetClients(t *testing.T) {
// cs := odbb.GetClients()
// fmt.Println("client found: ", cs)
// for _, c := range *cs {
// fmt.Println("client found in getClients: ", c)
// }
// if len(*cs) == 0 {
// t.Fail()
// }
// }
// func TestMySQLDB_SearchClients(t *testing.T) {
// cs := odbb.SearchClients("tester")
// fmt.Println("client found in search: ", cs)
// for _, c := range *cs {
// fmt.Println("client found in searchClients: ", c)
// }
// if len(*cs) == 0 {
// t.Fail()
// }
// }
func TestMySQLDB3_DeleteClient(t *testing.T) {
suc := odbb3.DeleteClient(cid3)
if suc {
t.Fail()
}
}
// func TestMySQLDB2_DeleteClient2(t *testing.T) {
// suc := odbb_2.DeleteClient(cid_2)
// if suc {
// t.Fail()
// }
// }
// func TestMySQLDB_DeleteClient2(t *testing.T) {
// suc := odbb.DeleteClient(cid2)
// if !suc {
// t.Fail()
// }
// }