snowflake
Intro
Depot-local snowflake test is comparably slower to snowflake transaction test using depot-test therefore we suggest it should be used only in scenarios where testing something is not possible with snowflake transaction tests i.e. queries.
Example
The depot.start() method, starts
- Each data store in its own container
- Local Depot configured with each data store
const depot = new DepotLocal({
depot: {
},
//dynamo db is required for snowflake tests
dynamodb: {
}
});
beforeAll(async () => {
await depot.start();
});
afterAll(async () => {
await depot.stop();
});
Once started, you can deploy a new Environment to your Depot local instance,
using depot.deploy(). Use a helper method to easily construct an environment,
for example from a namespace.
const namespace = Schemas.fromYamlFiles("test/schema/pet.yml");
const environment = new EnvironmentBuilder(schemas)
.location(LocationBuilder.snowflakeDb())
.build();
Each deployed dataset has its own DepotApi, for simple tests there will be only one.
const api = depot.deploy(environment).api(0);
the environment and api values should not be shared, but private to each individual test. This
will ensure Depot-Local provides an empty dataset at each execution.
Configuration
Snowflake test connection, database and credentials should be configured via a depot.properties file.
Requests
The api can then be used to make requests to your environment.
const create = await api.create({
schema: "pet.Pet",
data: {
name: "Ren",
age: 2
}
});
Transaction requests
The api can then be used to make transaction requests to your environment.
/** path containing file with matching schema name pet.Pet */
import {TransactionOperation} from "./api";
const pathToData = path.join(testDirectory, "data");
/** you need to load data to container */
const stagedDataPath = depot.stageData(environment, pathToData);
/** example transaction request through api */
const create = await api.transaction({
schema: "pet.Pet",
data: {
schema: "pet.Pet",
datasetId: environment.datasets[0].datasetId,
actions: [
{
operation: TransactionOperation.UPSERT,
locationUri: stagedDataPath,
format: "JSON",
target: "pet.Pet"
}
]
}
});
successful transactions returns http status 204 and no data.
staged file example :
[
{
"id": "156",
"name": "Doggo 3",
"age": 2
}
]