-
Notifications
You must be signed in to change notification settings - Fork 360
/
testing.go
105 lines (87 loc) · 2.18 KB
/
testing.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
package resources
import (
"fmt"
"os"
"strings"
"testing"
"github.com/activecm/mgorus"
"github.com/activecm/rita/config"
"github.com/activecm/rita/database"
)
//InitIntegrationTestingResources creates a default testing
//resource bundle for use with integration testing.
//The MongoDB server is contacted via the URI provided
//as by go test -args [MongoDB URI].
func InitIntegrationTestingResources(t *testing.T) *Resources {
if testing.Short() {
t.Skip()
}
mongoURI := os.Args[len(os.Args)-1]
if !strings.Contains(mongoURI, "mongodb://") {
t.Fatal("-args [MongoDB URI] is required to run RITA integration tests with go test")
}
conf, err := config.LoadTestingConfig(mongoURI)
if err != nil {
t.Fatal(err)
}
// Fire up the logging system
log := initLogger(&conf.S.Log)
// Allows code to interact with the database
db, err := database.NewDB(conf, log)
if err != nil {
t.Fatal(err)
}
// Allows code to create and remove tracked databases
metaDB := database.NewMetaDB(conf, db.Session, log)
//Begin logging to the metadatabase
if conf.S.Log.LogToDB {
log.Hooks.Add(
mgorus.NewHookerFromSession(
db.Session, conf.S.Bro.MetaDB, conf.T.Log.RitaLogTable,
),
)
}
//bundle up the system resources
r := &Resources{
Config: conf,
Log: log,
DB: db,
MetaDB: metaDB,
}
return r
}
//InitTestResources creates a default testing
//resource bundle for use with integration testing.
func InitTestResources() *Resources {
conf, err := config.LoadTestingConfig("mongodb://localhost:27017")
if err != nil {
fmt.Println(err)
return nil
}
// Fire up the logging system
log := initLogger(&conf.S.Log)
// Allows code to interact with the database
db, err := database.NewDB(conf, log)
if err != nil {
fmt.Println(err)
return nil
}
// Allows code to create and remove tracked databases
metaDB := database.NewMetaDB(conf, db.Session, log)
//Begin logging to the metadatabase
if conf.S.Log.LogToDB {
log.Hooks.Add(
mgorus.NewHookerFromSession(
db.Session, conf.S.Bro.MetaDB, conf.T.Log.RitaLogTable,
),
)
}
//bundle up the system resources
r := &Resources{
Config: conf,
Log: log,
DB: db,
MetaDB: metaDB,
}
return r
}