Skip to content

Commit

Permalink
Experiment with condensing names into simply ts.IdxName
Browse files Browse the repository at this point in the history
  • Loading branch information
aulorbe committed Jul 26, 2024
1 parent 600c06b commit 8b79a56
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
40 changes: 20 additions & 20 deletions pinecone/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,12 @@ func (ts *IntegrationTests) TestCreateServerlessIndex() {
}

func (ts *IntegrationTests) TestDescribeServerlessIndex() {
if ts.serverlessIdxName == "" {
if ts.IdxName == "" {
ts.T().Skip("No serverless index to test")
}
index, err := ts.client.DescribeIndex(context.Background(), ts.serverlessIdxName)
index, err := ts.client.DescribeIndex(context.Background(), ts.IdxName)
require.NoError(ts.T(), err)
require.Equal(ts.T(), ts.serverlessIdxName, index.Name, "Index name does not match")
require.Equal(ts.T(), ts.IdxName, index.Name, "Index name does not match")
}

func (ts *IntegrationTests) TestDescribeNonExistentIndex() {
Expand All @@ -322,34 +322,34 @@ func (ts *IntegrationTests) TestDescribeNonExistentIndex() {
}

func (ts *IntegrationTests) TestDescribeServerlessIndexSourceTag() {
if ts.serverlessIdxName == "" {
if ts.IdxName == "" {
ts.T().Skip("No serverless index to test")
}
index, err := ts.clientSourceTag.DescribeIndex(context.Background(), ts.serverlessIdxName)
index, err := ts.clientSourceTag.DescribeIndex(context.Background(), ts.IdxName)
require.NoError(ts.T(), err)
require.Equal(ts.T(), ts.serverlessIdxName, index.Name, "Index name does not match")
require.Equal(ts.T(), ts.IdxName, index.Name, "Index name does not match")
}

func (ts *IntegrationTests) TestDescribePodIndex() {
if ts.podIdxName == "" {
if ts.IdxName == "" {
ts.T().Skip("No pod index to test")
}
index, err := ts.client.DescribeIndex(context.Background(), ts.podIdxName)
index, err := ts.client.DescribeIndex(context.Background(), ts.IdxName)
require.NoError(ts.T(), err)
require.Equal(ts.T(), ts.podIdxName, index.Name, "Index name does not match")
require.Equal(ts.T(), ts.IdxName, index.Name, "Index name does not match")
}

func (ts *IntegrationTests) TestDescribePodIndexSourceTag() {
if ts.podIdxName == "" {
if ts.IdxName == "" {
ts.T().Skip("No pod index to test")
}
index, err := ts.clientSourceTag.DescribeIndex(context.Background(), ts.podIdxName)
index, err := ts.clientSourceTag.DescribeIndex(context.Background(), ts.IdxName)
require.NoError(ts.T(), err)
require.Equal(ts.T(), ts.podIdxName, index.Name, "Index name does not match")
require.Equal(ts.T(), ts.IdxName, index.Name, "Index name does not match")
}

func (ts *IntegrationTests) TestListCollections() {
if ts.podIdxName == "" {
if ts.IdxName == "" {
ts.T().Skip("No pod index to test")
}
ctx := context.Background()
Expand All @@ -370,7 +370,7 @@ func (ts *IntegrationTests) TestListCollections() {
for _, name := range collectionNames {
_, err := ts.client.CreateCollection(ctx, &CreateCollectionRequest{
Name: name,
Source: ts.podIdxName,
Source: ts.IdxName,
})
require.NoError(ts.T(), err, "Error creating collection")
}
Expand All @@ -394,7 +394,7 @@ func (ts *IntegrationTests) TestListCollections() {
}

func (ts *IntegrationTests) TestDescribeCollection() {
if ts.podIdxName == "" {
if ts.IdxName == "" {
ts.T().Skip("No pod index to test")
}
ctx := context.Background()
Expand All @@ -407,7 +407,7 @@ func (ts *IntegrationTests) TestDescribeCollection() {

_, err := ts.client.CreateCollection(ctx, &CreateCollectionRequest{
Name: collectionName,
Source: ts.podIdxName,
Source: ts.IdxName,
})
require.NoError(ts.T(), err)

Expand All @@ -417,11 +417,11 @@ func (ts *IntegrationTests) TestDescribeCollection() {
}

func (ts *IntegrationTests) TestCreateCollection() {
if ts.podIdxName == "" {
if ts.IdxName == "" {
ts.T().Skip("No pod index to test")
}
name := uuid.New().String()
sourceIndex := ts.podIdxName
sourceIndex := ts.IdxName

defer func() {
err := ts.client.DeleteCollection(context.Background(), name)
Expand All @@ -437,13 +437,13 @@ func (ts *IntegrationTests) TestCreateCollection() {
}

func (ts *IntegrationTests) TestDeleteCollection() {
if ts.podIdxName == "" {
if ts.IdxName == "" {
ts.T().Skip("No pod index to test")
}
collectionName := uuid.New().String()
_, err := ts.client.CreateCollection(context.Background(), &CreateCollectionRequest{
Name: collectionName,
Source: ts.podIdxName,
Source: ts.IdxName,
})
require.NoError(ts.T(), err)

Expand Down
52 changes: 25 additions & 27 deletions pinecone/integration_test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ import (

type IntegrationTests struct {
suite.Suite
apiKey string
client *Client
host string
dimension int32
indexType string
vectorIds []string
podIdxName string
serverlessIdxName string
idxConn *IndexConnection
sourceTag string
clientSourceTag Client
idxConnSourceTag *IndexConnection
apiKey string
client *Client
host string
dimension int32
indexType string
vectorIds []string
IdxName string
idxConn *IndexConnection
sourceTag string
clientSourceTag Client
idxConnSourceTag *IndexConnection
}

func (ts *IntegrationTests) SetupSuite() {
Expand Down Expand Up @@ -81,8 +80,8 @@ func (ts *IntegrationTests) TearDownSuite() {
ctx := context.Background()

// Delete test indexes
err := ts.client.DeleteIndex(ctx, ts.serverlessIdxName)
err = ts.client.DeleteIndex(ctx, ts.podIdxName)
err := ts.client.DeleteIndex(ctx, ts.IdxName)
//err = ts.client.DeleteIndex(ctx, ts.podIdxName)

err = ts.idxConn.Close()
require.NoError(ts.T(), err)
Expand Down Expand Up @@ -120,37 +119,36 @@ func upsertVectors(ts *IntegrationTests, ctx context.Context, vectors []*Vector)
return nil
}

// TODO: how to get this func to work for client tests too
func GetIndexStatus(ts *IntegrationTests, ctx context.Context) (bool, error) {
var indexName string
if ts.indexType == "serverless" {
indexName = ts.serverlessIdxName
} else if ts.indexType == "pods" {
indexName = ts.podIdxName
}
if ts.client == nil {
return false, fmt.Errorf("client is nil")
}
//var indexName string
//if ts.IdxName == "serverless" {
// indexName = ts.serverlessIdxName
//} else if ts.indexType == "pods" {
// indexName = ts.podIdxName
//}
//if ts.client == nil {
// return false, fmt.Errorf("client is nil")
//}

var desc *Index
var err error
maxRetries := 12
delay := 12 * time.Second
for i := 0; i < maxRetries; i++ {
desc, err = ts.client.DescribeIndex(ctx, indexName)
desc, err = ts.client.DescribeIndex(ctx, ts.IdxName)
if err == nil {
break
}
if status.Code(err) == codes.Unknown {
fmt.Printf("Index \"%s\" not found, retrying... (%d/%d)\n", indexName, i+1, maxRetries)
fmt.Printf("Index \"%s\" not found, retrying... (%d/%d)\n", ts.IdxName, i+1, maxRetries)
time.Sleep(delay)
} else {
fmt.Printf("Status code = %v\n", status.Code(err))
return false, err
}
}
if err != nil {
return false, fmt.Errorf("failed to describe index \"%s\" after retries: %v", err, indexName)
return false, fmt.Errorf("failed to describe index \"%s\" after retries: %v", err, ts.IdxName)
}
return desc.Status.Ready, nil
}
Expand Down

0 comments on commit 8b79a56

Please sign in to comment.