-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmysql_meta_store_test.go
140 lines (112 loc) · 3.42 KB
/
mysql_meta_store_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
package main
import (
"errors"
"fmt"
"testing"
)
var (
metaStoreTestMySQL *MySQLMetaStore
)
func TestMySQLConfiguration(t *testing.T) {
Config.MySQL = &MySQLConfig{
Enabled: true,
Host: "127.0.0.1:3306",
Database: "lfs_server_go_test",
}
mysqlStore, err := NewMySQLMetaStore()
if mysqlStore != nil {
t.Errorf("expected MySQL configration validation error, got : %s", err)
}
}
func TestMySQLAddProjects(t *testing.T) {
serr := setupMySQLMeta()
if serr != nil {
t.Errorf(serr.Error())
}
err := metaStoreTestMySQL.AddProject(testRepo)
if err != nil {
metaStoreTestMySQL.Close()
t.Errorf("expected AddProject to succeed, got : %s", err)
}
}
func TestMySQLPutWithAuth(t *testing.T) {
meta, err := metaStoreTestMySQL.Put(&RequestVars{Authorization: testAuth, Oid: contentOid, Size: 42, Repo: testRepo})
if err != nil {
metaStoreTestMySQL.Close()
t.Errorf("expected put to succeed, got : %s", err)
}
if meta.Existing {
metaStoreTestMySQL.Close()
t.Errorf("expected meta to not have existed")
}
meta, err = metaStoreTestMySQL.Get(&RequestVars{Authorization: testAuth, Oid: contentOid})
if err != nil {
metaStoreTestMySQL.Close()
t.Errorf("expected to be able to retreive new put, got : %s", err)
}
if meta.Oid != contentOid {
metaStoreTestMySQL.Close()
t.Errorf("expected oids to match, got: %s", meta.Oid)
}
if meta.Size != 42 {
metaStoreTestMySQL.Close()
t.Errorf("expected sizes to match, got: %d", meta.Size)
}
}
func TestMySQLPutWithoutAuth(t *testing.T) {
_, err := metaStoreTestMySQL.Put(&RequestVars{Authorization: badAuth, User: testUser, Oid: contentOid, Size: 42, Repo: testRepo})
if !isAuthError(err) {
metaStoreTestMySQL.Close()
t.Errorf("expected auth error, got: %s", err)
}
}
func TestMySQLGetWithAuth(t *testing.T) {
metaFail, err := metaStoreTestMySQL.Get(&RequestVars{Authorization: testAuth, Oid: noAuthOid})
if err == nil {
metaStoreTestMySQL.Close()
t.Fatalf("Error Should not have access to OID: %s", metaFail.Oid)
}
meta, err := metaStoreTestMySQL.Get(&RequestVars{Authorization: testAuth, Oid: contentOid})
if err != nil {
metaStoreTestMySQL.Close()
t.Fatalf("Error retreiving meta: %s", err)
}
if meta.Oid != contentOid {
metaStoreTestMySQL.Close()
t.Errorf("expected to get content oid, got: %s", meta.Oid)
}
if meta.Size != 42 {
metaStoreTestMySQL.Close()
t.Errorf("expected to get content size, got: %d", meta.Size)
}
}
func TestMySQLGetWithoutAuth(t *testing.T) {
_, err := metaStoreTestMySQL.Get(&RequestVars{Authorization: badAuth, Oid: noAuthOid})
if !isAuthError(err) {
metaStoreTestMySQL.Close()
t.Errorf("expected auth error, got: %s", err)
}
}
func setupMySQLMeta() error {
// Setup Config
Config.Ldap = &LdapConfig{Enabled: true, Server: "ldap://localhost:1389", Base: "o=company",
UserObjectClass: "posixaccount", UserCn: "uid", BindPass: "admin"}
Config.MySQL = &MySQLConfig{
Enabled: true,
Host: "127.0.0.1:3306",
Username: "lfs_server",
Password: "pass123",
Database: "lfs_server_go",
}
mysqlStore, err := NewMySQLMetaStore()
if err != nil {
fmt.Printf("error initializing test meta store: %s\n", err)
return errors.New(fmt.Sprintf("error initializing test meta store: %s\n", err))
}
metaStoreTestMySQL = mysqlStore
// Clean up any test
mysqlStore.client.Exec("TRUNCATE TABLE oid_maps")
mysqlStore.client.Exec("TRUNCATE TABLE oids")
mysqlStore.client.Exec("TRUNCATE TABLE projects")
return nil
}