forked from aerospike/aerospike-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaerospike_suite_test.go
117 lines (95 loc) · 2.89 KB
/
aerospike_suite_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
package aerospike_test
import (
"bytes"
"flag"
"log"
"math/rand"
"os"
"strings"
"testing"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
as "github.com/aerospike/aerospike-client-go"
asl "github.com/aerospike/aerospike-client-go/logger"
)
var host = flag.String("h", "127.0.0.1", "Aerospike server seed hostnames or IP addresses")
var port = flag.Int("p", 3000, "Aerospike server seed hostname or IP address port number.")
var user = flag.String("U", "", "Username.")
var password = flag.String("P", "", "Password.")
var authMode = flag.String("A", "internal", "Authentication mode: internal | external")
var clientPolicy *as.ClientPolicy
var client *as.Client
var useReplicas = flag.Bool("use-replicas", false, "Aerospike will use replicas as well as master partitions.")
var debug = flag.Bool("debug", false, "Will set the logging level to DEBUG.")
var namespace = flag.String("n", "test", "Namespace")
func initTestVars() {
rand.Seed(time.Now().UnixNano())
flag.Parse()
var buf bytes.Buffer
logger := log.New(&buf, "", log.LstdFlags|log.Lshortfile)
logger.SetOutput(os.Stdout)
asl.Logger.SetLogger(logger)
if *debug {
asl.Logger.SetLevel(asl.DEBUG)
}
clientPolicy = as.NewClientPolicy()
if *user != "" {
clientPolicy.User = *user
clientPolicy.Password = *password
}
clientPolicy.RequestProleReplicas = *useReplicas
*authMode = strings.ToLower(strings.TrimSpace(*authMode))
if *authMode != "internal" && *authMode != "external" {
log.Fatalln("Invalid auth mode: only `internal` and `external` values are accepted.")
}
if *authMode == "external" {
clientPolicy.AuthMode = as.AuthModeExternal
}
if client == nil || !client.IsConnected() {
client, err = as.NewClientWithPolicy(clientPolicy, *host, *port)
if err != nil {
log.Fatal(err.Error())
}
// set default policies
if *useReplicas {
client.DefaultPolicy.ReplicaPolicy = as.MASTER_PROLES
}
}
}
func TestAerospike(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Aerospike Client Library Suite")
}
func featureEnabled(feature string) bool {
node := client.GetNodes()[0]
infoMap, err := node.RequestInfo("features")
if err != nil {
log.Fatal("Failed to connect to aerospike: err:", err)
}
return strings.Contains(infoMap["features"], feature)
}
func nsInfo(ns string, feature string) string {
node := client.GetNodes()[0]
infoMap, err := node.RequestInfo("namespace/" + ns)
if err != nil {
log.Fatal("Failed to connect to aerospike: err:", err)
}
infoStr := infoMap["namespace/"+ns]
infoPairs := strings.Split(infoStr, ";")
for _, pairs := range infoPairs {
pair := strings.Split(pairs, "=")
if pair[0] == feature {
return pair[1]
}
}
return ""
}
func info(client *as.Client, feature string) string {
node := client.GetNodes()[0]
infoMap, err := node.RequestInfo(feature)
if err != nil {
log.Fatal("Failed to connect to aerospike: err:", err)
}
return infoMap[feature]
}