Skip to content

Commit

Permalink
Add json field and dynamic field test cases
Browse files Browse the repository at this point in the history
Signed-off-by: ThreadDao <[email protected]>
  • Loading branch information
ThreadDao committed Jul 31, 2023
1 parent c415da9 commit 46d007f
Show file tree
Hide file tree
Showing 17 changed files with 2,693 additions and 464 deletions.
86 changes: 43 additions & 43 deletions test/base/milvus_client.go

Large diffs are not rendered by default.

68 changes: 38 additions & 30 deletions test/common/response_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
)

// check err and errMsg
// CheckErr check err and errMsg
func CheckErr(t *testing.T, actualErr error, expErrNil bool, expErrorMsg ...string) {
if expErrNil {
require.NoError(t, actualErr)
Expand All @@ -23,13 +23,15 @@ func CheckErr(t *testing.T, actualErr error, expErrNil bool, expErrorMsg ...stri
}
}

// equal two fields
// EqualFields equal two fields
func EqualFields(t *testing.T, fieldA *entity.Field, fieldB *entity.Field) {
require.Equal(t, fieldA.Name, fieldB.Name)
require.Equal(t, fieldA.AutoID, fieldB.AutoID)
require.Equal(t, fieldA.PrimaryKey, fieldB.PrimaryKey)
require.Equal(t, fieldA.Description, fieldB.Description)
require.Equal(t, fieldA.DataType, fieldB.DataType)
require.Equal(t, fieldA.Name, fieldB.Name, fmt.Sprintf("Expected field name: %s, actual: %s", fieldA.Name, fieldB.Name))
require.Equal(t, fieldA.AutoID, fieldB.AutoID, fmt.Sprintf("Expected field AutoID: %t, actual: %t", fieldA.AutoID, fieldB.AutoID))
require.Equal(t, fieldA.PrimaryKey, fieldB.PrimaryKey, fmt.Sprintf("Expected field PrimaryKey: %t, actual: %t", fieldA.PrimaryKey, fieldB.PrimaryKey))
require.Equal(t, fieldA.Description, fieldB.Description, fmt.Sprintf("Expected field Description: %s, actual: %s", fieldA.Description, fieldB.Description))
require.Equal(t, fieldA.DataType, fieldB.DataType, fmt.Sprintf("Expected field DataType: %v, actual: %v", fieldA.DataType, fieldB.DataType))
require.Equal(t, fieldA.IsPartitionKey, fieldB.IsPartitionKey, fmt.Sprintf("Expected field IsPartitionKey: %t, actual: %t", fieldA.IsPartitionKey, fieldB.IsPartitionKey))
require.Equal(t, fieldA.IsDynamic, fieldB.IsDynamic, fmt.Sprintf("Expected field IsDynamic: %t, actual: %t", fieldA.IsDynamic, fieldB.IsDynamic))

// check vector field dim
switch fieldA.DataType {
Expand All @@ -47,27 +49,28 @@ func EqualFields(t *testing.T, fieldA *entity.Field, fieldB *entity.Field) {
//require.Equal(t, fieldA.IndexParams, fieldB.IndexParams)
}

// equal two schemas
// EqualSchema equal two schemas
func EqualSchema(t *testing.T, schemaA entity.Schema, schemaB entity.Schema) {
require.Equal(t, schemaA.CollectionName, schemaB.CollectionName)
require.Equal(t, schemaA.Description, schemaB.Description)
require.Equal(t, schemaA.AutoID, schemaB.AutoID)
require.Equal(t, len(schemaA.Fields), len(schemaB.Fields))
require.Equal(t, schemaA.CollectionName, schemaB.CollectionName, fmt.Sprintf("Expected schame CollectionName: %s, actual: %s", schemaA.CollectionName, schemaB.CollectionName))
require.Equal(t, schemaA.Description, schemaB.Description, fmt.Sprintf("Expected Description: %s, actual: %s", schemaA.Description, schemaB.Description))
require.Equal(t, schemaA.AutoID, schemaB.AutoID, fmt.Sprintf("Expected schema AutoID: %t, actual: %t", schemaA.AutoID, schemaB.AutoID))
require.Equal(t, len(schemaA.Fields), len(schemaB.Fields), fmt.Sprintf("Expected schame fields num: %d, actual: %d", len(schemaA.Fields), len(schemaB.Fields)))
require.Equal(t, schemaA.EnableDynamicField, schemaB.EnableDynamicField, fmt.Sprintf("Expected schame EnableDynamicField: %t, actual: %t", schemaA.EnableDynamicField, schemaB.EnableDynamicField))
for i := 0; i < len(schemaA.Fields); i++ {
EqualFields(t, schemaA.Fields[i], schemaB.Fields[i])
}
}

// check
// CheckCollection check collection
func CheckCollection(t *testing.T, actualCollection *entity.Collection, expCollName string, expShardNum int32,
expSchema *entity.Schema, expConsistencyLevel entity.ConsistencyLevel) {
require.Equal(t, expCollName, actualCollection.Name)
require.Equal(t, expShardNum, actualCollection.ShardNum)
require.Equal(t, expConsistencyLevel, actualCollection.ConsistencyLevel)
require.Equalf(t, expCollName, actualCollection.Name, fmt.Sprintf("Expected collection name: %s, actual: %v", expCollName, actualCollection.Name))
require.Equalf(t, expShardNum, actualCollection.ShardNum, fmt.Sprintf("Expected ShardNum: %d, actual: %d", expShardNum, actualCollection.ShardNum))
require.Equal(t, expConsistencyLevel, actualCollection.ConsistencyLevel, fmt.Sprintf("Expected ConsistencyLevel: %v, actual: %v", expConsistencyLevel, actualCollection.ConsistencyLevel))
EqualSchema(t, *expSchema, *actualCollection.Schema)
}

// check collections contains collName
// CheckContainsCollection check collections contains collName
func CheckContainsCollection(t *testing.T, collections []*entity.Collection, collName string) {
allCollNames := make([]string, 0, len(collections))
for _, collection := range collections {
Expand All @@ -76,7 +79,7 @@ func CheckContainsCollection(t *testing.T, collections []*entity.Collection, col
require.Containsf(t, allCollNames, collName, fmt.Sprintf("The collection %s not in: %v", collName, allCollNames))
}

// check collections not contains collName
// CheckNotContainsCollection check collections not contains collName
func CheckNotContainsCollection(t *testing.T, collections []*entity.Collection, collName string) {
allCollNames := make([]string, 0, len(collections))
for _, collection := range collections {
Expand All @@ -85,7 +88,7 @@ func CheckNotContainsCollection(t *testing.T, collections []*entity.Collection,
require.NotContainsf(t, allCollNames, collName, fmt.Sprintf("The collection %s should not be in: %v", collName, allCollNames))
}

// check insert result, ids len (insert count), ids data (pks, but no auto ids)
// CheckInsertResult check insert result, ids len (insert count), ids data (pks, but no auto ids)
func CheckInsertResult(t *testing.T, actualIds entity.Column, expIds entity.Column) {
require.Equal(t, actualIds.Len(), expIds.Len())
switch expIds.Type() {
Expand All @@ -99,7 +102,7 @@ func CheckInsertResult(t *testing.T, actualIds entity.Column, expIds entity.Colu
}
}

// check index result, index type, metric type, index params
// CheckIndexResult check index result, index type, metric type, index params
func CheckIndexResult(t *testing.T, actualIndexes []entity.Index, expIndexes ...entity.Index) {
mNameActualIndex := make(map[string]entity.Index)
allActualIndexNames := make([]string, 0, len(actualIndexes))
Expand All @@ -115,7 +118,7 @@ func CheckIndexResult(t *testing.T, actualIndexes []entity.Index, expIndexes ...
}
}

// assert field data is equal of two columns
// EqualColumn assert field data is equal of two columns
func EqualColumn(t *testing.T, columnA entity.Column, columnB entity.Column) {
require.Equal(t, columnA.Name(), columnB.Name())
require.Equal(t, columnA.Type(), columnB.Type())
Expand All @@ -136,6 +139,10 @@ func EqualColumn(t *testing.T, columnA entity.Column, columnB entity.Column) {
require.ElementsMatch(t, columnA.(*entity.ColumnDouble).Data(), columnB.(*entity.ColumnDouble).Data())
case entity.FieldTypeVarChar:
require.ElementsMatch(t, columnA.(*entity.ColumnVarChar).Data(), columnB.(*entity.ColumnVarChar).Data())
case entity.FieldTypeJSON:
log.Printf("columnA: %s", columnA.(*entity.ColumnJSONBytes).Data())
log.Printf("columnB: %s", columnB.(*entity.ColumnJSONBytes).Data())
require.ElementsMatch(t, columnA.(*entity.ColumnJSONBytes).Data(), columnB.(*entity.ColumnJSONBytes).Data())
case entity.FieldTypeFloatVector:
require.ElementsMatch(t, columnA.(*entity.ColumnFloatVector).Data(), columnB.(*entity.ColumnFloatVector).Data())
case entity.FieldTypeBinaryVector:
Expand All @@ -149,8 +156,7 @@ func EqualColumn(t *testing.T, columnA entity.Column, columnB entity.Column) {
}
}

// check query result, column name, type and field date
// expColumns are
// CheckQueryResult check query result, column name, type and field
func CheckQueryResult(t *testing.T, actualColumns []entity.Column, expColumns []entity.Column) {
require.GreaterOrEqual(t, len(actualColumns), len(expColumns),
"The len of actual columns %d should greater or equal to the expected columns %d", len(actualColumns), len(expColumns))
Expand All @@ -163,24 +169,26 @@ func CheckQueryResult(t *testing.T, actualColumns []entity.Column, expColumns []
}
}

// check query output fields
// CheckOutputFields check query output fields
func CheckOutputFields(t *testing.T, actualColumns []entity.Column, expFields []string) {
actualFields := make([]string, 0)
for _, actualColumn := range actualColumns {
log.Printf("column name: %s, column type: %s, column fieldData: %v",
actualColumn.Name(), actualColumn.Type(), actualColumn.FieldData())
actualFields = append(actualFields, actualColumn.Name())
}
require.ElementsMatch(t, actualFields, expFields)
require.ElementsMatchf(t, expFields, actualFields, fmt.Sprintf("Expected search output fields: %v, actual: %v", expFields, actualFields))
}

// check search result, check nq, topk, ids, score
func CheckSearchResult(t *testing.T, actualSearchResults []client.SearchResult, expNq int64, expTopk int64) {
// CheckSearchResult check search result, check nq, topk, ids, score
func CheckSearchResult(t *testing.T, actualSearchResults []client.SearchResult, expNq int, expTopk int) {
require.Equal(t, len(actualSearchResults), expNq)
for _, actualSearchResult := range actualSearchResults {
require.Equal(t, actualSearchResult.ResultCount, expTopk)
}
}

// check persistent segments
// CheckPersistentSegments check persistent segments
func CheckPersistentSegments(t *testing.T, actualSegments []*entity.Segment, expNb int64) {
actualNb := int64(0)
for _, segment := range actualSegments {
Expand All @@ -201,13 +209,13 @@ func getDbNames(dbs []entity.Database) []string {
return allDbNames
}

// check collections contains collName
// CheckContainsDb check collections contains collName
func CheckContainsDb(t *testing.T, dbs []entity.Database, dbName string) {
allDbNames := getDbNames(dbs)
require.Containsf(t, allDbNames, dbName, fmt.Sprintf("%s db not in dbs: %v", dbName, dbs))
}

// check collections contains collName
// CheckNotContainsDb check collections contains collName
func CheckNotContainsDb(t *testing.T, dbs []entity.Database, dbName string) {
allDbNames := getDbNames(dbs)
require.NotContainsf(t, allDbNames, dbName, fmt.Sprintf("%s db should not be in dbs: %v", dbName, dbs))
Expand Down
Loading

0 comments on commit 46d007f

Please sign in to comment.