Skip to content

Commit

Permalink
add more test for http client
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid committed Dec 19, 2023
1 parent 8a78711 commit b44be7d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
6 changes: 3 additions & 3 deletions milvus/http/Vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export function Vector<T extends Constructor<HttpBaseClient>>(Base: T) {
async get(
params: HttpVectorGetReq,
options?: FetchOptions
): Promise<HttpBaseResponse> {
): Promise<HttpVectorQueryResponse> {
const url = `/vector/get`;
return await this.GET<HttpBaseResponse>(url, params, options);
return await this.POST<HttpVectorQueryResponse>(url, params, options);
}

// POST insert data
Expand All @@ -52,7 +52,7 @@ export function Vector<T extends Constructor<HttpBaseClient>>(Base: T) {
data: HttpVectorInsertReq,
options?: FetchOptions
): Promise<HttpVectorInsertResponse> {
const url = `/vector/insert`;
const url = `/vector/upsert`;
return await this.POST<HttpVectorInsertResponse>(url, data, options);
}

Expand Down
33 changes: 30 additions & 3 deletions test/http/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../tools';

export function generateTests(
config: HttpClientConfig & { address?: string; cloud?: boolean, desc: string }
config: HttpClientConfig & { address?: string; cloud?: boolean; desc: string }
) {
describe(config.desc, () => {
if (!config.cloud) {
Expand Down Expand Up @@ -42,7 +42,7 @@ export function generateTests(
dimension: 128,
};

const count = 10;
const count = 100;
const data = generateInsertData(
[
...genCollectionParams({
Expand Down Expand Up @@ -123,7 +123,18 @@ export function generateTests(
expect(insert.data.insertCount).toEqual(count);
});

it('should query data successfully', async () => {
// it('should upsert data successfully', async () => {
// const upsert = await client.upsert({
// collectionName: createParams.collectionName,
// data: data,
// });

// console.log(upsert);
// expect(upsert.code).toEqual(200);
// expect(upsert.data.insertCount).toEqual(count);
// });

it('should query data and get data and delete successfully', async () => {
const query = await client.query({
collectionName: createParams.collectionName,
outputFields: ['id'],
Expand All @@ -132,6 +143,22 @@ export function generateTests(

expect(query.code).toEqual(200);
expect(query.data.length).toEqual(data.length);

const ids = query.data.map(d => d.id);

const get = await client.get({
collectionName: createParams.collectionName,
id: ids,
outputFields: ['id', 'vector'],
});
expect(get.code).toEqual(200);
expect(get.data.length).toEqual(ids.length);

const del = await client.delete({
collectionName: createParams.collectionName,
id: ids,
});
expect(del.code).toEqual(200);
});

it('should search data successfully', async () => {
Expand Down

0 comments on commit b44be7d

Please sign in to comment.