-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utility.go
76 lines (54 loc) · 1.72 KB
/
test_utility.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
package main
import (
"database/sql"
"fmt"
"log"
"strconv"
"testing"
_ "github.com/lib/pq"
)
const (
DB_USER = "postgres"
DB_PASSWORD = "postgres"
DB_NAME = "test"
)
func connectToGpss() *gpssClient {
/* Reading properties from ./properties.ini */
prop, _ := ReadPropertiesFile("./properties.ini")
port, _ := strconv.Atoi(prop["GreenplumPort"])
log.Printf("Properties read: Connecting to the Grpc server specified")
/* Connect to the grpc server specified */
gpssClient := MakeGpssClient(prop["GpssAddress"], prop["GreenplumAddress"], int32(port), prop["GreenplumUser"], prop["GreenplumPassword"], prop["Database"], prop["SchemaName"], prop["TableName"])
gpssClient.ConnectToGrpcServer()
return gpssClient
}
func connectToRabbitAndSend(batch int) (string, string) {
prop, _ := ReadPropertiesFile("./properties.ini")
ch := connect(prop["rabbit"])
send(ch, prop["queue"], batch)
return prop["rabbit"], prop["queue"]
}
func connectToPostgres(t *testing.T) int {
prop, _ := ReadPropertiesFile("./properties.ini")
host := prop["GreenplumAddress"]
user := prop["GreenplumUser"]
//passwd := prop["GreenplumPassword"]
port, _ := strconv.Atoi(prop["GreenplumPort"])
dbName := prop["Database"]
tableName := prop["TableName"]
//schemaName := prop["SchemaName"]
var db *sql.DB
var err error
// Connecting to the database
dbinfo := fmt.Sprintf("host=%s port=%d user=%s "+
"dbname=%s sslmode=disable",
host, port, user, dbName)
if db, err = sql.Open("postgres", dbinfo); err != nil {
t.Errorf("Error connecting to the database")
}
count := 0
if err := db.QueryRow("SELECT count(*) from " + tableName + ";").Scan(&count); err != nil {
t.Errorf("Error querying the database %v", err)
}
return count
}