diff --git a/.github/workflows/unit-benchmark.yml b/.github/workflows/unit-benchmark.yml index c810344a..77b64f39 100644 --- a/.github/workflows/unit-benchmark.yml +++ b/.github/workflows/unit-benchmark.yml @@ -39,5 +39,5 @@ jobs: --count=5 --debug --bench "^BenchmarkCrud|BenchmarkQuery|BenchmarkSearch" - --tolerance=1.0 + --tolerance=5.0 github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/cbmgmtx/mgmt.go b/cbmgmtx/mgmt.go index c6c4455d..b00d9db4 100644 --- a/cbmgmtx/mgmt.go +++ b/cbmgmtx/mgmt.go @@ -251,7 +251,10 @@ type GetBucketConfigOptions struct { func (h Management) GetBucketConfig(ctx context.Context, opts *GetBucketConfigOptions) (*cbconfig.FullBucketConfigJson, error) { if opts.BucketName == "" { - return nil, errors.New("must specify bucket name when fetching a bucket config") + return nil, ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } resp, err := h.Execute(ctx, "GET", @@ -277,7 +280,10 @@ type GetTerseBucketConfigOptions struct { func (h Management) GetTerseBucketConfig(ctx context.Context, opts *GetTerseBucketConfigOptions) (*cbconfig.TerseConfigJson, error) { if opts.BucketName == "" { - return nil, errors.New("must specify bucket name when fetching a terse bucket config") + return nil, ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } resp, err := h.Execute(ctx, "GET", @@ -303,7 +309,10 @@ type CheckBucketExistsOptions struct { func (h Management) CheckBucketExists(ctx context.Context, opts *CheckBucketExistsOptions) (bool, error) { if opts.BucketName == "" { - return false, errors.New("must specify bucket name when checking a bucket exists") + return false, ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } resp, err := h.Execute(ctx, "HEAD", @@ -334,7 +343,10 @@ type TerseBucketConfig_Stream interface { func (h Management) StreamTerseBucketConfig(ctx context.Context, opts *StreamTerseBucketConfigOptions) (TerseBucketConfig_Stream, error) { if opts.BucketName == "" { - return nil, errors.New("must specify bucket name when streaming a bucket config") + return nil, ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } resp, err := h.Execute(ctx, "GET", @@ -420,7 +432,10 @@ type GetCollectionManifestOptions struct { func (h Management) GetCollectionManifest(ctx context.Context, opts *GetCollectionManifestOptions) (*cbconfig.CollectionManifestJson, error) { if opts.BucketName == "" { - return nil, errors.New("must specify bucket name when fetching a collection manifest") + return nil, ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } resp, err := h.Execute(ctx, "GET", @@ -457,10 +472,16 @@ func (h Management) CreateScope( opts *CreateScopeOptions, ) (*CreateScopeResponse, error) { if opts.BucketName == "" { - return nil, errors.New("must specify bucket name when creating a scope") + return nil, ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } if opts.ScopeName == "" { - return nil, errors.New("must specify scope name when creating a scope") + return nil, ServerInvalidArgError{ + Argument: "ScopeName", + Reason: "scope name cannot be blank", + } } posts := url.Values{} @@ -505,10 +526,16 @@ func (h Management) DeleteScope( opts *DeleteScopeOptions, ) (*DeleteScopeResponse, error) { if opts.BucketName == "" { - return nil, errors.New("must specify bucket name when deleting a scope") + return nil, ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } if opts.ScopeName == "" { - return nil, errors.New("must specify scope name when deleting a scope") + return nil, ServerInvalidArgError{ + Argument: "ScopeName", + Reason: "scope name cannot be blank", + } } resp, err := h.Execute( @@ -553,13 +580,22 @@ func (h Management) CreateCollection( opts *CreateCollectionOptions, ) (*CreateCollectionResponse, error) { if opts.BucketName == "" { - return nil, errors.New("must specify bucket name when creating a collection") + return nil, ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } if opts.ScopeName == "" { - return nil, errors.New("must specify scope name when creating a collection") + return nil, ServerInvalidArgError{ + Argument: "ScopeName", + Reason: "scope name cannot be blank", + } } if opts.CollectionName == "" { - return nil, errors.New("must specify collection name when creating a collection") + return nil, ServerInvalidArgError{ + Argument: "CollectionName", + Reason: "collection name cannot be blank", + } } posts := url.Values{} @@ -613,13 +649,22 @@ func (h Management) DeleteCollection( opts *DeleteCollectionOptions, ) (*DeleteCollectionResponse, error) { if opts.BucketName == "" { - return nil, errors.New("must specify bucket name when deleting a collection") + return nil, ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } if opts.ScopeName == "" { - return nil, errors.New("must specify scope name when deleting a collection") + return nil, ServerInvalidArgError{ + Argument: "ScopeName", + Reason: "scope name cannot be blank", + } } if opts.CollectionName == "" { - return nil, errors.New("must specify collection name when deleting a collection") + return nil, ServerInvalidArgError{ + Argument: "CollectionName", + Reason: "collection name cannot be blank", + } } resp, err := h.Execute( @@ -664,13 +709,22 @@ func (h Management) UpdateCollection( opts *UpdateCollectionOptions, ) (*UpdateCollectionResponse, error) { if opts.BucketName == "" { - return nil, errors.New("must specify bucket name when updating a collection") + return nil, ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } if opts.ScopeName == "" { - return nil, errors.New("must specify scope name when updating a collection") + return nil, ServerInvalidArgError{ + Argument: "ScopeName", + Reason: "scope name cannot be blank", + } } if opts.CollectionName == "" { - return nil, errors.New("must specify collection name when updating a collection") + return nil, ServerInvalidArgError{ + Argument: "CollectionName", + Reason: "collection name cannot be blank", + } } posts := url.Values{} @@ -799,7 +853,10 @@ func (h Management) encodeBucketSettings(posts *url.Values, opts *BucketSettings } if opts.ReplicaIndex { if opts.BucketType == BucketTypeEphemeral { - return errors.New("cannot specify ReplicaIndex for Ephemeral buckets") + return ServerInvalidArgError{ + Argument: "ReplicaIndex", + Reason: "cannot specify ReplicaIndex for Ephemeral buckets", + } } posts.Add("replicaIndex", "1") } else if opts.BucketType != BucketTypeEphemeral { @@ -902,10 +959,10 @@ func (h Management) GetBucket( opts *GetBucketOptions, ) (*BucketDef, error) { if opts.BucketName == "" { - return nil, fmt.Errorf("%w: %w", ErrServerInvalidArg, ServerInvalidArgError{ + return nil, ServerInvalidArgError{ Argument: "BucketName", Reason: "bucket name cannot be blank", - }) + } } resp, err := h.Execute( @@ -945,10 +1002,10 @@ func (h Management) CreateBucket( opts *CreateBucketOptions, ) error { if opts.BucketName == "" { - return fmt.Errorf("%w: %w", ErrServerInvalidArg, ServerInvalidArgError{ + return ServerInvalidArgError{ Argument: "BucketName", Reason: "bucket name cannot be blank", - }) + } } posts := url.Values{} @@ -989,10 +1046,10 @@ func (h Management) UpdateBucket( opts *UpdateBucketOptions, ) error { if opts.BucketName == "" { - return fmt.Errorf("%w: %w", ErrServerInvalidArg, ServerInvalidArgError{ + return ServerInvalidArgError{ Argument: "BucketName", Reason: "bucket name cannot be blank", - }) + } } posts := url.Values{} @@ -1029,10 +1086,10 @@ func (h Management) DeleteBucket( opts *DeleteBucketOptions, ) error { if opts.BucketName == "" { - return fmt.Errorf("%w: %w", ErrServerInvalidArg, ServerInvalidArgError{ + return ServerInvalidArgError{ Argument: "BucketName", Reason: "bucket name cannot be blank", - }) + } } resp, err := h.Execute( @@ -1070,10 +1127,10 @@ func (h Management) FlushBucket( opts *FlushBucketOptions, ) error { if opts.BucketName == "" { - return fmt.Errorf("%w: %w", ErrServerInvalidArg, ServerInvalidArgError{ + return ServerInvalidArgError{ Argument: "BucketName", Reason: "bucket name cannot be blank", - }) + } } resp, err := h.Execute( @@ -1297,7 +1354,10 @@ func (h Management) UpsertUser( opts *UpsertUserOptions, ) error { if opts.Username == "" { - return errors.New("must specify username when upserting a user") + return ServerInvalidArgError{ + Argument: "Username", + Reason: "username cannot be blank", + } } if opts.Domain == "" { @@ -1347,7 +1407,10 @@ func (h Management) DeleteUser( opts *DeleteUserOptions, ) error { if opts.Username == "" { - return errors.New("must specify username when deleting a user") + return ServerInvalidArgError{ + Argument: "Username", + Reason: "username cannot be blank", + } } if opts.Domain == "" { diff --git a/cbqueryx/query.go b/cbqueryx/query.go index 5db7eb60..132591ef 100644 --- a/cbqueryx/query.go +++ b/cbqueryx/query.go @@ -171,7 +171,10 @@ type CreatePrimaryIndexOptions struct { func (h Query) CreatePrimaryIndex(ctx context.Context, opts *CreatePrimaryIndexOptions) error { if opts.BucketName == "" { - return errors.New("must specify bucket name when creating an index") + return ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } qs := "CREATE PRIMARY INDEX" @@ -237,13 +240,22 @@ type CreateIndexOptions struct { func (h Query) CreateIndex(ctx context.Context, opts *CreateIndexOptions) error { if opts.IndexName == "" { - return errors.New("must specify index name when creating an index") + return ServerInvalidArgError{ + Argument: "IndexName", + Reason: "index name cannot be blank", + } } if opts.BucketName == "" { - return errors.New("must specify bucket name when creating an index") + return ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } if len(opts.Fields) == 0 { - return errors.New("must specify fields when creating an index") + return ServerInvalidArgError{ + Argument: "Fields", + Reason: "fields cannot be empty", + } } qs := "CREATE INDEX" @@ -309,7 +321,10 @@ type DropPrimaryIndexOptions struct { func (h Query) DropPrimaryIndex(ctx context.Context, opts *DropPrimaryIndexOptions) error { if opts.BucketName == "" { - return errors.New("must specify bucket name when dropping an index") + return ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } keyspace := buildKeyspace(opts.BucketName, opts.ScopeName, opts.CollectionName) @@ -363,10 +378,16 @@ type DropIndexOptions struct { func (h Query) DropIndex(ctx context.Context, opts *DropIndexOptions) error { if opts.IndexName == "" { - return errors.New("must specify index name when dropping an index") + return ServerInvalidArgError{ + Argument: "IndexName", + Reason: "index name cannot be blank", + } } if opts.BucketName == "" { - return errors.New("must specify bucket name when dropping an index") + return ServerInvalidArgError{ + Argument: "BucketName", + Reason: "bucket name cannot be blank", + } } encodedName := EncodeIdentifier(opts.IndexName) diff --git a/cbqueryx/query_test.go b/cbqueryx/query_test.go index bb4c656b..6dc39abf 100644 --- a/cbqueryx/query_test.go +++ b/cbqueryx/query_test.go @@ -86,6 +86,83 @@ func TestQueryIndexExists(t *testing.T) { assert.ErrorIs(t, err, ErrIndexExists) } +func TestCreatePrimaryIndexInvalidArgs(t *testing.T) { + q := Query{} + + err := q.CreatePrimaryIndex(context.Background(), &CreatePrimaryIndexOptions{BucketName: ""}) + require.ErrorIs(t, err, ErrServerInvalidArg) + var argErr ServerInvalidArgError + require.ErrorAs(t, err, &argErr) + assert.Equal(t, "BucketName", argErr.Argument) +} + +func TestCreateIndexInvalidArgs(t *testing.T) { + q := Query{} + + t.Run("BlankIndexName", func(t *testing.T) { + err := q.CreateIndex(context.Background(), &CreateIndexOptions{ + BucketName: "b", + Fields: []string{"f"}, + }) + require.ErrorIs(t, err, ErrServerInvalidArg) + var argErr ServerInvalidArgError + require.ErrorAs(t, err, &argErr) + assert.Equal(t, "IndexName", argErr.Argument) + }) + + t.Run("BlankBucketName", func(t *testing.T) { + err := q.CreateIndex(context.Background(), &CreateIndexOptions{ + IndexName: "idx", + Fields: []string{"f"}, + }) + require.ErrorIs(t, err, ErrServerInvalidArg) + var argErr ServerInvalidArgError + require.ErrorAs(t, err, &argErr) + assert.Equal(t, "BucketName", argErr.Argument) + }) + + t.Run("EmptyFields", func(t *testing.T) { + err := q.CreateIndex(context.Background(), &CreateIndexOptions{ + IndexName: "idx", + BucketName: "b", + }) + require.ErrorIs(t, err, ErrServerInvalidArg) + var argErr ServerInvalidArgError + require.ErrorAs(t, err, &argErr) + assert.Equal(t, "Fields", argErr.Argument) + }) +} + +func TestDropPrimaryIndexInvalidArgs(t *testing.T) { + q := Query{} + + err := q.DropPrimaryIndex(context.Background(), &DropPrimaryIndexOptions{BucketName: ""}) + require.ErrorIs(t, err, ErrServerInvalidArg) + var argErr ServerInvalidArgError + require.ErrorAs(t, err, &argErr) + assert.Equal(t, "BucketName", argErr.Argument) +} + +func TestDropIndexInvalidArgs(t *testing.T) { + q := Query{} + + t.Run("BlankIndexName", func(t *testing.T) { + err := q.DropIndex(context.Background(), &DropIndexOptions{BucketName: "b"}) + require.ErrorIs(t, err, ErrServerInvalidArg) + var argErr ServerInvalidArgError + require.ErrorAs(t, err, &argErr) + assert.Equal(t, "IndexName", argErr.Argument) + }) + + t.Run("BlankBucketName", func(t *testing.T) { + err := q.DropIndex(context.Background(), &DropIndexOptions{IndexName: "idx"}) + require.ErrorIs(t, err, ErrServerInvalidArg) + var argErr ServerInvalidArgError + require.ErrorAs(t, err, &argErr) + assert.Equal(t, "BucketName", argErr.Argument) + }) +} + func TestQueryIndexNotFound(t *testing.T) { index := uuid.NewString()[:6] expectedResult := makeErrorQueryResult([]queryErrorJson{ diff --git a/cbsearchx/errors.go b/cbsearchx/errors.go index 0394ee75..14fab182 100644 --- a/cbsearchx/errors.go +++ b/cbsearchx/errors.go @@ -13,7 +13,9 @@ var ( ErrIndexNameInvalid = errors.New("index name invalid") ErrIndexNameTooLong = errors.New("index name too long") ErrIndexNameEmpty = errors.New("index name empty") + ErrIndexTypeEmpty = errors.New("index type empty") ErrUnknownIndexType = errors.New("unknown index type") + ErrSourceTypeEmpty = errors.New("source type empty") ErrSourceTypeIncorrect = errors.New("source type incorrect") ErrSourceNotFound = errors.New("source not found") ErrNoIndexPartitionsPlanned = errors.New("no index partitions planned") diff --git a/cbsearchx/search.go b/cbsearchx/search.go index 427e5776..0c1d1d4c 100644 --- a/cbsearchx/search.go +++ b/cbsearchx/search.go @@ -82,7 +82,7 @@ func (h Search) Query(ctx context.Context, opts *QueryOptions) (QueryResultStrea reqURI = fmt.Sprintf("/api/index/%s/query", url.PathEscape(opts.IndexName)) } else { if opts.ScopeName == "" || opts.BucketName == "" { - return nil, errors.New("must specify both or neither of scope and bucket names") + return nil, ErrOnlyBucketOrScopeSet } reqURI = fmt.Sprintf("/api/bucket/%s/scope/%s/index/%s/query", url.PathEscape(opts.BucketName), url.PathEscape(opts.ScopeName), url.PathEscape(opts.IndexName)) @@ -130,10 +130,10 @@ func (h Search) UpsertIndex( return nil, ErrIndexNameEmpty } if opts.Type == "" { - return nil, errors.New("must specify index type when creating an index") + return nil, ErrIndexTypeEmpty } if opts.SourceType == "" { - return nil, errors.New("must specify source type when creating an index") + return nil, ErrSourceTypeEmpty } var reqURI string diff --git a/cbsearchx/search_int_test.go b/cbsearchx/search_int_test.go index d408d348..f40b4335 100644 --- a/cbsearchx/search_int_test.go +++ b/cbsearchx/search_int_test.go @@ -129,14 +129,28 @@ func TestUpsertIndex(t *testing.T) { opts := defaultOpts(indexName) opts.Type = "" _, err := search.UpsertIndex(ctx, &opts) - require.NotNil(t, err) + require.ErrorIs(t, err, cbsearchx.ErrIndexTypeEmpty) }) t.Run("MissingIndexSourceType", func(t *testing.T) { opts := defaultOpts(indexName) opts.SourceType = "" _, err := search.UpsertIndex(ctx, &opts) - require.NotNil(t, err) + require.ErrorIs(t, err, cbsearchx.ErrSourceTypeEmpty) + }) + + t.Run("MissingBucketName", func(t *testing.T) { + opts := defaultOpts(indexName) + opts.ScopeName = "_default" + _, err := search.UpsertIndex(ctx, &opts) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + + t.Run("MissingScopeName", func(t *testing.T) { + opts := defaultOpts(indexName) + opts.BucketName = testutilsint.TestOpts.BucketName + _, err := search.UpsertIndex(ctx, &opts) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) }) t.Run("IndexSourceTypeIncorrect", func(t *testing.T) { @@ -230,6 +244,14 @@ func TestGetIndex(t *testing.T) { require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) }) + t.Run("MissingScopeName", func(t *testing.T) { + _, err := search.GetIndex(ctx, &cbsearchx.GetIndexOptions{ + IndexName: indexName, + BucketName: testutilsint.TestOpts.BucketName, + }) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + t.Run("IndexNotFound", func(t *testing.T) { _, err := search.GetIndex(ctx, &cbsearchx.GetIndexOptions{ IndexName: "indexNotFound", @@ -320,6 +342,14 @@ func TestDeleteIndex(t *testing.T) { require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) }) + t.Run("IndexMissingBucket", func(t *testing.T) { + err := search.DeleteIndex(ctx, &cbsearchx.DeleteIndexOptions{ + IndexName: indexName, + ScopeName: "_default", + }) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + t.Run("SuccessScopedSearch", func(t *testing.T) { testutilsint.SkipIfUnsupportedFeature(t, testutilsint.TestFeatureScopedSearch) opts.BucketName = "some-bucket" @@ -397,6 +427,13 @@ func TestGetAllIndexes(t *testing.T) { require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) }) + t.Run("BucketNameMissing", func(t *testing.T) { + _, err := search.GetAllIndexes(ctx, &cbsearchx.GetAllIndexesOptions{ + ScopeName: "_default", + }) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + t.Run("SuccessScopedSearch", func(t *testing.T) { testutilsint.SkipIfUnsupportedFeature(t, testutilsint.TestFeatureScopedSearch) temp := opts @@ -477,6 +514,22 @@ func TestPartitionControl(t *testing.T) { require.ErrorIs(t, sErr.Cause, cbsearchx.ErrIndexNotFound) }) + t.Run("MissingBucketName", func(t *testing.T) { + err = search.FreezePlan(ctx, &cbsearchx.FreezePlanOptions{ + IndexName: indexName, + ScopeName: "_default", + }) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + + t.Run("MissingScopeName", func(t *testing.T) { + err = search.FreezePlan(ctx, &cbsearchx.FreezePlanOptions{ + IndexName: indexName, + BucketName: testutilsint.TestOpts.BucketName, + }) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + t.Run("ScopedSuccess", func(t *testing.T) { testutilsint.SkipIfUnsupportedFeature(t, testutilsint.TestFeatureScopedSearch) opts := scopedOpts(scopedIndexName) @@ -557,6 +610,22 @@ func TestIngestControl(t *testing.T) { require.ErrorIs(t, sErr.Cause, cbsearchx.ErrIndexNotFound) }) + t.Run("MissingBucketName", func(t *testing.T) { + err = search.PauseIngest(ctx, &cbsearchx.PauseIngestOptions{ + IndexName: indexName, + ScopeName: "_default", + }) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + + t.Run("MissingScopeName", func(t *testing.T) { + err = search.PauseIngest(ctx, &cbsearchx.PauseIngestOptions{ + IndexName: indexName, + BucketName: testutilsint.TestOpts.BucketName, + }) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + t.Run("ScopedSuccess", func(t *testing.T) { testutilsint.SkipIfUnsupportedFeature(t, testutilsint.TestFeatureScopedSearch) opts := scopedOpts(scopedIndexName) @@ -644,6 +713,22 @@ func TestQueryControl(t *testing.T) { require.ErrorIs(t, sErr.Cause, cbsearchx.ErrIndexNotFound) }) + t.Run("MissingBucketName", func(t *testing.T) { + err = search.DisallowQuerying(ctx, &cbsearchx.DisallowQueryingOptions{ + IndexName: indexName, + ScopeName: "_default", + }) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + + t.Run("MissingScopeName", func(t *testing.T) { + err = search.DisallowQuerying(ctx, &cbsearchx.DisallowQueryingOptions{ + IndexName: indexName, + BucketName: testutilsint.TestOpts.BucketName, + }) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + t.Run("ScopedSuccess", func(t *testing.T) { testutilsint.SkipIfUnsupportedFeature(t, testutilsint.TestFeatureScopedSearch) scopedName := newSearchIndexName() @@ -753,6 +838,26 @@ func TestAnalyzeDocument(t *testing.T) { require.ErrorIs(t, sErr.Cause, cbsearchx.ErrIndexNotFound) }) + t.Run("MissingBucketName", func(t *testing.T) { + aOpts := cbsearchx.AnalyzeDocumentOptions{ + IndexName: indexName, + ScopeName: "_default", + DocContent: []byte("true"), + } + _, err := search.AnalyzeDocument(ctx, &aOpts) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + + t.Run("MissingScopeName", func(t *testing.T) { + aOpts := cbsearchx.AnalyzeDocumentOptions{ + IndexName: indexName, + BucketName: testutilsint.TestOpts.BucketName, + DocContent: []byte("true"), + } + _, err := search.AnalyzeDocument(ctx, &aOpts) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + t.Run("ScopedSuccess", func(t *testing.T) { testutilsint.SkipIfUnsupportedFeature(t, testutilsint.TestFeatureScopedSearch) opts := cbsearchx.UpsertIndexOptions{ @@ -850,6 +955,22 @@ func TestGetIndexedDocumentsCount(t *testing.T) { require.ErrorIs(t, sErr.Cause, cbsearchx.ErrIndexNotFound) }) + t.Run("MissingBucketName", func(t *testing.T) { + _, err := search.GetIndexedDocumentsCount(ctx, &cbsearchx.GetIndexedDocumentsCountOptions{ + IndexName: indexName, + ScopeName: "_default", + }) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + + t.Run("MissingScopeName", func(t *testing.T) { + _, err := search.GetIndexedDocumentsCount(ctx, &cbsearchx.GetIndexedDocumentsCountOptions{ + IndexName: indexName, + BucketName: testutilsint.TestOpts.BucketName, + }) + require.Equal(t, cbsearchx.ErrOnlyBucketOrScopeSet, err) + }) + scopedName := newSearchIndexName() scopedOpts := cbsearchx.UpsertIndexOptions{ BucketName: "someBucket",