Skip to content

Commit 90682c7

Browse files
committed
GOCBC-1818: Fix panic when running test suite with -short flag
We have a few places in the test suite that assume a globalCluster is configured. This is not the case when running the tests with the -short flag, which only runs unit tests. Change-Id: I324b19f1916715a14cd458a7c59b647da979d129 Reviewed-on: https://review.couchbase.org/c/gocb/+/244631 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Charles Dixon <chvckd@gmail.com>
1 parent ce83cdd commit 90682c7

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ devsetup:
44

55
test:
66
go test ./
7+
78
fasttest:
89
go test -short ./
910

scope_searchindexes_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,18 @@ func (suite *UnitTestSuite) TestScopeSearchIndexesAnalyzeDocumentCore() {
269269
Body: io.NopCloser(bytes.NewReader(analyzeResp)),
270270
}
271271

272-
indexName := "searchy"
272+
cli := new(mockConnectionManager)
273+
bucket := suite.bucket("mock", cli)
274+
scope := suite.newScope(bucket, "test")
275+
indexName := "test-index"
273276

274277
mockProvider := new(mockMgmtProvider)
275278
mockProvider.
276279
On("executeMgmtRequest", nil, mock.AnythingOfType("mgmtRequest")).
277280
Run(func(args mock.Arguments) {
278281
req := args.Get(1).(mgmtRequest)
279282

280-
expectedPath := fmt.Sprintf("/api/bucket/%s/scope/%s/index/%s/analyzeDoc", globalScope.bucket.bucketName, globalScope.scopeName, indexName)
283+
expectedPath := fmt.Sprintf("/api/bucket/%s/scope/%s/index/%s/analyzeDoc", bucket.Name(), scope.Name(), indexName)
281284

282285
suite.Assert().Equal(expectedPath, req.Path)
283286
suite.Assert().Equal(ServiceTypeSearch, req.Service)
@@ -299,11 +302,10 @@ func (suite *UnitTestSuite) TestScopeSearchIndexesAnalyzeDocumentCore() {
299302
tracer: newTracerWrapper(&NoopTracer{}, ObservabilityConfig{}),
300303
}
301304

302-
res, err := mgr.AnalyzeDocument(globalScope, indexName, struct{}{}, &AnalyzeDocumentOptions{
305+
res, err := mgr.AnalyzeDocument(scope, indexName, struct{}{}, &AnalyzeDocumentOptions{
303306
Timeout: 1 * time.Second,
304307
})
305-
suite.Require().Nil(err, err)
306-
308+
suite.Require().NoError(err)
307309
suite.Require().NotNil(res)
308310
}
309311

testmain_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func TestMain(m *testing.M) {
138138
setupCluster()
139139
}
140140

141-
if !globalCluster.IsProtostellar() {
141+
if globalCluster != nil && !globalCluster.IsProtostellar() {
142142
gocbcore.EnableHttpResponseTracking()
143143
}
144144

@@ -177,7 +177,7 @@ func TestMain(m *testing.M) {
177177
log.Printf("No goroutines appear to have leaked (%d before == %d after)", initialGoroutineCount, finalGoroutineCount)
178178
}
179179

180-
if !globalCluster.IsProtostellar() && !gocbcore.ReportLeakedHttpResponses() {
180+
if globalCluster != nil && !globalCluster.IsProtostellar() && !gocbcore.ReportLeakedHttpResponses() {
181181
result = 1
182182
}
183183

0 commit comments

Comments
 (0)