diff --git a/packages/client-sdk-nodejs/test/integration/integration-setup.ts b/packages/client-sdk-nodejs/test/integration/integration-setup.ts index 8b031830c..b018aaccf 100644 --- a/packages/client-sdk-nodejs/test/integration/integration-setup.ts +++ b/packages/client-sdk-nodejs/test/integration/integration-setup.ts @@ -1,4 +1,9 @@ -import {testCacheName} from '@gomomento/common-integration-tests'; +import { + createStoreIfNotExists, + deleteStoreIfExists, + testCacheName, + testStoreName, +} from '@gomomento/common-integration-tests'; import { AuthClient, CreateCache, @@ -247,10 +252,22 @@ export function SetupTopicIntegrationTest(): { export function SetupStorageIntegrationTest(): { storageClient: PreviewStorageClient; + integrationTestStoreName: string; } { + const integrationTestStoreName = testStoreName(); const storageClient = momentoStorageClientForTesting(); + + beforeAll(async () => { + await createStoreIfNotExists(storageClient, integrationTestStoreName); + }); + + afterAll(async () => { + await deleteStoreIfExists(storageClient, integrationTestStoreName); + }); + return { storageClient, + integrationTestStoreName, }; } diff --git a/packages/client-sdk-nodejs/test/integration/shared/storage/storage.test.ts b/packages/client-sdk-nodejs/test/integration/shared/storage/storage.test.ts index 39a17d282..e73711e51 100644 --- a/packages/client-sdk-nodejs/test/integration/shared/storage/storage.test.ts +++ b/packages/client-sdk-nodejs/test/integration/shared/storage/storage.test.ts @@ -1,5 +1,5 @@ import {runStorageServiceTests} from '@gomomento/common-integration-tests'; import {SetupStorageIntegrationTest} from '../../integration-setup'; -const {storageClient} = SetupStorageIntegrationTest(); -runStorageServiceTests(storageClient); +const {storageClient, integrationTestStoreName} = SetupStorageIntegrationTest(); +runStorageServiceTests(storageClient, integrationTestStoreName); diff --git a/packages/client-sdk-web/test/integration/integration-setup.ts b/packages/client-sdk-web/test/integration/integration-setup.ts index 13f1b3c16..27cda6b1d 100644 --- a/packages/client-sdk-web/test/integration/integration-setup.ts +++ b/packages/client-sdk-web/test/integration/integration-setup.ts @@ -3,6 +3,9 @@ import { testCacheName, isLocalhostDevelopmentMode, createCacheIfNotExists, + testStoreName, + deleteStoreIfExists, + createStoreIfNotExists, } from '@gomomento/common-integration-tests'; import { CreateCache, @@ -235,10 +238,22 @@ export function SetupTopicIntegrationTest(): { export function SetupStorageIntegrationTest(): { storageClient: IStorageClient; + integrationTestStoreName: string; } { + const integrationTestStoreName = testStoreName(); const storageClient = momentoStorageClientForTesting(); + + beforeAll(async () => { + await createStoreIfNotExists(storageClient, integrationTestStoreName); + }); + + afterAll(async () => { + await deleteStoreIfExists(storageClient, integrationTestStoreName); + }); + return { storageClient, + integrationTestStoreName, }; } diff --git a/packages/client-sdk-web/test/integration/shared/storage/storage.test.ts b/packages/client-sdk-web/test/integration/shared/storage/storage.test.ts index 3e7545c94..45fb44ece 100644 --- a/packages/client-sdk-web/test/integration/shared/storage/storage.test.ts +++ b/packages/client-sdk-web/test/integration/shared/storage/storage.test.ts @@ -1,6 +1,6 @@ import {runStorageServiceTests} from '@gomomento/common-integration-tests'; import {SetupStorageIntegrationTest} from '../../integration-setup'; -const {storageClient} = SetupStorageIntegrationTest(); +const {storageClient, integrationTestStoreName} = SetupStorageIntegrationTest(); -runStorageServiceTests(storageClient); +runStorageServiceTests(storageClient, integrationTestStoreName); diff --git a/packages/common-integration-tests/src/storage/storage.ts b/packages/common-integration-tests/src/storage/storage.ts index 77ba0bdd0..aa3d460c5 100644 --- a/packages/common-integration-tests/src/storage/storage.ts +++ b/packages/common-integration-tests/src/storage/storage.ts @@ -15,7 +15,10 @@ import { } from '../common-int-test-utils'; import {v4} from 'uuid'; -export function runStorageServiceTests(storageClient: IStorageClient) { +export function runStorageServiceTests( + storageClient: IStorageClient, + testingStoreName: string +): void { describe('#create list and delete stores', () => { it('creates a store, lists it and makes sure it exists, and then deletes it', async () => { const storeName = testStoreName(); @@ -67,162 +70,26 @@ export function runStorageServiceTests(storageClient: IStorageClient) { }); it('should return AlreadyExists response if trying to create a store that already exists', async () => { const storeName = testStoreName(); - const createResponse = await storageClient.createStore(storeName); - switch (createResponse.type) { - // this is the expected response - case CreateStoreResponse.Success: { - break; - } - case CreateStoreResponse.AlreadyExists: { - break; - } - case CreateStoreResponse.Error: { - throw new Error( - `failed to create store, expected store to be able to happen, error: ${createResponse.message()} exception: ${createResponse.toString()}` - ); - } - } - const alreadyExistResponse = await storageClient.createStore(storeName); - switch (alreadyExistResponse.type) { - case CreateStoreResponse.AlreadyExists: { - break; - } - case CreateStoreResponse.Error: { - throw new Error( - `failed to create store, expected AlreadyExists response, error: ${alreadyExistResponse.message()} exception: ${alreadyExistResponse.toString()}` - ); - } - case CreateStoreResponse.Success: { - throw new Error( - 'store already exists, we should not be able to create it again' - ); - } - } - await storageClient.deleteStore(storeName); - }); - }); - describe('#store get put and delete', () => { - it('put get and delete key in a store', async () => { - const storeName = testStoreName(); + // WithStore creates a store then deletes it await WithStore(storageClient, storeName, async () => { - const key = v4(); - - // put/get an int value - const intValue = 42; - const putIntResponse = await storageClient.putInt( - storeName, - key, - intValue - ); - switch (putIntResponse.type) { - case StoragePutResponse.Success: { - break; - } - case StoragePutResponse.Error: { - throw new Error( - `failed to put key: ${putIntResponse.message()} ${putIntResponse.toString()}` - ); - } - } - const getIntResponse = await storageClient.get(storeName, key); - expectWithMessage(() => { - expect(getIntResponse.type).toEqual(StorageGetResponse.Found); - }, `expected Found, received ${getIntResponse.toString()}`); - expect(getIntResponse.value()?.int()).toEqual(intValue); - - // put/get a double value - const doubleValue = 42.42; - const putDoubleResponse = await storageClient.putDouble( - storeName, - key, - doubleValue - ); - switch (putDoubleResponse.type) { - case StoragePutResponse.Success: { - break; - } - case StoragePutResponse.Error: { - throw new Error( - `failed to put key: ${putDoubleResponse.message()} ${putDoubleResponse.toString()}` - ); - } - } - const getDoubleResponse = await storageClient.get(storeName, key); - expectWithMessage(() => { - expect(getDoubleResponse.type).toEqual(StorageGetResponse.Found); - }, `expected Found, received ${getDoubleResponse.toString()}`); - expect(getDoubleResponse.value()?.double()).toEqual(doubleValue); - - // put/get a string value - const stringValue = v4(); - const putStringResponse = await storageClient.putString( - storeName, - key, - stringValue - ); - switch (putStringResponse.type) { - case StoragePutResponse.Success: { + const alreadyExistResponse = await storageClient.createStore(storeName); + switch (alreadyExistResponse.type) { + case CreateStoreResponse.AlreadyExists: { break; } - case StoragePutResponse.Error: { + case CreateStoreResponse.Error: { throw new Error( - `failed to put key: ${putStringResponse.message()} ${putStringResponse.toString()}` + `failed to create store, expected AlreadyExists response, error: ${alreadyExistResponse.message()} exception: ${alreadyExistResponse.toString()}` ); } - } - const getStringResponse = await storageClient.get(storeName, key); - expectWithMessage(() => { - expect(getStringResponse.type).toEqual(StorageGetResponse.Found); - }, `expected Found, received ${getStringResponse.toString()}`); - expect(getStringResponse.value()?.string()).toEqual(stringValue); - - // put/get a bytes value - const bytesValue = new Uint8Array([1, 2, 3, 4]); - const putBytesResponse = await storageClient.putBytes( - storeName, - key, - bytesValue - ); - switch (putBytesResponse.type) { - case StoragePutResponse.Success: { - break; - } - case StoragePutResponse.Error: { + case CreateStoreResponse.Success: { throw new Error( - `failed to put key: ${putBytesResponse.message()} ${putBytesResponse.toString()}` - ); - } - } - const getBytesResponse = await storageClient.get(storeName, key); - expectWithMessage(() => { - expect(getBytesResponse.type).toEqual(StorageGetResponse.Found); - }, `expected Found, received ${getBytesResponse.toString()}`); - expect(getBytesResponse.value()?.bytes()).toEqual(bytesValue); - - const deleteResponse = await storageClient.delete(storeName, key); - switch (deleteResponse.type) { - case StorageDeleteResponse.Success: { - break; - } - case StorageDeleteResponse.Error: { - throw new Error( - `failed to delete key in store: ${deleteResponse.message()} ${deleteResponse.toString()}` + 'store already exists, we should not be able to create it again' ); } } }); }); - it('should return an undefined value for a key that doesnt exist', async () => { - const storeName = testStoreName(); - await WithStore(storageClient, storeName, async () => { - const key = v4(); - const getResponse = await storageClient.get(storeName, key); - expectWithMessage(() => { - expect(getResponse.type).toEqual(StorageGetResponse.NotFound); - }, `expected NotFound, received ${getResponse.toString()}`); - expect(getResponse.value()).toBeUndefined(); - }); - }); it('should return store not found error for deleting a store that doesnt exist', async () => { const storeName = testStoreName(); const deleteResponse = await storageClient.deleteStore(storeName); @@ -243,4 +110,124 @@ export function runStorageServiceTests(storageClient: IStorageClient) { } }); }); + + // Data plane tests should use the shared integration test store + // with the BeforeAll setup and AfterAll teardown + describe('#store get put and delete', () => { + it('put get and delete key in a store', async () => { + const key = v4(); + + // put/get an int value + const intValue = 42; + const putIntResponse = await storageClient.putInt( + testingStoreName, + key, + intValue + ); + switch (putIntResponse.type) { + case StoragePutResponse.Success: { + break; + } + case StoragePutResponse.Error: { + throw new Error( + `failed to put key: ${putIntResponse.message()} ${putIntResponse.toString()}` + ); + } + } + const getIntResponse = await storageClient.get(testingStoreName, key); + expectWithMessage(() => { + expect(getIntResponse.type).toEqual(StorageGetResponse.Found); + }, `expected Found, received ${getIntResponse.toString()}`); + expect(getIntResponse.value()?.int()).toEqual(intValue); + + // put/get a double value + const doubleValue = 42.42; + const putDoubleResponse = await storageClient.putDouble( + testingStoreName, + key, + doubleValue + ); + switch (putDoubleResponse.type) { + case StoragePutResponse.Success: { + break; + } + case StoragePutResponse.Error: { + throw new Error( + `failed to put key: ${putDoubleResponse.message()} ${putDoubleResponse.toString()}` + ); + } + } + const getDoubleResponse = await storageClient.get(testingStoreName, key); + expectWithMessage(() => { + expect(getDoubleResponse.type).toEqual(StorageGetResponse.Found); + }, `expected Found, received ${getDoubleResponse.toString()}`); + expect(getDoubleResponse.value()?.double()).toEqual(doubleValue); + + // put/get a string value + const stringValue = v4(); + const putStringResponse = await storageClient.putString( + testingStoreName, + key, + stringValue + ); + switch (putStringResponse.type) { + case StoragePutResponse.Success: { + break; + } + case StoragePutResponse.Error: { + throw new Error( + `failed to put key: ${putStringResponse.message()} ${putStringResponse.toString()}` + ); + } + } + const getStringResponse = await storageClient.get(testingStoreName, key); + expectWithMessage(() => { + expect(getStringResponse.type).toEqual(StorageGetResponse.Found); + }, `expected Found, received ${getStringResponse.toString()}`); + expect(getStringResponse.value()?.string()).toEqual(stringValue); + + // put/get a bytes value + const bytesValue = new Uint8Array([1, 2, 3, 4]); + const putBytesResponse = await storageClient.putBytes( + testingStoreName, + key, + bytesValue + ); + switch (putBytesResponse.type) { + case StoragePutResponse.Success: { + break; + } + case StoragePutResponse.Error: { + throw new Error( + `failed to put key: ${putBytesResponse.message()} ${putBytesResponse.toString()}` + ); + } + } + const getBytesResponse = await storageClient.get(testingStoreName, key); + expectWithMessage(() => { + expect(getBytesResponse.type).toEqual(StorageGetResponse.Found); + }, `expected Found, received ${getBytesResponse.toString()}`); + expect(getBytesResponse.value()?.bytes()).toEqual(bytesValue); + + const deleteResponse = await storageClient.delete(testingStoreName, key); + switch (deleteResponse.type) { + case StorageDeleteResponse.Success: { + break; + } + case StorageDeleteResponse.Error: { + throw new Error( + `failed to delete key in store: ${deleteResponse.message()} ${deleteResponse.toString()}` + ); + } + } + }); + it('should return an undefined value for a key that doesnt exist', async () => { + const key = v4(); + const getResponse = await storageClient.get(testingStoreName, key); + expectWithMessage(() => { + expect(getResponse.type).toEqual(StorageGetResponse.NotFound); + }, `expected NotFound, received ${getResponse.toString()}`); + expect(getResponse.value()).toBeUndefined(); + }); + }); }