Skip to content

Commit fdb617d

Browse files
committed
chore(test): add tg deployer through shell in meta test
1 parent e2cc245 commit fdb617d

File tree

3 files changed

+73
-15
lines changed

3 files changed

+73
-15
lines changed

typegate/tests/runtimes/wasmedge/wasmedge.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
from typegraph.gen.exports.core import (
2+
ArtifactResolutionConfig,
3+
MigrationAction,
4+
MigrationConfig,
5+
)
6+
from typegraph.graph.shared_types import BasicAuth
7+
from typegraph.graph.tg_deploy import TypegraphDeployParams, tg_deploy
18
from typegraph.graph.typegraph import Graph
29
from typegraph.policy import Policy
310
from typegraph.runtimes.wasmedge import WasmEdgeRuntime
@@ -18,3 +25,24 @@ def wasmedge(g: Graph):
1825
func="add",
1926
).with_policy(pub),
2027
)
28+
29+
30+
PORT = 7698
31+
gate = f"http://localhost:{PORT}"
32+
auth = BasicAuth("admin", "password")
33+
34+
wasmedge_tg = wasmedge()
35+
serialized, typegate = tg_deploy(
36+
wasmedge_tg,
37+
TypegraphDeployParams(
38+
base_url=gate,
39+
artifacts_config=ArtifactResolutionConfig(
40+
prisma_migration=MigrationConfig(
41+
migration_dir="prisma-migrations",
42+
global_action=MigrationAction(reset=False, create=True),
43+
)
44+
),
45+
),
46+
)
47+
48+
print(serialized)

typegate/tests/runtimes/wasmedge/wasmedge_test.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,34 @@ import { BasicAuth, tgDeploy } from "@typegraph/sdk/tg_deploy.js";
55
import { gql, Meta } from "../../utils/mod.ts";
66
import { testDir } from "test-utils/dir.ts";
77
import { tg } from "./wasmedge.ts";
8+
import { SDKLangugage } from "test-utils/test.ts";
89

910
const port = 7698;
1011
const gate = `http://localhost:${port}`;
1112
const cwdDir = testDir;
1213
const auth = new BasicAuth("admin", "password");
1314

14-
// Meta.test("WasmEdge runtime", async (t) => {
15-
// const e = await t.engine("runtimes/wasmedge/wasmedge.py", {}, { port });
16-
17-
// await t.should("works", async () => {
18-
// await gql`
19-
// query {
20-
// test(a: 1, b: 2)
21-
// }
22-
// `
23-
// .expectData({
24-
// test: 3,
25-
// })
26-
// .on(e);
27-
// });
28-
// }, { port: port });
15+
Meta.test("WasmEdge runtime", async (t) => {
16+
await t.should("works", async () => {
17+
const serialized = await t.serializeTypegraphFromShell(
18+
"runtimes/wasmedge/wasmedge.py",
19+
SDKLangugage.Python,
20+
);
21+
22+
const engine = await t.engineFromDeployed(serialized);
23+
24+
await gql`
25+
query {
26+
test(a: 1, b: 2)
27+
}
28+
`
29+
.expectData({
30+
test: 3,
31+
})
32+
.on(engine);
33+
await engine.terminate();
34+
});
35+
}, { port: port });
2936

3037
Meta.test("WasmEdge Runtime typescript sdk", async (metaTest) => {
3138
await metaTest.should("work after deploying artifact", async () => {

typegate/tests/utils/test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export interface ParseOptions {
3131
pretty?: boolean;
3232
}
3333

34+
export enum SDKLangugage {
35+
Python = "python3",
36+
TypeScript = "deno",
37+
}
38+
3439
function serve(typegate: Typegate, port: number): () => void {
3540
const server = Deno.serve({ port }, (req) => {
3641
return typegate.handle(req, {
@@ -157,6 +162,24 @@ export class MetaTest {
157162
return engine;
158163
}
159164

165+
async serializeTypegraphFromShell(
166+
path: string,
167+
lang: SDKLangugage,
168+
): Promise<string> {
169+
// run self deployed typegraph
170+
const { stderr, stdout } = await this.shell([lang.toString(), path]);
171+
172+
if (stderr.length > 0) {
173+
throw new Error(`${stderr}`);
174+
}
175+
176+
if (stdout.length === 0) {
177+
throw new Error("No typegraph");
178+
}
179+
180+
return stdout;
181+
}
182+
160183
async unregister(engine: QueryEngine) {
161184
await Promise.all(
162185
this.register

0 commit comments

Comments
 (0)