-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Refactor pkg test helper functions (#1678)
* refactor charset helper func Signed-off-by: kevindiu <kevindiujp@gmail.com> * refactor vector helper func Signed-off-by: kevindiu <kevindiujp@gmail.com> * refactor request helper func Signed-off-by: kevindiu <kevindiujp@gmail.com> * add missing files Signed-off-by: kevindiu <kevindiujp@gmail.com> * move charset to conv Signed-off-by: kevindiu <kevindiujp@gmail.com> * return error from helper func Signed-off-by: kevindiu <kevindiujp@gmail.com> * refactor conv helper func Signed-off-by: kevindiu <kevindiujp@gmail.com> * refactor fill() and implement buildIndex() Signed-off-by: kevindiu <kevindiujp@gmail.com> * fix comment Signed-off-by: kevindiu <kevindiujp@gmail.com> * refactor convertXXX Signed-off-by: kevindiu <kevindiujp@gmail.com> * refactor search test func Signed-off-by: kevindiu <kevindiujp@gmail.com> * refactor beforeFunc test func to use buildIndex Signed-off-by: kevindiu <kevindiujp@gmail.com> * 🤖 Update license headers / Format go codes and yaml files Signed-off-by: Vdaas CI <vald@vdaas.org> * Revert "🤖 Update license headers / Format go codes and yaml files" This reverts commit a8b44c3. * format code Signed-off-by: kevindiu <kevindiujp@gmail.com> * fix comment Signed-off-by: kevindiu <kevindiujp@gmail.com> * implement test for helper functions Signed-off-by: kevindiu <kevindiujp@gmail.com> * add comments to helper functions Signed-off-by: kevindiu <kevindiujp@gmail.com> * implement conv test Signed-off-by: kevindiu <kevindiujp@gmail.com> * fix golangci warning Signed-off-by: kevindiu <kevindiujp@gmail.com> * fix comment Signed-off-by: kevindiu <kevindiujp@gmail.com> * fix golangci warning Signed-off-by: kevindiu <kevindiujp@gmail.com> * split encode() Signed-off-by: kevindiu <kevindiujp@gmail.com> * implement boundary value test for vector/gen Signed-off-by: kevindiu <kevindiujp@gmail.com> * use io instead of ioutil package Signed-off-by: kevindiu <kevindiujp@gmail.com> * Update internal/conv/conv_test.go Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * add boundary tests Signed-off-by: kevindiu <kevindiujp@gmail.com> * fix test error Signed-off-by: kevindiu <kevindiujp@gmail.com> * add more boundary tests Signed-off-by: kevindiu <kevindiujp@gmail.com> Co-authored-by: Vdaas CI <vald@vdaas.org> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
815b44a
commit 626c706
Showing
10 changed files
with
2,272 additions
and
693 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Copyright (C) 2019-2022 vdaas.org vald team <vald@vdaas.org> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
// Package request provides functions to generate proto request for testing | ||
package request |
This file contains 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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// Copyright (C) 2019-2022 vdaas.org vald team <vald@vdaas.org> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
package request | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/vdaas/vald/apis/grpc/v1/payload" | ||
"github.com/vdaas/vald/internal/test/data/vector" | ||
) | ||
|
||
type ObjectType int | ||
|
||
const ( | ||
Uint8 ObjectType = iota | ||
Float | ||
) | ||
|
||
func GenMultiInsertReq(t ObjectType, dist vector.Distribution, num int, dim int, cfg *payload.Insert_Config) (*payload.Insert_MultiRequest, error) { | ||
var vecs [][]float32 | ||
var err error | ||
switch t { | ||
case Float: | ||
vecs, err = vector.GenF32Vec(dist, num, dim) | ||
case Uint8: | ||
vecs, err = vector.GenUint8Vec(dist, num, dim) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req := &payload.Insert_MultiRequest{ | ||
Requests: make([]*payload.Insert_Request, num), | ||
} | ||
for i, vec := range vecs { | ||
req.Requests[i] = &payload.Insert_Request{ | ||
Vector: &payload.Object_Vector{ | ||
Id: "uuid-" + strconv.Itoa(i+1), | ||
Vector: vec, | ||
}, | ||
Config: cfg, | ||
} | ||
} | ||
|
||
return req, nil | ||
} | ||
|
||
// generate MultiInsert request with the same vector | ||
func GenSameVecMultiInsertReq(num int, vec []float32, cfg *payload.Insert_Config) *payload.Insert_MultiRequest { | ||
req := &payload.Insert_MultiRequest{ | ||
Requests: make([]*payload.Insert_Request, num), | ||
} | ||
for i := 0; i < num; i++ { | ||
req.Requests[i] = &payload.Insert_Request{ | ||
Vector: &payload.Object_Vector{ | ||
Id: "uuid-" + strconv.Itoa(i+1), | ||
Vector: vec, | ||
}, | ||
Config: cfg, | ||
} | ||
} | ||
|
||
return req | ||
} |
Oops, something went wrong.