Skip to content

Commit 9d04139

Browse files
committed
Add cleanup step to all tests
1 parent c09a0e1 commit 9d04139

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

__tests__/astra.test.ts

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,30 @@ import { describe, test } from "mocha";
33
import { expect } from "chai";
44

55
const { ASTRA_DB_TOKEN, ASTRA_DB_ID } = process.env;
6+
const epoch = new Date().getTime();
67

78
describe("Astra", () => {
9+
let astra;
10+
before(async () => {
11+
astra = new Astra({
12+
token: ASTRA_DB_TOKEN,
13+
databaseId: ASTRA_DB_ID,
14+
databaseRegion: "us-east1",
15+
namespace: "test",
16+
});
17+
})
818
describe("Collections", () => {
919
test("should create collection", async () => {
10-
const astra = new Astra({
11-
token: ASTRA_DB_TOKEN,
12-
databaseId: ASTRA_DB_ID,
13-
databaseRegion: "us-east1",
14-
namespace: "test",
15-
});
16-
17-
const results = await astra.createCollection({ name: "blah" });
20+
const collectionName = `test${epoch}`;
21+
const results = await astra.createCollection({ name: collectionName });
1822
expect(results.status.ok).to.equal(1);
23+
await astra.deleteCollection({ name: collectionName });
1924
});
2025

2126
test("should create vector collection", async () => {
22-
const astra = new Astra({
23-
token: ASTRA_DB_TOKEN,
24-
databaseId: ASTRA_DB_ID,
25-
databaseRegion: "us-east1",
26-
namespace: "test",
27-
});
28-
27+
const collectionName = `test${epoch}`;
2928
const results = await astra.createCollection({
30-
name: "blahs",
29+
name: collectionName,
3130
options: {
3231
vector: {
3332
size: 2,
@@ -36,28 +35,26 @@ describe("Astra", () => {
3635
},
3736
});
3837
expect(results.status.ok).to.equal(1);
38+
await astra.deleteCollection({ name: collectionName });
3939
});
4040

4141
test("should find collections", async () => {
42-
const astra = new Astra({
43-
token: ASTRA_DB_TOKEN,
44-
databaseId: ASTRA_DB_ID,
45-
databaseRegion: "us-east1",
46-
namespace: "test",
42+
const collectionName = `test${epoch}`;
43+
await astra.createCollection({
44+
name: collectionName,
45+
options: {
46+
vector: {
47+
size: 2,
48+
function: "cosine",
49+
},
50+
},
4751
});
48-
4952
const results = await astra.findCollections();
50-
expect(results.status.collections[0]).to.equal("blah");
53+
expect(results.status.collections[0]).to.equal(collectionName);
54+
await astra.deleteCollection({ name: collectionName });
5155
});
5256

5357
test("should delete collection that doesn't exist", async () => {
54-
const astra = new Astra({
55-
token: ASTRA_DB_TOKEN,
56-
databaseId: ASTRA_DB_ID,
57-
databaseRegion: "us-east1",
58-
namespace: "test",
59-
});
60-
6158
const collection = await astra.deleteCollection({ name: "bah" });
6259
expect(collection.status.ok).to.equal(1);
6360
});

__tests__/collection.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ describe("Collections", () => {
7979
},
8080
},
8181
});
82-
console.log(updateResults);
8382
await astra.deleteCollection({ name: collectionName });
8483
});
8584
test("should delete one", async () => {

0 commit comments

Comments
 (0)