github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/client/admin_test.go (about) 1 package client 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/golang/protobuf/proto" 8 common "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" 9 server "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb" 10 "github.com/milvus-io/milvus-sdk-go/v2/entity" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestCheckHealth(t *testing.T) { 15 ctx := context.Background() 16 c := testClient(ctx, t) 17 defer c.Close() 18 19 t.Run("test milvus healthy", func(t *testing.T) { 20 mockServer.SetInjection(MCheckHealth, func(ctx context.Context, message proto.Message) (proto.Message, error) { 21 resp := &server.CheckHealthResponse{ 22 Status: &common.Status{ErrorCode: common.ErrorCode_Success}, 23 IsHealthy: true, 24 Reasons: nil, 25 QuotaStates: nil, 26 } 27 return resp, nil 28 }) 29 defer mockServer.DelInjection(MCheckHealth) 30 31 resp, err := c.CheckHealth(ctx) 32 assert.Nil(t, err) 33 assert.True(t, resp.IsHealthy) 34 assert.Empty(t, resp.Reasons) 35 assert.Empty(t, resp.QuotaStates) 36 }) 37 38 t.Run("test milvus unhealthy", func(t *testing.T) { 39 mockServer.SetInjection(MCheckHealth, func(ctx context.Context, message proto.Message) (proto.Message, error) { 40 resp := &server.CheckHealthResponse{ 41 Status: &common.Status{ErrorCode: common.ErrorCode_Success}, 42 IsHealthy: false, 43 Reasons: []string{"some reason"}, 44 QuotaStates: []server.QuotaState{server.QuotaState_DenyToRead, server.QuotaState_DenyToWrite}, 45 } 46 return resp, nil 47 }) 48 defer mockServer.DelInjection(MCheckHealth) 49 50 resp, err := c.CheckHealth(ctx) 51 assert.Nil(t, err) 52 assert.False(t, resp.IsHealthy) 53 assert.ElementsMatch(t, resp.Reasons, []string{"some reason"}) 54 assert.ElementsMatch(t, resp.QuotaStates, []entity.QuotaState{entity.QuotaStateDenyToRead, entity.QuotaStateDenyToWrite}) 55 }) 56 57 }