From 8c9b7c90bf819c55182ad33c1bba99425187dd26 Mon Sep 17 00:00:00 2001 From: Tommy Smith Date: Mon, 3 Jun 2024 10:27:59 +0100 Subject: [PATCH] Update schema to 1.25.2 refactoring tests to handle new field --- src/openapi/schema.ts | 2 ++ src/schema/journey.test.ts | 53 ++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/openapi/schema.ts b/src/openapi/schema.ts index a17803d5..8d574a3a 100644 --- a/src/openapi/schema.ts +++ b/src/openapi/schema.ts @@ -371,6 +371,8 @@ export interface definitions { enabled?: boolean; /** @description Nonexistent tenants should (not) be created implicitly */ autoTenantCreation?: boolean; + /** @description Existing tenants should (not) be turned HOT implicitly when they are accessed and in another activity status */ + autoTenantActivation?: boolean; }; /** @description JSON object value. */ JsonObject: { [key: string]: unknown }; diff --git a/src/schema/journey.test.ts b/src/schema/journey.test.ts index 42dd5421..0849987b 100644 --- a/src/schema/journey.test.ts +++ b/src/schema/journey.test.ts @@ -10,7 +10,7 @@ import { Meta, } from '../openapi/types.js'; -const is125 = (client: WeaviateClient) => +const isVer = (client: WeaviateClient, minor: number, patch: number) => client.misc .metaGetter() .do() @@ -20,7 +20,7 @@ const is125 = (client: WeaviateClient) => return false; } const semver = version.split('.').map((v) => parseInt(v, 10)); - return semver[1] >= 25; + return semver[1] >= minor && semver[2] >= patch; }); describe('schema', () => { @@ -29,7 +29,7 @@ describe('schema', () => { host: 'localhost:8080', }); - const classObjPromise = newClassObject('MyThingClass', is125(client)); + const classObjPromise = newClassObject('MyThingClass', isVer(client, 25, 0), isVer(client, 25, 2)); it('creates a thing class (implicitly)', async () => { const classObj = await classObjPromise; @@ -174,7 +174,7 @@ describe('schema', () => { it('updates all shards in a class', async () => { const shardCount = 3; - const newClass: any = await newClassObject('NewClass', is125(client)); + const newClass: any = await newClassObject('NewClass', isVer(client, 25, 0), isVer(client, 25, 2)); newClass.shardingConfig.desiredCount = shardCount; await client.schema @@ -217,7 +217,7 @@ describe('schema', () => { }); it('has updated values of bm25 config', async () => { - const newClass: any = await newClassObject('NewClass', is125(client)); + const newClass: any = await newClassObject('NewClass', isVer(client, 25, 0), isVer(client, 25, 2)); const bm25Config = { k1: 1.13, b: 0.222 }; newClass.invertedIndexConfig.bm25 = bm25Config; @@ -234,7 +234,7 @@ describe('schema', () => { }); it('has updated values of stopwords config', async () => { - const newClass: any = await newClassObject('SpaceClass', is125(client)); + const newClass: any = await newClassObject('SpaceClass', isVer(client, 25, 0), isVer(client, 25, 2)); const stopwordConfig: any = { preset: 'en', additions: ['star', 'nebula'], @@ -286,7 +286,7 @@ describe('schema', () => { it('creates a class with explicit replication config', async () => { const replicationFactor = 1; - const newClass: any = await newClassObject('SomeClass', is125(client)); + const newClass: any = await newClassObject('SomeClass', isVer(client, 25, 0), isVer(client, 25, 2)); newClass.replicationConfig.factor = replicationFactor; await client.schema @@ -301,7 +301,7 @@ describe('schema', () => { }); it('creates a class with implicit replication config', async () => { - const newClass: any = await newClassObject('SomeClass', is125(client)); + const newClass: any = await newClassObject('SomeClass', isVer(client, 25, 0), isVer(client, 25, 2)); delete newClass.replicationConfig; await client.schema @@ -316,8 +316,16 @@ describe('schema', () => { }); it('delete all data from the schema', async () => { - const newClass: any = await newClassObject('LetsDeleteThisClass', is125(client)); - const newClass2: any = await newClassObject('LetsDeleteThisClassToo', is125(client)); + const newClass: any = await newClassObject( + 'LetsDeleteThisClass', + isVer(client, 25, 0), + isVer(client, 25, 2) + ); + const newClass2: any = await newClassObject( + 'LetsDeleteThisClassToo', + isVer(client, 25, 0), + isVer(client, 25, 2) + ); const classNames = [newClass.class, newClass2.class]; Promise.all([ client.schema.classCreator().withClass(newClass).do(), @@ -593,6 +601,7 @@ describe('multi tenancy', () => { vectorIndexType: 'hnsw', vectorizer: 'text2vec-contextionary', multiTenancyConfig: { + autoTenantActivation: true, autoTenantCreation: true, enabled: true, }, @@ -600,9 +609,12 @@ describe('multi tenancy', () => { const tenants: Array = [{ name: 'tenantA' }, { name: 'tenantB' }, { name: 'tenantC' }]; it('creates a MultiTenancy class', async () => { - if (!(await is125(client))) { + if (!(await isVer(client, 25, 0))) { delete classObj.multiTenancyConfig?.autoTenantCreation; } + if (!(await isVer(client, 25, 2))) { + delete classObj.multiTenancyConfig?.autoTenantActivation; + } return client.schema .classCreator() .withClass(classObj) @@ -651,7 +663,7 @@ describe('multi tenancy', () => { }); it('successfully finds an existing tenant for MultiTenancy class', async () => { - if (!(await is125(client))) { + if (!(await isVer(client, 25, 0))) { return Promise.resolve(); } return client.schema @@ -661,7 +673,7 @@ describe('multi tenancy', () => { }); it('successfully fails to find a non-existant tenant for MultiTenancy class', async () => { - if (!(await is125(client))) { + if (!(await isVer(client, 25, 0))) { return Promise.resolve(); } return client.schema @@ -674,7 +686,11 @@ describe('multi tenancy', () => { return deleteClass(client, classObj.class!); }); - const classObjWithoutMultiTenancyConfig = newClassObject('NoMultiTenancy', is125(client)); + const classObjWithoutMultiTenancyConfig = newClassObject( + 'NoMultiTenancy', + isVer(client, 25, 0), + isVer(client, 25, 2) + ); it('creates a NoMultiTenancy class', async () => { return client.schema @@ -700,7 +716,11 @@ describe('multi tenancy', () => { }); }); -async function newClassObject(className: string, is125Promise: Promise) { +async function newClassObject( + className: string, + is1250Promise: Promise, + is1252Promise: Promise +) { return { class: className, properties: [ @@ -765,7 +785,8 @@ async function newClassObject(className: string, is125Promise: Promise) }, }, multiTenancyConfig: { - autoTenantCreation: (await is125Promise) ? false : undefined, + autoTenantActivation: (await is1252Promise) ? false : undefined, + autoTenantCreation: (await is1250Promise) ? false : undefined, enabled: false, }, shardingConfig: {