Browse Source

Move __mocks__ to __tests__ folder

tumao 3 years ago
parent
commit
a6e241ec5f

+ 1 - 1
express/package.json

@@ -84,4 +84,4 @@
     ],
     "ext": "ts yml"
   }
-}
+}

+ 165 - 0
express/src/__tests__/__mocks__/consts.ts

@@ -0,0 +1,165 @@
+// mock data
+export const mockAddress = '127.0.0.1';
+export const mockCollectionNames = [{ name: 'c1' }, { name: 'c2' }];
+export const mockCollections = [
+  {
+    name: 'c1',
+    collectionID: 1,
+    schema: {
+      fields: [
+        {
+          name: 'vector_field',
+          data_type: 'data_type',
+          type_params: [
+            {
+              key: 'dim',
+              value: '4',
+            },
+          ],
+        },
+        {
+          is_primary_key: true,
+          autoID: true,
+          name: 'age',
+          data_type: 'data_type',
+          type_params: [] as any[],
+        },
+      ],
+      description: 'mock schema description 1',
+    },
+    created_utc_timestamp: '123456',
+  },
+  {
+    name: 'c2',
+    collectionID: 2,
+    schema: {
+      fields: [
+        {
+          name: 'vector_field',
+          data_type: 'data_type',
+          type_params: [
+            {
+              key: 'dim',
+              value: '4',
+            },
+          ],
+        },
+        {
+          name: 'age',
+          data_type: 'data_type',
+          type_params: [] as any[],
+        },
+      ],
+      description: 'mock schema description 2',
+    },
+    created_utc_timestamp: '1234567',
+  },
+];
+export const mockLoadedCollections = [
+  {
+    id: 1,
+    name: 'c1',
+    loadedPercentage: '100',
+  },
+];
+// index state is finished
+export const mockIndexState = [
+  { collection_name: 'c1', state: 3 },
+  { collection_name: 'c2', state: 2 },
+];
+
+export const mockPartition = {
+  partition_names: ['p1', 'p2'],
+  partitionIDs: [1, 2],
+  created_timestamps: ['12345', '12354'],
+  created_utc_timestamps: ['12345', '12354'],
+};
+
+// mock results
+export const mockGetAllCollectionsData = [
+  {
+    collection_name: 'c2',
+    schema: {
+      fields: [
+        {
+          name: 'vector_field',
+          data_type: 'data_type',
+          type_params: [
+            {
+              key: 'dim',
+              value: '4',
+            },
+          ],
+        },
+        {
+          name: 'age',
+          data_type: 'data_type',
+          type_params: [] as any[],
+        },
+      ],
+      description: 'mock schema description 2',
+    },
+    description: 'mock schema description 2',
+    autoID: undefined as boolean,
+    rowCount: 7,
+    id: 2,
+    loadedPercentage: '-1',
+    createdTime: 1234567,
+    index_status: 2,
+  },
+  {
+    collection_name: 'c1',
+    schema: {
+      fields: [
+        {
+          name: 'vector_field',
+          data_type: 'data_type',
+          type_params: [
+            {
+              key: 'dim',
+              value: '4',
+            },
+          ],
+        },
+        {
+          is_primary_key: true,
+          autoID: true,
+          name: 'age',
+          data_type: 'data_type',
+          type_params: [] as any[],
+        },
+      ],
+      description: 'mock schema description 1',
+    },
+    description: 'mock schema description 1',
+    autoID: true,
+    rowCount: 7,
+    id: 1,
+    loadedPercentage: '100',
+    createdTime: 123456,
+    index_status: 3,
+  },
+];
+
+export const mockLoadedCollectionsData = [
+  {
+    collection_name: 'c1',
+    id: 1,
+    rowCount: 7,
+  },
+];
+
+export const mockGetPartitionsInfoData = [
+  {
+    name: 'p1',
+    id: 1,
+    createdTime: '12345',
+    rowCount: 7,
+  },
+  {
+    name: 'p2',
+    id: 2,
+    createdTime: '12354',
+    rowCount: 7,
+  },
+];

+ 5 - 3
express/src/__mocks__/milvus/milvusClient.ts → express/src/__tests__/__mocks__/milvus/milvusClient.ts

@@ -24,7 +24,7 @@ import {
   ShowCollectionsReq,
   ShowPartitionsReq,
 } from '@zilliz/milvus2-sdk-node/dist/milvus/types';
-import { QueryDto } from '../../collections/dto';
+import { QueryDto } from '../../../collections/dto';
 import {
   CodeEnum,
   ERR_NO_ADDRESS,
@@ -32,13 +32,15 @@ import {
   ERR_NO_COLLECTION,
   ERR_NO_INDEX,
   ERR_NO_PARAM,
+} from '../../utils/constants';
+import { mockStatusInfo } from '../../utils/mock.util';
+import {
   mockCollectionNames,
   mockCollections,
   mockIndexState,
   mockLoadedCollections,
   mockPartition,
-} from '../../__tests__/utils/constants';
-import { mockStatusInfo } from '../../__tests__/utils/mock.util';
+} from '../consts';
 
 const mockMilvusClient = jest.fn().mockImplementation((address: string) => {
   return {

+ 0 - 0
express/src/__mocks__/milvus/milvus.service.ts → express/src/__tests__/__mocks__/milvus/milvusService.ts


+ 4 - 2
express/src/__tests__/collections/collections.service.test.ts

@@ -1,17 +1,19 @@
-import mockMilvusClient from '../../__mocks__/milvus/milvusClient';
+import mockMilvusClient from '../__mocks__/milvus/milvusClient';
 import { CollectionsService } from '../../collections/collections.service';
 import { MilvusService } from '../../milvus/milvus.service';
 import {
   ERR_NO_ALIAS,
   ERR_NO_COLLECTION,
   ERR_NO_PARAM,
+} from '../utils/constants';
+import {
   mockAddress,
   mockCollectionNames,
   mockCollections,
   mockGetAllCollectionsData,
   mockLoadedCollections,
   mockLoadedCollectionsData,
-} from '../utils/constants';
+} from '../__mocks__/consts';
 
 // mock Milvus client
 jest.mock('@zilliz/milvus2-sdk-node', () => {

+ 2 - 2
express/src/__tests__/crons/crons.service.test.ts

@@ -1,10 +1,10 @@
-import mockMilvusClient from '../../__mocks__/milvus/milvusClient';
+import mockMilvusClient from '../__mocks__/milvus/milvusClient';
 import { schedule } from 'node-cron';
 import { CollectionsService } from '../../collections/collections.service';
 import { CronsService, SchedulerRegistry } from '../../crons/crons.service';
 import { MilvusService } from '../../milvus/milvus.service';
-import { mockAddress } from '../utils/constants';
 import { WS_EVENTS, WS_EVENTS_TYPE } from '../../utils/Const';
+import { mockAddress } from '../__mocks__/consts';
 
 // mock Milvus client
 jest.mock('@zilliz/milvus2-sdk-node', () => {

+ 3 - 4
express/src/__tests__/milvus/milvus.controller.test.ts

@@ -3,13 +3,12 @@ import http from 'http';
 import supertest from 'supertest';
 import { TransformResMiddlerware } from '../../middlewares';
 import { router as connectRouter } from '../../milvus/index';
+import { mockAddress } from '../__mocks__/consts';
 
-import MilvusService from '../../__mocks__/milvus/milvus.service';
-import { mockAddress } from '../utils/constants';
-
+import MilvusService from '../__mocks__/milvus/milvusService';
 
 // mock Milvus client service
-jest.mock('../../__mocks__/milvus/milvus.service');
+jest.mock('../__mocks__/milvus/milvusService');
 
 describe('Test Milvus Module', () => {
   let app: any;

+ 2 - 3
express/src/__tests__/milvus/milvus.service.test.ts

@@ -1,7 +1,6 @@
-import mockMilvusClient from '../../__mocks__/milvus/milvusClient';
+import mockMilvusClient from '../__mocks__/milvus/milvusClient';
 import { MilvusService } from '../../milvus/milvus.service';
-import { mockAddress } from '../utils/constants';
-
+import { mockAddress } from '../__mocks__/consts';
 
 // mock Milvus client
 jest.mock('@zilliz/milvus2-sdk-node', () => {

+ 4 - 4
express/src/__tests__/partitions/partitions.service.test.ts

@@ -1,12 +1,12 @@
-import mockMilvusClient from '../../__mocks__/milvus/milvusClient';
+import mockMilvusClient from '../__mocks__/milvus/milvusClient';
 import { MilvusService } from '../../milvus/milvus.service';
+import { ERR_NO_COLLECTION } from '../utils/constants';
+import { PartitionsService } from '../../partitions/partitions.service';
 import {
-  ERR_NO_COLLECTION,
   mockAddress,
   mockGetPartitionsInfoData,
   mockPartition,
-} from '../utils/constants';
-import { PartitionsService } from '../../partitions/partitions.service';
+} from '../__mocks__/consts';
 
 // mock Milvus client
 jest.mock('@zilliz/milvus2-sdk-node', () => {

+ 3 - 2
express/src/__tests__/schema/schema.service.test.ts

@@ -1,7 +1,8 @@
-import mockMilvusClient from '../../__mocks__/milvus/milvusClient';
+import mockMilvusClient from '../__mocks__/milvus/milvusClient';
 import { MilvusService } from '../../milvus/milvus.service';
-import { CodeEnum, ERR_NO_COLLECTION, mockAddress } from '../utils/constants';
+import { CodeEnum, ERR_NO_COLLECTION } from '../utils/constants';
 import { SchemaService } from '../../schema/schema.service';
+import { mockAddress } from '../__mocks__/consts';
 
 // mock Milvus client
 jest.mock('@zilliz/milvus2-sdk-node', () => {

+ 0 - 166
express/src/__tests__/utils/constants.ts

@@ -15,169 +15,3 @@ export const ERR_NO_ADDRESS = 'no address';
 export const ERR_NO_PARAM = 'no valid param';
 export const ERR_NO_ALIAS = 'no valid alias';
 export const ERR_NO_INDEX = 'index not exist';
-
-// mock data
-export const mockAddress = '127.0.0.1';
-export const mockCollectionNames = [{ name: 'c1' }, { name: 'c2' }];
-export const mockCollections = [
-  {
-    name: 'c1',
-    collectionID: 1,
-    schema: {
-      fields: [
-        {
-          name: 'vector_field',
-          data_type: 'data_type',
-          type_params: [
-            {
-              key: 'dim',
-              value: '4',
-            },
-          ],
-        },
-        {
-          is_primary_key: true,
-          autoID: true,
-          name: 'age',
-          data_type: 'data_type',
-          type_params: [] as any[],
-        },
-      ],
-      description: 'mock schema description 1',
-    },
-    created_utc_timestamp: '123456',
-  },
-  {
-    name: 'c2',
-    collectionID: 2,
-    schema: {
-      fields: [
-        {
-          name: 'vector_field',
-          data_type: 'data_type',
-          type_params: [
-            {
-              key: 'dim',
-              value: '4',
-            },
-          ],
-        },
-        {
-          name: 'age',
-          data_type: 'data_type',
-          type_params: [] as any[],
-        },
-      ],
-      description: 'mock schema description 2',
-    },
-    created_utc_timestamp: '1234567',
-  },
-];
-export const mockLoadedCollections = [
-  {
-    id: 1,
-    name: 'c1',
-    loadedPercentage: '100',
-  },
-];
-// index state is finished
-export const mockIndexState = [
-  { collection_name: 'c1', state: 3 },
-  { collection_name: 'c2', state: 2 },
-];
-
-export const mockPartition = {
-  partition_names: ['p1', 'p2'],
-  partitionIDs: [1, 2],
-  created_timestamps: ['12345', '12354'],
-  created_utc_timestamps: ['12345', '12354'],
-};
-
-// mock results
-export const mockGetAllCollectionsData = [
-  {
-    collection_name: 'c2',
-    schema: {
-      fields: [
-        {
-          name: 'vector_field',
-          data_type: 'data_type',
-          type_params: [
-            {
-              key: 'dim',
-              value: '4',
-            },
-          ],
-        },
-        {
-          name: 'age',
-          data_type: 'data_type',
-          type_params: [] as any[],
-        },
-      ],
-      description: 'mock schema description 2',
-    },
-    description: 'mock schema description 2',
-    autoID: undefined as boolean,
-    rowCount: 7,
-    id: 2,
-    loadedPercentage: '-1',
-    createdTime: 1234567,
-    index_status: 2,
-  },
-  {
-    collection_name: 'c1',
-    schema: {
-      fields: [
-        {
-          name: 'vector_field',
-          data_type: 'data_type',
-          type_params: [
-            {
-              key: 'dim',
-              value: '4',
-            },
-          ],
-        },
-        {
-          is_primary_key: true,
-          autoID: true,
-          name: 'age',
-          data_type: 'data_type',
-          type_params: [] as any[],
-        },
-      ],
-      description: 'mock schema description 1',
-    },
-    description: 'mock schema description 1',
-    autoID: true,
-    rowCount: 7,
-    id: 1,
-    loadedPercentage: '100',
-    createdTime: 123456,
-    index_status: 3,
-  },
-];
-
-export const mockLoadedCollectionsData = [
-  {
-    collection_name: 'c1',
-    id: 1,
-    rowCount: 7,
-  },
-];
-
-export const mockGetPartitionsInfoData = [
-  {
-    name: 'p1',
-    id: 1,
-    createdTime: '12345',
-    rowCount: 7,
-  },
-  {
-    name: 'p2',
-    id: 2,
-    createdTime: '12354',
-    rowCount: 7,
-  },
-];