-
Notifications
You must be signed in to change notification settings - Fork 3
Fix --tags not being applied to integrated indexes, refactor /index/create.go for unit tests
#51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,13 @@ import ( | |
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // Abstracts the Pinecone Go SDK for testing purposes | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interface abstraction to allow passing in a mock service to represent the SDK in unit tests. |
||
| type CreateIndexService interface { | ||
| CreateServerlessIndex(ctx context.Context, req *pinecone.CreateServerlessIndexRequest) (*pinecone.Index, error) | ||
| CreatePodIndex(ctx context.Context, req *pinecone.CreatePodIndexRequest) (*pinecone.Index, error) | ||
| CreateIndexForModel(ctx context.Context, req *pinecone.CreateIndexForModelRequest) (*pinecone.Index, error) | ||
| } | ||
|
|
||
| type indexType string | ||
|
|
||
| const ( | ||
|
|
@@ -138,16 +145,25 @@ func runCreateIndexCmd(options createIndexOptions) { | |
| ctx := context.Background() | ||
| pc := sdk.NewPineconeClient() | ||
|
|
||
| idx, err := runCreateIndexWithService(ctx, pc, options) | ||
| if err != nil { | ||
| msg.FailMsg("Failed to create index: %s\n", err) | ||
| exit.Error(err) | ||
| } | ||
|
|
||
| renderSuccessOutput(idx, options) | ||
| } | ||
|
|
||
| // This function plus the CreateIndexService interface allows for testing | ||
| func runCreateIndexWithService(ctx context.Context, service CreateIndexService, options createIndexOptions) (*pinecone.Index, error) { | ||
| // validate and derive index type from arguments | ||
| err := options.validate() | ||
| if err != nil { | ||
| exit.Error(err) | ||
| return | ||
| return nil, err | ||
| } | ||
| idxType, err := options.deriveIndexType() | ||
| if err != nil { | ||
| exit.Error(err) | ||
| return | ||
| return nil, err | ||
| } | ||
|
|
||
| // index tags | ||
|
|
@@ -175,10 +191,11 @@ func runCreateIndexCmd(options createIndexOptions) { | |
| SourceCollection: pointerOrNil(options.sourceCollection), | ||
| } | ||
|
|
||
| idx, err = pc.CreateServerlessIndex(ctx, &args) | ||
| idx, err = service.CreateServerlessIndex(ctx, &args) | ||
| if err != nil { | ||
| msg.FailMsg("Failed to create serverless index %s: %s\n", style.Emphasis(options.name), err) | ||
| exit.Error(err) | ||
| wrapped := pcio.Errorf("Failed to create serverless index %s: %w", style.Emphasis(options.name), err) | ||
| msg.FailMsg("%v", wrapped) | ||
| return nil, wrapped | ||
| } | ||
| case indexTypePod: | ||
| // create pod index | ||
|
|
@@ -202,10 +219,11 @@ func runCreateIndexCmd(options createIndexOptions) { | |
| MetadataConfig: metadataConfig, | ||
| } | ||
|
|
||
| idx, err = pc.CreatePodIndex(ctx, &args) | ||
| idx, err = service.CreatePodIndex(ctx, &args) | ||
| if err != nil { | ||
| msg.FailMsg("Failed to create pod index %s: %s\n", style.Emphasis(options.name), err) | ||
| exit.Error(err) | ||
| wrapped := pcio.Errorf("Failed to create pod index %s: %w", style.Emphasis(options.name), err) | ||
| msg.FailMsg("%v", wrapped) | ||
| return nil, wrapped | ||
| } | ||
| case indexTypeIntegrated: | ||
| // create integrated index | ||
|
|
@@ -223,20 +241,21 @@ func runCreateIndexCmd(options createIndexOptions) { | |
| ReadParameters: &readParams, | ||
| WriteParameters: &writeParams, | ||
| }, | ||
| Tags: indexTags, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the actual "fix" for the bug. |
||
| } | ||
|
|
||
| idx, err = pc.CreateIndexForModel(ctx, &args) | ||
| idx, err = service.CreateIndexForModel(ctx, &args) | ||
| if err != nil { | ||
| msg.FailMsg("Failed to create integrated index %s: %s\n", style.Emphasis(options.name), err) | ||
| exit.Error(err) | ||
| wrapped := pcio.Errorf("Failed to create integrated index %s: %w", style.Emphasis(options.name), err) | ||
| msg.FailMsg("%v", wrapped) | ||
| return nil, wrapped | ||
| } | ||
| default: | ||
| err := pcio.Errorf("invalid index type") | ||
| log.Error().Err(err).Msg("Error creating index") | ||
| exit.Error(err) | ||
| err := pcio.Errorf("Error creating index: invalid index type") | ||
| return nil, err | ||
| } | ||
|
|
||
| renderSuccessOutput(idx, options) | ||
| return idx, nil | ||
| } | ||
|
|
||
| func renderSuccessOutput(idx *pinecone.Index, options createIndexOptions) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulling this in mainly to use the
assertstuff for now, because I really don't want to bloat tests further with a bunch ofifstatements. Eventually would like to use testify for integration suites, etc.