github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/client/database_test.go (about)

     1  package client
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/go-faker/faker/v4"
     8  	"github.com/go-faker/faker/v4/pkg/options"
     9  	"github.com/golang/protobuf/proto"
    10  	"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
    11  	"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
    12  	"github.com/milvus-io/milvus-sdk-go/v2/entity"
    13  	"github.com/milvus-io/milvus-sdk-go/v2/merr"
    14  	"github.com/stretchr/testify/assert"
    15  )
    16  
    17  func TestGrpcClientListDatabases(t *testing.T) {
    18  	ctx := context.Background()
    19  	c := testClient(ctx, t)
    20  
    21  	type testCase struct {
    22  		DBName []string
    23  	}
    24  	caseList := []testCase{}
    25  	faker.FakeData(&caseList, options.WithRandomMapAndSliceMaxSize(25))
    26  
    27  	for _, singleCase := range caseList {
    28  		mockServer.SetInjection(MListDatabase, func(ctx context.Context, m proto.Message) (proto.Message, error) {
    29  			s, err := SuccessStatus()
    30  			resp := &milvuspb.ListDatabasesResponse{
    31  				Status:  s,
    32  				DbNames: singleCase.DBName,
    33  			}
    34  			return resp, err
    35  		})
    36  		dbNames, err := c.ListDatabases(ctx)
    37  		assert.Nil(t, err)
    38  		assert.Equal(t, len(singleCase.DBName), len(dbNames))
    39  		for i, db := range singleCase.DBName {
    40  			assert.Equal(t, db, dbNames[i].Name)
    41  		}
    42  	}
    43  }
    44  
    45  func TestGrpcClientCreateDatabase(t *testing.T) {
    46  	ctx := context.Background()
    47  	c := testClient(ctx, t)
    48  	mockServer.SetInjection(MCreateDatabase, func(ctx context.Context, m proto.Message) (proto.Message, error) {
    49  		return SuccessStatus()
    50  	})
    51  	err := c.CreateDatabase(ctx, "a", WithCreateDatabaseMsgBase(&commonpb.MsgBase{}))
    52  	assert.Nil(t, err)
    53  }
    54  
    55  func TestGrpcClientDropDatabase(t *testing.T) {
    56  	ctx := context.Background()
    57  	c := testClient(ctx, t)
    58  	mockServer.SetInjection(MDropDatabase, func(ctx context.Context, m proto.Message) (proto.Message, error) {
    59  		return SuccessStatus()
    60  	})
    61  	err := c.DropDatabase(ctx, "a", WithDropDatabaseMsgBase(&commonpb.MsgBase{}))
    62  	assert.Nil(t, err)
    63  }
    64  
    65  func TestGrpcClientAlterDatabase(t *testing.T) {
    66  	ctx := context.Background()
    67  	c := testClient(ctx, t)
    68  	mockServer.SetInjection(MAlterDatabase, func(ctx context.Context, m proto.Message) (proto.Message, error) {
    69  		return SuccessStatus()
    70  	})
    71  	err := c.AlterDatabase(ctx, "a", entity.DatabaseReplica(1), entity.DatabaseResourceGroups([]string{"a", "b", "c"}))
    72  	assert.Nil(t, err)
    73  }
    74  
    75  func TestGpcClientDescribeDatabase(t *testing.T) {
    76  	ctx := context.Background()
    77  	c := testClient(ctx, t)
    78  	mockServer.SetInjection(MDescribeDatabase, func(ctx context.Context, m proto.Message) (proto.Message, error) {
    79  		return &milvuspb.DescribeDatabaseResponse{
    80  			Status: merr.Success(),
    81  		}, nil
    82  	})
    83  	_, err := c.DescribeDatabase(ctx, "a")
    84  	assert.Nil(t, err)
    85  }