diff --git a/internal/cli/deployments/search/indexes/create.go b/internal/cli/deployments/search/indexes/create.go index b812f18a2c..238ca85431 100644 --- a/internal/cli/deployments/search/indexes/create.go +++ b/internal/cli/deployments/search/indexes/create.go @@ -105,13 +105,7 @@ func (opts *CreateOpts) RunAtlas() error { return err } - //TODO: CLOUDP-260963 Update to use the new struct - result, err := opts.store.CreateSearchIndexes(opts.ConfigProjectID(), opts.DeploymentName, index) - if err != nil { - return err - } - - opts.index = search.IndexResponseToDeprecated(result) + opts.index, err = opts.store.CreateSearchIndexes(opts.ConfigProjectID(), opts.DeploymentName, index) return err } diff --git a/internal/cli/deployments/search/indexes/create_test.go b/internal/cli/deployments/search/indexes/create_test.go index 3612559c12..ff6b6405e0 100644 --- a/internal/cli/deployments/search/indexes/create_test.go +++ b/internal/cli/deployments/search/indexes/create_test.go @@ -290,19 +290,17 @@ func TestCreate_RunAtlas(t *testing.T) { index, err := opts.NewSearchIndex() require.NoError(t, err) - indexWithID := &atlasv2.SearchIndexResponse{ - CollectionName: &opts.Collection, - Database: &opts.DBName, - LatestDefinition: &atlasv2.BaseSearchIndexResponseLatestDefinition{ - Analyzer: &opts.Analyzer, - Mappings: &atlasv2.SearchMappings{ - Dynamic: &opts.Dynamic, - Fields: nil, - }, - SearchAnalyzer: &opts.SearchAnalyzer, + indexWithID := &atlasv2.ClusterSearchIndex{ + CollectionName: opts.Collection, + Database: opts.DBName, + Analyzer: &opts.Analyzer, + Mappings: &atlasv2.ApiAtlasFTSMappings{ + Dynamic: &opts.Dynamic, + Fields: nil, }, - Name: &opts.Name, - IndexID: &indexID, + SearchAnalyzer: &opts.SearchAnalyzer, + Name: opts.Name, + IndexID: &indexID, } deploymentTest.CommonAtlasMocks(opts.ProjectID) diff --git a/internal/cli/deployments/search/indexes/describe_test.go b/internal/cli/deployments/search/indexes/describe_test.go index bf22d1a2a5..c80412e0d3 100644 --- a/internal/cli/deployments/search/indexes/describe_test.go +++ b/internal/cli/deployments/search/indexes/describe_test.go @@ -156,18 +156,18 @@ func TestDescribe_RunAtlas(t *testing.T) { mockStore. EXPECT(). SearchIndex(opts.ProjectID, opts.DeploymentName, opts.indexID). - Return(&atlasv2.SearchIndexResponse{ - Name: &name, - Database: &database, - CollectionName: &collectionName, + Return(&atlasv2.ClusterSearchIndex{ + Name: name, + Database: database, + CollectionName: collectionName, IndexID: pointer.Get("test"), }, nil). Times(1) - expected := &atlasv2.SearchIndexResponse{ - Name: &name, - Database: &database, - CollectionName: &collectionName, + expected := &atlasv2.ClusterSearchIndex{ + Name: name, + Database: database, + CollectionName: collectionName, IndexID: pointer.Get("test"), } diff --git a/internal/cli/deployments/search/indexes/list_test.go b/internal/cli/deployments/search/indexes/list_test.go index a899b5d159..2f4e46efc1 100644 --- a/internal/cli/deployments/search/indexes/list_test.go +++ b/internal/cli/deployments/search/indexes/list_test.go @@ -177,22 +177,22 @@ func TestList_RunAtlas(t *testing.T) { mockStore. EXPECT(). SearchIndexes(opts.ProjectID, opts.DeploymentName, opts.DBName, opts.Collection). - Return([]atlasv2.SearchIndexResponse{ + Return([]atlasv2.ClusterSearchIndex{ { - Name: &expectedName, - Database: &expectedDB, - CollectionName: &expectedCollection, + Name: expectedName, + Database: expectedDB, + CollectionName: expectedCollection, IndexID: pointer.Get(expectedID), }, }, nil). Times(1) - expected := []*atlasv2.SearchIndexResponse{ + expected := []*atlasv2.ClusterSearchIndex{ { - Name: &expectedName, + Name: expectedName, IndexID: pointer.Get(expectedID), - CollectionName: &expectedCollection, - Database: &expectedDB, + CollectionName: expectedCollection, + Database: expectedDB, }, } diff --git a/internal/cli/search/create_test.go b/internal/cli/search/create_test.go index ff061c2bf7..33c66a2d27 100644 --- a/internal/cli/search/create_test.go +++ b/internal/cli/search/create_test.go @@ -45,7 +45,7 @@ func TestCreateOpts_Run(t *testing.T) { if err != nil { t.Fatalf("newSearchIndex() unexpected error: %v", err) } - expected := &atlasv2.SearchIndexResponse{} + expected := &atlasv2.ClusterSearchIndex{} mockStore. EXPECT(). CreateSearchIndexes(opts.ProjectID, opts.clusterName, request). @@ -68,7 +68,7 @@ func TestCreateOpts_Run(t *testing.T) { opts.Filename = fileName opts.Fs = appFS - expected := &atlasv2.SearchIndexResponse{} + expected := &atlasv2.ClusterSearchIndex{} request, err := opts.NewSearchIndex() if err != nil { t.Fatalf("newSearchIndex() unexpected error: %v", err) diff --git a/internal/cli/search/describe_test.go b/internal/cli/search/describe_test.go index 562ad81033..cf416e2e44 100644 --- a/internal/cli/search/describe_test.go +++ b/internal/cli/search/describe_test.go @@ -35,8 +35,8 @@ func TestDescribe_Run(t *testing.T) { store: mockStore, } - expected := &atlasv2.SearchIndexResponse{ - Name: &describeOpts.clusterName, + expected := &atlasv2.ClusterSearchIndex{ + Name: describeOpts.clusterName, } mockStore. EXPECT(). diff --git a/internal/cli/search/index_opts.go b/internal/cli/search/index_opts.go index 2df8f30fac..6e86a7952d 100644 --- a/internal/cli/search/index_opts.go +++ b/internal/cli/search/index_opts.go @@ -116,22 +116,9 @@ func (opts *IndexOpts) DeprecatedNewSearchIndex() (*atlasv2.ClusterSearchIndex, return i, nil } -func IndexResponseToDeprecated(r *atlasv2.SearchIndexResponse) *atlasv2.ClusterSearchIndex { - return &atlasv2.ClusterSearchIndex{ - CollectionName: *r.CollectionName, - Database: *r.Database, - Mappings: (*atlasv2.ApiAtlasFTSMappings)(r.LatestDefinition.Mappings), - Name: *r.Name, - SearchAnalyzer: r.LatestDefinition.SearchAnalyzer, - Status: r.Status, - Type: r.Type, - IndexID: r.IndexID, - } -} - -func (opts *IndexOpts) NewSearchIndex() (*atlasv2.SearchIndexCreateRequest, error) { +func (opts *IndexOpts) NewSearchIndex() (*atlasv2.ClusterSearchIndex, error) { if len(opts.Filename) > 0 { - index := &atlasv2.SearchIndexCreateRequest{} + index := &atlasv2.ClusterSearchIndex{} if err := file.Load(opts.Fs, opts.Filename, index); err != nil { return nil, fmt.Errorf(failedToLoadIndexMessage, err.Error()) } @@ -152,51 +139,17 @@ func (opts *IndexOpts) NewSearchIndex() (*atlasv2.SearchIndexCreateRequest, erro opts.SearchAnalyzer = DefaultAnalyzer } - i := &atlasv2.SearchIndexCreateRequest{ + i := &atlasv2.ClusterSearchIndex{ CollectionName: opts.Collection, Database: opts.DBName, Name: opts.Name, // only search indexes can be created using flags - Type: pointer.Get(SearchIndexType), - Definition: &atlasv2.BaseSearchIndexCreateRequestDefinition{ - Analyzer: &opts.Analyzer, - SearchAnalyzer: &opts.SearchAnalyzer, - Mappings: &atlasv2.SearchMappings{ - Dynamic: &opts.Dynamic, - Fields: f, - }, - }, - } - return i, nil -} - -func (opts *IndexOpts) NewSearchIndexUpdate() (*atlasv2.SearchIndexUpdateRequest, error) { - if len(opts.Filename) > 0 { - index := &atlasv2.SearchIndexUpdateRequest{} - if err := file.Load(opts.Fs, opts.Filename, index); err != nil { - return nil, fmt.Errorf(failedToLoadIndexMessage, err.Error()) - } - - return index, nil - } - - f, err := opts.indexFields() - if err != nil { - return nil, err - } - - if opts.SearchAnalyzer == "" { - opts.SearchAnalyzer = DefaultAnalyzer - } - - i := &atlasv2.SearchIndexUpdateRequest{ - Definition: atlasv2.SearchIndexUpdateRequestDefinition{ - Analyzer: &opts.Analyzer, - SearchAnalyzer: &opts.SearchAnalyzer, - Mappings: &atlasv2.SearchMappings{ - Dynamic: &opts.Dynamic, - Fields: f, - }, + Type: pointer.Get(SearchIndexType), + Analyzer: &opts.Analyzer, + SearchAnalyzer: &opts.SearchAnalyzer, + Mappings: &atlasv2.ApiAtlasFTSMappings{ + Dynamic: &opts.Dynamic, + Fields: f, }, } return i, nil diff --git a/internal/cli/search/list_test.go b/internal/cli/search/list_test.go index 06df12bc6c..d83a180ca3 100644 --- a/internal/cli/search/list_test.go +++ b/internal/cli/search/list_test.go @@ -34,9 +34,9 @@ func TestList_Run(t *testing.T) { } name := "test" - expected := []atlasv2.SearchIndexResponse{ + expected := []atlasv2.ClusterSearchIndex{ { - Name: &name, + Name: name, }, } diff --git a/internal/cli/search/nodes/delete.go b/internal/cli/search/nodes/delete.go index 3cb43772bf..03be332065 100644 --- a/internal/cli/search/nodes/delete.go +++ b/internal/cli/search/nodes/delete.go @@ -35,7 +35,7 @@ type DeleteOpts struct { store store.SearchNodesDeleter } -const atlasFtsDeploymentDoesNotExist = "ATLAS_FTS_DEPLOYMENT_DOES_NOT_EXIST" +const atlasFtsDeploymentDoesNotExist = "ATLAS_SEARCH_DEPLOYMENT_DOES_NOT_EXIST" func (opts *DeleteOpts) initStore(ctx context.Context) func() error { return func() error { diff --git a/internal/cli/search/update.go b/internal/cli/search/update.go index 2ef47a9cd3..a38599d609 100644 --- a/internal/cli/search/update.go +++ b/internal/cli/search/update.go @@ -48,7 +48,7 @@ func (opts *UpdateOpts) initStore(ctx context.Context) func() error { var updateTemplate = "Index {{.Name}} updated.\n" func (opts *UpdateOpts) Run() error { - index, err := opts.NewSearchIndexUpdate() + index, err := opts.NewSearchIndex() if err != nil { return err } diff --git a/internal/cli/search/update_test.go b/internal/cli/search/update_test.go index 2219d3f46f..e265e8f031 100644 --- a/internal/cli/search/update_test.go +++ b/internal/cli/search/update_test.go @@ -37,9 +37,9 @@ func TestUpdateOpts_Run(t *testing.T) { updateOpts.Name = testName updateOpts.id = "1" - expected := &atlasv2.SearchIndexResponse{} + expected := &atlasv2.ClusterSearchIndex{} - request, err := updateOpts.NewSearchIndexUpdate() + request, err := updateOpts.NewSearchIndex() require.NoError(t, err) mockStore. EXPECT(). @@ -63,9 +63,9 @@ func TestUpdateOpts_Run(t *testing.T) { updateOpts.Filename = fileName updateOpts.Fs = appFS - expected := &atlasv2.SearchIndexResponse{} + expected := &atlasv2.ClusterSearchIndex{} - request, err := updateOpts.NewSearchIndexUpdate() + request, err := updateOpts.NewSearchIndex() require.NoError(t, err) mockStore. EXPECT(). diff --git a/internal/mocks/mock_search.go b/internal/mocks/mock_search.go index 9bd305cd88..c108040acd 100644 --- a/internal/mocks/mock_search.go +++ b/internal/mocks/mock_search.go @@ -35,10 +35,10 @@ func (m *MockSearchIndexLister) EXPECT() *MockSearchIndexListerMockRecorder { } // SearchIndexes mocks base method. -func (m *MockSearchIndexLister) SearchIndexes(arg0, arg1, arg2, arg3 string) ([]admin.SearchIndexResponse, error) { +func (m *MockSearchIndexLister) SearchIndexes(arg0, arg1, arg2, arg3 string) ([]admin.ClusterSearchIndex, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SearchIndexes", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].([]admin.SearchIndexResponse) + ret0, _ := ret[0].([]admin.ClusterSearchIndex) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -73,10 +73,10 @@ func (m *MockSearchIndexCreator) EXPECT() *MockSearchIndexCreatorMockRecorder { } // CreateSearchIndexes mocks base method. -func (m *MockSearchIndexCreator) CreateSearchIndexes(arg0, arg1 string, arg2 *admin.SearchIndexCreateRequest) (*admin.SearchIndexResponse, error) { +func (m *MockSearchIndexCreator) CreateSearchIndexes(arg0, arg1 string, arg2 *admin.ClusterSearchIndex) (*admin.ClusterSearchIndex, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateSearchIndexes", arg0, arg1, arg2) - ret0, _ := ret[0].(*admin.SearchIndexResponse) + ret0, _ := ret[0].(*admin.ClusterSearchIndex) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -88,10 +88,10 @@ func (mr *MockSearchIndexCreatorMockRecorder) CreateSearchIndexes(arg0, arg1, ar } // SearchIndex mocks base method. -func (m *MockSearchIndexCreator) SearchIndex(arg0, arg1, arg2 string) (*admin.SearchIndexResponse, error) { +func (m *MockSearchIndexCreator) SearchIndex(arg0, arg1, arg2 string) (*admin.ClusterSearchIndex, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SearchIndex", arg0, arg1, arg2) - ret0, _ := ret[0].(*admin.SearchIndexResponse) + ret0, _ := ret[0].(*admin.ClusterSearchIndex) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -126,10 +126,10 @@ func (m *MockSearchIndexDescriber) EXPECT() *MockSearchIndexDescriberMockRecorde } // SearchIndex mocks base method. -func (m *MockSearchIndexDescriber) SearchIndex(arg0, arg1, arg2 string) (*admin.SearchIndexResponse, error) { +func (m *MockSearchIndexDescriber) SearchIndex(arg0, arg1, arg2 string) (*admin.ClusterSearchIndex, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SearchIndex", arg0, arg1, arg2) - ret0, _ := ret[0].(*admin.SearchIndexResponse) + ret0, _ := ret[0].(*admin.ClusterSearchIndex) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -164,10 +164,10 @@ func (m *MockSearchIndexUpdater) EXPECT() *MockSearchIndexUpdaterMockRecorder { } // UpdateSearchIndexes mocks base method. -func (m *MockSearchIndexUpdater) UpdateSearchIndexes(arg0, arg1, arg2 string, arg3 *admin.SearchIndexUpdateRequest) (*admin.SearchIndexResponse, error) { +func (m *MockSearchIndexUpdater) UpdateSearchIndexes(arg0, arg1, arg2 string, arg3 *admin.ClusterSearchIndex) (*admin.ClusterSearchIndex, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateSearchIndexes", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(*admin.SearchIndexResponse) + ret0, _ := ret[0].(*admin.ClusterSearchIndex) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/store/search.go b/internal/store/search.go index 8618c2178f..17a388da45 100644 --- a/internal/store/search.go +++ b/internal/store/search.go @@ -21,20 +21,20 @@ import ( //go:generate mockgen -destination=../mocks/mock_search.go -package=mocks github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store SearchIndexLister,SearchIndexCreator,SearchIndexDescriber,SearchIndexUpdater,SearchIndexDeleter type SearchIndexLister interface { - SearchIndexes(string, string, string, string) ([]atlasv2.SearchIndexResponse, error) + SearchIndexes(string, string, string, string) ([]atlasv2.ClusterSearchIndex, error) } type SearchIndexCreator interface { - CreateSearchIndexes(string, string, *atlasv2.SearchIndexCreateRequest) (*atlasv2.SearchIndexResponse, error) - SearchIndex(string, string, string) (*atlasv2.SearchIndexResponse, error) + CreateSearchIndexes(string, string, *atlasv2.ClusterSearchIndex) (*atlasv2.ClusterSearchIndex, error) + SearchIndex(string, string, string) (*atlasv2.ClusterSearchIndex, error) } type SearchIndexDescriber interface { - SearchIndex(string, string, string) (*atlasv2.SearchIndexResponse, error) + SearchIndex(string, string, string) (*atlasv2.ClusterSearchIndex, error) } type SearchIndexUpdater interface { - UpdateSearchIndexes(string, string, string, *atlasv2.SearchIndexUpdateRequest) (*atlasv2.SearchIndexResponse, error) + UpdateSearchIndexes(string, string, string, *atlasv2.ClusterSearchIndex) (*atlasv2.ClusterSearchIndex, error) } type SearchIndexDeleter interface { @@ -42,31 +42,31 @@ type SearchIndexDeleter interface { } // SearchIndexes encapsulate the logic to manage different cloud providers. -func (s *Store) SearchIndexes(projectID, clusterName, dbName, collName string) ([]atlasv2.SearchIndexResponse, error) { - result, _, err := s.clientv2.AtlasSearchApi.ListAtlasSearchIndexes(s.ctx, projectID, clusterName, collName, dbName).Execute() +func (s *Store) SearchIndexes(projectID, clusterName, dbName, collName string) ([]atlasv2.ClusterSearchIndex, error) { + result, _, err := s.clientv2.AtlasSearchApi.ListAtlasSearchIndexesDeprecated(s.ctx, projectID, clusterName, collName, dbName).Execute() return result, err } // CreateSearchIndexes encapsulate the logic to manage different cloud providers. -func (s *Store) CreateSearchIndexes(projectID, clusterName string, index *atlasv2.SearchIndexCreateRequest) (*atlasv2.SearchIndexResponse, error) { - result, _, err := s.clientv2.AtlasSearchApi.CreateAtlasSearchIndex(s.ctx, projectID, clusterName, index).Execute() +func (s *Store) CreateSearchIndexes(projectID, clusterName string, index *atlasv2.ClusterSearchIndex) (*atlasv2.ClusterSearchIndex, error) { + result, _, err := s.clientv2.AtlasSearchApi.CreateAtlasSearchIndexDeprecated(s.ctx, projectID, clusterName, index).Execute() return result, err } // SearchIndex encapsulate the logic to manage different cloud providers. -func (s *Store) SearchIndex(projectID, clusterName, indexID string) (*atlasv2.SearchIndexResponse, error) { - index, _, err := s.clientv2.AtlasSearchApi.GetAtlasSearchIndex(s.ctx, projectID, clusterName, indexID).Execute() +func (s *Store) SearchIndex(projectID, clusterName, indexID string) (*atlasv2.ClusterSearchIndex, error) { + index, _, err := s.clientv2.AtlasSearchApi.GetAtlasSearchIndexDeprecated(s.ctx, projectID, clusterName, indexID).Execute() return index, err } // UpdateSearchIndexes encapsulate the logic to manage different cloud providers. -func (s *Store) UpdateSearchIndexes(projectID, clusterName, indexID string, index *atlasv2.SearchIndexUpdateRequest) (*atlasv2.SearchIndexResponse, error) { - result, _, err := s.clientv2.AtlasSearchApi.UpdateAtlasSearchIndex(s.ctx, projectID, clusterName, indexID, index).Execute() +func (s *Store) UpdateSearchIndexes(projectID, clusterName, indexID string, index *atlasv2.ClusterSearchIndex) (*atlasv2.ClusterSearchIndex, error) { + result, _, err := s.clientv2.AtlasSearchApi.UpdateAtlasSearchIndexDeprecated(s.ctx, projectID, clusterName, indexID, index).Execute() return result, err } // DeleteSearchIndex encapsulate the logic to manage different cloud providers. func (s *Store) DeleteSearchIndex(projectID, clusterName, indexID string) error { - _, _, err := s.clientv2.AtlasSearchApi.DeleteAtlasSearchIndex(s.ctx, projectID, clusterName, indexID).Execute() + _, _, err := s.clientv2.AtlasSearchApi.DeleteAtlasSearchIndexDeprecated(s.ctx, projectID, clusterName, indexID).Execute() return err } diff --git a/test/e2e/atlas/search_nodes_test.go b/test/e2e/atlas/search_nodes_test.go index 0a694f487f..3ac8673e66 100644 --- a/test/e2e/atlas/search_nodes_test.go +++ b/test/e2e/atlas/search_nodes_test.go @@ -59,7 +59,7 @@ func TestSearchNodes(t *testing.T) { respStr := string(resp) require.Error(t, err, respStr) - require.Contains(t, respStr, "ATLAS_FTS_DEPLOYMENT_DOES_NOT_EXIST", respStr) + require.Contains(t, respStr, "ATLAS_SEARCH_DEPLOYMENT_DOES_NOT_EXIST", respStr) }) t.Run("Create search node", func(t *testing.T) { diff --git a/test/e2e/atlas/search_test.go b/test/e2e/atlas/search_test.go index dadbab8c59..42493de6c2 100644 --- a/test/e2e/atlas/search_test.go +++ b/test/e2e/atlas/search_test.go @@ -70,10 +70,8 @@ func TestSearch(t *testing.T) { "collectionName": "{{ .collectionName }}", "database": "test", "name": "{{ .indexName }}", - "definition": { - "mappings": { - "dynamic": true - } + "mappings": { + "dynamic": true } }`)) require.NoError(t, tpl.Execute(file, map[string]string{ @@ -95,7 +93,7 @@ func TestSearch(t *testing.T) { cmd.Env = os.Environ() resp, err := e2e.RunAndGetStdOut(cmd) require.NoError(t, err, string(resp)) - var index atlasv2.SearchIndexResponse + var index atlasv2.ClusterSearchIndex require.NoError(t, json.Unmarshal(resp, &index)) assert.Equal(t, index.GetName(), indexName) indexID = index.GetIndexID() @@ -114,7 +112,7 @@ func TestSearch(t *testing.T) { cmd.Env = os.Environ() resp, err := e2e.RunAndGetStdOut(cmd) require.NoError(t, err, string(resp)) - var index atlasv2.SearchIndexResponse + var index atlasv2.ClusterSearchIndex require.NoError(t, json.Unmarshal(resp, &index)) assert.Equal(t, indexID, index.GetIndexID()) }) @@ -128,13 +126,15 @@ func TestSearch(t *testing.T) { t.Cleanup(func() { require.NoError(t, os.Remove(fileName)) }) + tpl := template.Must(template.New("").Parse(` { - "definition": { - "analyzer": "{{ .analyzer }}", - "mappings": { - "dynamic": true - } + "collectionName": "{{ .collectionName }}", + "database": "test", + "name": "{{ .indexName }}", + "analyzer": "{{ .analyzer }}", + "mappings": { + "dynamic": true } }`)) require.NoError(t, tpl.Execute(file, map[string]string{ @@ -158,12 +158,11 @@ func TestSearch(t *testing.T) { cmd.Env = os.Environ() resp, err := e2e.RunAndGetStdOut(cmd) require.NoError(t, err, string(resp)) - var index atlasv2.SearchIndexResponse + var index atlasv2.ClusterSearchIndex require.NoError(t, json.Unmarshal(resp, &index)) a := assert.New(t) a.Equal(indexID, index.GetIndexID()) - def := index.GetLatestDefinition() - a.Equal(analyzer, def.GetAnalyzer()) + a.Equal(analyzer, index.GetAnalyzer()) }) t.Run("Delete", func(t *testing.T) { @@ -197,33 +196,31 @@ func TestSearch(t *testing.T) { "collectionName": "planets", "database": "sample_guides", "name": "{{ .indexName }}", - "definition": { - "analyzer": "lucene.standard", - "searchAnalyzer": "lucene.standard", - "mappings": { - "dynamic": false, - "fields": { - "name": { - "type": "string", - "analyzer": "lucene.whitespace", - "multi": { - "mySecondaryAnalyzer": { - "type": "string", - "analyzer": "lucene.french" - } - } - }, - "mainAtmosphere": { - "type": "string", - "analyzer": "lucene.standard" - }, - "surfaceTemperatureC": { - "type": "document", - "dynamic": true, - "analyzer": "lucene.standard" - } - } - } + "analyzer": "lucene.standard", + "searchAnalyzer": "lucene.standard", + "mappings": { + "dynamic": false, + "fields": { + "name": { + "type": "string", + "analyzer": "lucene.whitespace", + "multi": { + "mySecondaryAnalyzer": { + "type": "string", + "analyzer": "lucene.french" + } + } + }, + "mainAtmosphere": { + "type": "string", + "analyzer": "lucene.standard" + }, + "surfaceTemperatureC": { + "type": "document", + "dynamic": true, + "analyzer": "lucene.standard" + } + } } }`)) require.NoError(t, tpl.Execute(file, map[string]string{ @@ -244,9 +241,9 @@ func TestSearch(t *testing.T) { cmd.Env = os.Environ() resp, err := e2e.RunAndGetStdOut(cmd) require.NoError(t, err, string(resp)) - var index atlasv2.SearchIndexResponse + var index atlasv2.ClusterSearchIndex require.NoError(t, json.Unmarshal(resp, &index)) - assert.Equal(t, indexName, index.GetName()) + assert.Equal(t, indexName, index.Name) }) t.Run("Create staticMapping", func(t *testing.T) { @@ -263,73 +260,71 @@ func TestSearch(t *testing.T) { "collectionName": "posts", "database": "sample_training", "name": "{{ .indexName }}", - "definition": { - "analyzer": "lucene.standard", - "searchAnalyzer": "lucene.standard", - "mappings": { - "dynamic": false, - "fields": { - "comments": { - "type": "document", - "fields": { - "body": { - "type": "string", - "analyzer": "lucene.simple", - "ignoreAbove": 255 - }, - "author": { - "type": "string", - "analyzer": "keywordLowerCase" - } - } - }, - "body": { - "type": "string", - "analyzer": "lucene.whitespace", - "multi": { - "mySecondaryAnalyzer": { - "type": "string", - "analyzer": "keywordLowerCase" - } - } - }, - "tags": { - "type": "string", - "analyzer": "standardLowerCase" - } - } - }, - "analyzers":[ - { - "charFilters":[ - - ], - "name":"keywordLowerCase", - "tokenFilters":[ - { - "type":"lowercase" - } - ], - "tokenizer":{ - "type":"keyword" - } - }, - { - "charFilters":[ - - ], - "name":"standardLowerCase", - "tokenFilters":[ - { - "type":"lowercase" - } - ], - "tokenizer":{ - "type":"standard" - } - } - ] - } + "analyzer": "lucene.standard", + "searchAnalyzer": "lucene.standard", + "mappings": { + "dynamic": false, + "fields": { + "comments": { + "type": "document", + "fields": { + "body": { + "type": "string", + "analyzer": "lucene.simple", + "ignoreAbove": 255 + }, + "author": { + "type": "string", + "analyzer": "keywordLowerCase" + } + } + }, + "body": { + "type": "string", + "analyzer": "lucene.whitespace", + "multi": { + "mySecondaryAnalyzer": { + "type": "string", + "analyzer": "keywordLowerCase" + } + } + }, + "tags": { + "type": "string", + "analyzer": "standardLowerCase" + } + } + }, +"analyzers":[ + { + "charFilters":[ + + ], + "name":"keywordLowerCase", + "tokenFilters":[ + { + "type":"lowercase" + } + ], + "tokenizer":{ + "type":"keyword" + } + }, + { + "charFilters":[ + + ], + "name":"standardLowerCase", + "tokenFilters":[ + { + "type":"lowercase" + } + ], + "tokenizer":{ + "type":"standard" + } + } + ] }`)) require.NoError(t, tpl.Execute(file, map[string]string{ "indexName": indexName, @@ -349,9 +344,9 @@ func TestSearch(t *testing.T) { cmd.Env = os.Environ() resp, err := e2e.RunAndGetStdOut(cmd) require.NoError(t, err, string(resp)) - var index atlasv2.SearchIndexResponse + var index atlasv2.ClusterSearchIndex require.NoError(t, json.Unmarshal(resp, &index)) - assert.Equal(t, indexName, index.GetName()) + assert.Equal(t, indexName, index.Name) }) t.Run("Create array mapping", func(t *testing.T) { @@ -371,22 +366,20 @@ func TestSearch(t *testing.T) { "collectionName": "posts", "database": "sample_training", "name": "{{ .indexName }}", - "definition": { - "analyzer": "lucene.standard", - "searchAnalyzer": "lucene.standard", - "mappings": { - "dynamic": false, - "fields": { - "comments": [ - { - "dynamic": true, - "type": "document" - }, - { - "type": "string" - }] - } - } + "analyzer": "lucene.standard", + "searchAnalyzer": "lucene.standard", + "mappings": { + "dynamic": false, + "fields": { + "comments": [ + { + "dynamic": true, + "type": "document" + }, + { + "type": "string" + }] + } } }`)) require.NoError(t, tpl.Execute(file, map[string]string{ @@ -407,9 +400,9 @@ func TestSearch(t *testing.T) { cmd.Env = os.Environ() resp, err := e2e.RunAndGetStdOut(cmd) require.NoError(t, err, string(resp)) - var index atlasv2.SearchIndexResponse + var index atlasv2.ClusterSearchIndex require.NoError(t, json.Unmarshal(resp, &index)) - assert.Equal(t, indexName, index.GetName()) + assert.Equal(t, indexName, index.Name) }) t.Run("list", func(t *testing.T) { @@ -428,7 +421,7 @@ func TestSearch(t *testing.T) { resp, err := e2e.RunAndGetStdOut(cmd) require.NoError(t, err, string(resp)) - var indexes []atlasv2.SearchIndexResponse + var indexes []atlasv2.ClusterSearchIndex require.NoError(t, json.Unmarshal(resp, &indexes)) assert.NotEmpty(t, indexes) })