-
Notifications
You must be signed in to change notification settings - Fork 104
/
bucket_test.go
123 lines (103 loc) · 3.73 KB
/
bucket_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
118
119
120
121
122
123
package gocb
import (
"errors"
"time"
)
func (suite *IntegrationTestSuite) TestBucketWaitUntilReady() {
suite.skipIfUnsupported(WaitUntilReadyFeature)
c, err := Connect(globalConfig.connstr, ClusterOptions{
Authenticator: globalConfig.Auth,
SecurityConfig: globalConfig.SecurityConfig,
})
suite.Require().Nil(err, err)
defer c.Close(nil)
b := c.Bucket(globalConfig.Bucket)
err = b.WaitUntilReady(globalCluster.waitUntilReadyTimeout(), nil)
suite.Require().Nil(err, err)
// Just test that we can use the bucket.
_, err = b.DefaultCollection().Upsert(generateDocId("TestBucketWaitUntilReady"), "test", nil)
suite.Require().Nil(err, err)
}
func (suite *IntegrationTestSuite) TestBucketWaitUntilReadyInvalidAuth() {
suite.skipIfUnsupported(WaitUntilReadyFeature)
suite.skipIfUnsupported(WaitUntilReadyAuthFailFeature)
c, err := Connect(globalConfig.connstr, ClusterOptions{
Authenticator: PasswordAuthenticator{
Username: globalConfig.User,
Password: globalConfig.Password + "nopethisshouldntwork",
},
SecurityConfig: globalConfig.SecurityConfig,
})
suite.Require().Nil(err, err)
defer c.Close(nil)
b := c.Bucket(globalConfig.Bucket)
start := time.Now()
err = b.WaitUntilReady(globalCluster.waitUntilReadyTimeout(), 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(globalCluster.waitUntilReadyTimeout()))
suite.Assert().LessOrEqual(int64(elapsed), int64(globalCluster.waitUntilReadyTimeout()+time.Second))
}
func (suite *IntegrationTestSuite) TestBucketWaitUntilReadyFastFailAuth() {
suite.skipIfUnsupported(WaitUntilReadyFeature)
suite.skipIfUnsupported(WaitUntilReadyFastFailFeature)
c, err := Connect(globalConfig.connstr, ClusterOptions{
Authenticator: PasswordAuthenticator{
Username: globalConfig.User,
Password: "thisisaprettyunlikelypasswordtobeused",
},
SecurityConfig: globalConfig.SecurityConfig,
})
suite.Require().Nil(err, err)
defer c.Close(nil)
b := c.Bucket(globalConfig.Bucket)
err = b.WaitUntilReady(globalCluster.waitUntilReadyTimeout(), &WaitUntilReadyOptions{
RetryStrategy: newFailFastRetryStrategy(),
})
if !errors.Is(err, ErrAuthenticationFailure) {
suite.T().Fatalf("Expected authentication error but was: %v", err)
}
}
func (suite *IntegrationTestSuite) TestBucketWaitUntilReadyFastFailConnStr() {
suite.skipIfUnsupported(WaitUntilReadyFeature)
suite.skipIfUnsupported(WaitUntilReadyClusterFeature)
suite.skipIfUnsupported(WaitUntilReadyFastFailFeature)
c, err := Connect("10.10.10.10", ClusterOptions{
Authenticator: PasswordAuthenticator{
Username: globalConfig.User,
Password: globalConfig.Password,
},
SecurityConfig: globalConfig.SecurityConfig,
})
suite.Require().Nil(err, err)
defer c.Close(nil)
b := c.Bucket(globalConfig.Bucket)
err = b.WaitUntilReady(globalCluster.waitUntilReadyTimeout(), &WaitUntilReadyOptions{
RetryStrategy: newFailFastRetryStrategy(),
})
if !errors.Is(err, ErrTimeout) {
suite.T().Fatalf("Expected timeout error but was: %v", err)
}
}
func (suite *IntegrationTestSuite) TestBucketOpsAfterClusterClose() {
_, b := suite.CreateAndCloseNewClusterAndBucket()
suite.Run("Ping", func() {
_, err := b.Ping(nil)
suite.Require().ErrorIs(err, ErrShutdown)
})
suite.Run("WaitUntilReady", func() {
err := b.WaitUntilReady(5*time.Second, nil)
suite.Require().ErrorIs(err, ErrShutdown)
})
suite.Run("Internal.IORouter", func() {
_, err := b.Internal().IORouter()
suite.Require().ErrorIs(err, ErrShutdown)
})
suite.Run("ViewQuery", func() {
_, b := suite.CreateAndCloseNewClusterAndBucket()
_, err := b.ViewQuery("test", "test", nil)
suite.Require().ErrorIs(err, ErrShutdown)
})
}