-
Notifications
You must be signed in to change notification settings - Fork 104
/
cluster_test.go
106 lines (87 loc) · 3.28 KB
/
cluster_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
package gocb
import (
"errors"
"time"
)
func (suite *IntegrationTestSuite) TestClusterWaitUntilReady() {
suite.skipIfUnsupported(WaitUntilReadyFeature)
suite.skipIfUnsupported(WaitUntilReadyClusterFeature)
c, err := Connect(globalConfig.Server, ClusterOptions{Authenticator: PasswordAuthenticator{
Username: globalConfig.User,
Password: globalConfig.Password,
}})
suite.Require().Nil(err, err)
defer c.Close(nil)
err = c.WaitUntilReady(7*time.Second, nil)
suite.Require().Nil(err, err)
// Just test that we can use the cluster.
buckets, err := c.Buckets().GetAllBuckets(nil)
suite.Require().Nil(err, err)
suite.Assert().GreaterOrEqual(len(buckets), 1)
}
func (suite *IntegrationTestSuite) TestClusterWaitUntilReadyInvalidAuth() {
suite.skipIfUnsupported(WaitUntilReadyFeature)
suite.skipIfUnsupported(WaitUntilReadyClusterFeature)
c, err := Connect(globalConfig.Server, ClusterOptions{Authenticator: PasswordAuthenticator{
Username: globalConfig.User,
Password: globalConfig.Password + "nopethisshouldntwork",
}})
suite.Require().Nil(err, err)
defer c.Close(nil)
start := time.Now()
err = c.WaitUntilReady(7*time.Second, nil)
if !errors.Is(err, ErrUnambiguousTimeout) {
suite.T().Fatalf("Expected unambiguous timeout error but was %v", err)
}
elapsed := time.Since(start)
suite.Assert().GreaterOrEqual(int64(elapsed), int64(7*time.Second))
suite.Assert().LessOrEqual(int64(elapsed), int64(8*time.Second))
}
func (suite *IntegrationTestSuite) TestClusterWaitUntilReadyFastFailAuth() {
suite.skipIfUnsupported(WaitUntilReadyFeature)
suite.skipIfUnsupported(WaitUntilReadyClusterFeature)
c, err := Connect(globalConfig.Server, ClusterOptions{Authenticator: PasswordAuthenticator{
Username: globalConfig.User,
Password: "thisisaprettyunlikelypasswordtobeused",
}})
suite.Require().Nil(err, err)
defer c.Close(nil)
err = c.WaitUntilReady(7*time.Second, &WaitUntilReadyOptions{
RetryStrategy: newFailFastRetryStrategy(),
})
if !errors.Is(err, ErrAuthenticationFailure) {
suite.T().Fatalf("Expected authentication error but was: %v", err)
}
}
func (suite *IntegrationTestSuite) TestClusterWaitUntilReadyFastFailConnStr() {
suite.skipIfUnsupported(WaitUntilReadyFeature)
suite.skipIfUnsupported(WaitUntilReadyClusterFeature)
c, err := Connect("10.10.10.10", ClusterOptions{Authenticator: PasswordAuthenticator{
Username: globalConfig.User,
Password: globalConfig.Password,
}})
suite.Require().Nil(err, err)
defer c.Close(nil)
err = c.WaitUntilReady(7*time.Second, &WaitUntilReadyOptions{
RetryStrategy: newFailFastRetryStrategy(),
})
if !errors.Is(err, ErrTimeout) {
suite.T().Fatalf("Expected timeout error but was: %v", err)
}
}
func (suite *IntegrationTestSuite) TestClusterWaitUntilReadyKeyValueService() {
suite.skipIfUnsupported(WaitUntilReadyFeature)
suite.skipIfUnsupported(WaitUntilReadyClusterFeature)
c, err := Connect(globalConfig.Server, ClusterOptions{Authenticator: PasswordAuthenticator{
Username: globalConfig.User,
Password: globalConfig.Password,
}})
suite.Require().Nil(err, err)
defer c.Close(nil)
err = c.WaitUntilReady(7*time.Second, &WaitUntilReadyOptions{
ServiceTypes: []ServiceType{ServiceTypeKeyValue},
})
if !errors.Is(err, ErrInvalidArgument) {
suite.T().Fatalf("Expected error to be invalid argument but was %v", err)
}
}