forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql_test.go
63 lines (51 loc) · 1.4 KB
/
mysql_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
// +build deprecated
package datastore
import (
"database/sql"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"www.velocidex.com/golang/velociraptor/config"
)
type MysqlTestSuite struct {
BaseTestSuite
}
func (self *MysqlTestSuite) SetupTest() {
// Drop the database to start a new test.
conn_string := fmt.Sprintf("%s:%s@tcp(%s)/",
self.config_obj.Datastore.MysqlUsername,
self.config_obj.Datastore.MysqlPassword,
self.config_obj.Datastore.MysqlServer)
db, err := sql.Open("mysql", conn_string)
assert.NoError(self.T(), err)
_, err = db.Exec(fmt.Sprintf("drop database if exists `%v`",
self.config_obj.Datastore.MysqlDatabase))
if err != nil {
self.T().Skipf("Unable to contact mysql - skipping: %v", err)
return
}
defer db.Close()
_, err = initializeDatabase(self.config_obj)
assert.NoError(self.T(), err)
self.datastore, err = NewMySQLDataStore(self.config_obj)
assert.NoError(self.T(), err)
}
func (self *MysqlTestSuite) TearDownTest() {
if self.datastore != nil {
self.datastore.Close()
}
}
func TestMysqlDatabase(t *testing.T) {
// If a local testing mysql server is configured we can run
// this test, otherwise skip it.
config_obj, err := new(config.Loader).WithFileLoader(
"test_data/mysql.config.yaml").
LoadAndValidate()
if err != nil {
return
}
suite.Run(t, &MysqlTestSuite{BaseTestSuite{
config_obj: config_obj,
}})
}