Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Commit e5a8846

Browse files
committed
test(sdl): for each spec expect full groups and manifest
1 parent 03af646 commit e5a8846

5 files changed

Lines changed: 248 additions & 73 deletions

File tree

‎src/sdl/SDL/SDL.spec.ts‎

Lines changed: 87 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { faker } from "@faker-js/faker";
22

3-
import { readBasicSdl } from "../../../test/yml";
3+
import { createGroupsWith, createManifestWith, readBasicSdl } from "../../../test/templates";
44
import { SdlValidationError } from "../../error";
55
import { SDL } from "./SDL";
66
import { v2ServiceImageCredentials } from "../types";
7-
import { omit } from "lodash";
7+
import omit from "lodash/omit";
88
import { AKT_DENOM, SANDBOX_ID, USDC_IBC_DENOMS } from "../../config/network";
99

1010
describe("SDL", () => {
@@ -13,18 +13,21 @@ describe("SDL", () => {
1313
const yml = readBasicSdl({ denom });
1414
const sdl = SDL.fromString(yml, "beta3", "sandbox");
1515

16-
expect(sdl.groups()).toMatchObject([
17-
{
18-
resources: [
19-
{
20-
price: {
21-
denom: denom,
22-
amount: "1000"
16+
expect(sdl.manifest()).toMatchObject(createManifestWith());
17+
expect(sdl.groups()).toMatchObject(
18+
createGroupsWith([
19+
{
20+
resources: [
21+
{
22+
price: {
23+
denom: denom,
24+
amount: "1000"
25+
}
2326
}
24-
}
25-
]
26-
}
27-
]);
27+
]
28+
}
29+
])
30+
);
2831
});
2932

3033
it("should throw an error when denomination is invalid", () => {
@@ -39,53 +42,57 @@ describe("SDL", () => {
3942

4043
describe("endpoints", () => {
4144
it("should resolve with valid endpoints", () => {
42-
const endpointName = faker.lorem.word();
45+
const endpointName = faker.lorem.word({ length: { min: 3, max: 10 } });
4346
const endpoint = {
4447
[endpointName]: {
4548
kind: "ip"
4649
}
4750
};
48-
const yml = readBasicSdl({ endpoint });
51+
const yml = readBasicSdl({ endpoint, denom: "uakt" });
4952
const sdl = SDL.fromString(yml, "beta3", "sandbox");
5053

51-
expect(sdl.manifest()).toMatchObject([
52-
{
53-
services: [
54-
{
55-
resources: {
56-
endpoints: {
57-
1: {
58-
kind: 2,
59-
sequence_number: 1
54+
expect(sdl.manifest()).toMatchObject(
55+
createManifestWith([
56+
{
57+
services: [
58+
{
59+
resources: {
60+
endpoints: {
61+
1: {
62+
kind: 2,
63+
sequence_number: 1
64+
}
6065
}
61-
}
62-
},
63-
expose: [
64-
{
65-
ip: endpointName,
66-
endpointSequenceNumber: 1
67-
}
68-
]
69-
}
70-
]
71-
}
72-
]);
73-
expect(sdl.groups()).toMatchObject([
74-
{
75-
resources: [
76-
{
77-
resource: {
78-
endpoints: {
79-
1: {
80-
kind: 2,
81-
sequence_number: 1
66+
},
67+
expose: [
68+
{
69+
ip: endpointName,
70+
endpointSequenceNumber: 1
71+
}
72+
]
73+
}
74+
]
75+
}
76+
])
77+
);
78+
expect(sdl.groups()).toMatchObject(
79+
createGroupsWith([
80+
{
81+
resources: [
82+
{
83+
resource: {
84+
endpoints: {
85+
1: {
86+
kind: 2,
87+
sequence_number: 1
88+
}
8289
}
8390
}
8491
}
85-
}
86-
]
87-
}
88-
]);
92+
]
93+
}
94+
])
95+
);
8996
});
9097

9198
it("should throw provided an invalid endpoint name", () => {
@@ -101,7 +108,7 @@ describe("SDL", () => {
101108
});
102109

103110
it("should throw provided no endpoint kind", () => {
104-
const endpointName = faker.lorem.word();
111+
const endpointName = faker.lorem.word({ length: { min: 3, max: 10 } });
105112
const endpoint = {
106113
[endpointName]: {}
107114
};
@@ -111,7 +118,7 @@ describe("SDL", () => {
111118
});
112119

113120
it("should throw provided invalid endpoint kind", () => {
114-
const endpointName = faker.lorem.word();
121+
const endpointName = faker.lorem.word({ length: { min: 3, max: 10 } });
115122
const endpointKind = faker.lorem.word();
116123
const endpoint = {
117124
[endpointName]: {
@@ -126,7 +133,7 @@ describe("SDL", () => {
126133
});
127134

128135
it("should throw when endpoint is unused", () => {
129-
const endpointName = faker.lorem.word();
136+
const endpointName = faker.lorem.word({ length: { min: 3, max: 10 } });
130137
const endpoint = {
131138
[endpointName]: {
132139
kind: "ip"
@@ -145,28 +152,37 @@ describe("SDL", () => {
145152
username: faker.internet.userName(),
146153
password: faker.internet.password()
147154
};
148-
const sdl = SDL.fromString(readBasicSdl({ credentials }), "beta3", "sandbox");
149-
150-
expect(sdl.manifest()).toMatchObject([
151-
{
152-
services: [
153-
{
154-
credentials
155-
}
156-
]
157-
}
158-
]);
155+
const sdl = SDL.fromString(readBasicSdl({ credentials, denom: "uakt" }), "beta3", "sandbox");
156+
157+
expect(sdl.manifest()).toMatchObject(
158+
createManifestWith([
159+
{
160+
services: [
161+
{
162+
credentials
163+
}
164+
]
165+
}
166+
])
167+
);
168+
expect(sdl.groups()).toMatchObject(createGroupsWith());
159169
});
160170

161171
it("should resolve a service without credentials", () => {
162-
const sdl = SDL.fromString(readBasicSdl(), "beta3", "sandbox");
163-
const group = sdl.manifest()[0];
164-
165-
if (!("services" in group)) {
166-
throw new Error("No services found in group");
167-
}
168-
169-
expect(group.services[0].credentials).toBeNull();
172+
const sdl = SDL.fromString(readBasicSdl({ denom: "uakt" }), "beta3", "sandbox");
173+
174+
expect(sdl.manifest()).toMatchObject(
175+
createManifestWith([
176+
{
177+
services: [
178+
{
179+
credentials: null
180+
}
181+
]
182+
}
183+
])
184+
);
185+
expect(sdl.groups()).toMatchObject(createGroupsWith());
170186
});
171187

172188
describe("invalid credentials errors", () => {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[
2+
{
3+
"name": "dcloud",
4+
"resources": [
5+
{
6+
"resource": {
7+
"endpoints": [
8+
{
9+
"sequence_number": 0
10+
}
11+
],
12+
"cpu": {
13+
"units": {
14+
"val": {
15+
"0": 53,
16+
"1": 48,
17+
"2": 48
18+
}
19+
}
20+
},
21+
"memory": {
22+
"quantity": {
23+
"val": {
24+
"0": 53,
25+
"1": 51,
26+
"2": 54,
27+
"3": 56,
28+
"4": 55,
29+
"5": 48,
30+
"6": 57,
31+
"7": 49,
32+
"8": 50
33+
}
34+
}
35+
},
36+
"storage": [
37+
{
38+
"name": "default",
39+
"quantity": {
40+
"val": {
41+
"0": 53,
42+
"1": 51,
43+
"2": 54,
44+
"3": 56,
45+
"4": 55,
46+
"5": 48,
47+
"6": 57,
48+
"7": 49,
49+
"8": 50
50+
}
51+
}
52+
}
53+
],
54+
"gpu": {
55+
"units": {
56+
"val": {
57+
"0": 48
58+
}
59+
}
60+
},
61+
"id": 1
62+
},
63+
"price": {
64+
"denom": "uakt",
65+
"amount": "1000"
66+
},
67+
"count": 1
68+
}
69+
],
70+
"requirements": {
71+
"attributes": [],
72+
"signedBy": {
73+
"allOf": [],
74+
"anyOf": []
75+
}
76+
}
77+
}
78+
]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[
2+
{
3+
"name": "dcloud",
4+
"services": [
5+
{
6+
"name": "web",
7+
"image": "akashlytics/hello-akash-world:0.2.0",
8+
"command": null,
9+
"args": null,
10+
"env": null,
11+
"resources": {
12+
"id": 1,
13+
"cpu": {
14+
"units": {
15+
"val": "500"
16+
}
17+
},
18+
"memory": {
19+
"size": {
20+
"val": 536870912
21+
}
22+
},
23+
"storage": [
24+
{
25+
"name": "default",
26+
"size": {
27+
"val": 536870912
28+
}
29+
}
30+
],
31+
"endpoints": [
32+
{
33+
"sequence_number": 0
34+
}
35+
],
36+
"gpu": {
37+
"units": {
38+
"val": 0
39+
}
40+
}
41+
},
42+
"count": 1,
43+
"expose": [
44+
{
45+
"port": 3000,
46+
"externalPort": 80,
47+
"proto": "TCP",
48+
"service": "",
49+
"global": true,
50+
"hosts": null,
51+
"httpOptions": {
52+
"maxBodySize": 1048576,
53+
"readTimeout": 60000,
54+
"sendTimeout": 60000,
55+
"nextTries": 3,
56+
"nextTimeout": 0,
57+
"nextCases": ["error", "timeout"]
58+
},
59+
"ip": "",
60+
"endpointSequenceNumber": 0
61+
}
62+
],
63+
"params": null,
64+
"credentials": null
65+
}
66+
]
67+
}
68+
]

test/yml.ts renamed to test/templates.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import { dump } from "js-yaml";
44
import { faker } from "@faker-js/faker";
55
import template from "lodash/template";
66
import memoize from "lodash/memoize";
7+
import pick from "lodash/pick";
8+
79
import { AKT_DENOM } from "../src/config/network";
810
import { SANDBOX_ID, USDC_IBC_DENOMS } from "../src/config/network";
9-
import { pick } from "lodash";
11+
import groupsBasicSnapshot from "./fixtures/groups-basic-snapshot.json";
12+
import manifestBasicSnapshot from "./fixtures/manifest-basic-snapshot.json";
13+
import { merge } from "lodash";
1014

1115
export const readYml = (name: string): string => {
1216
return fs.readFileSync(path.resolve(__dirname, `./fixtures/${name}.yml`), "utf-8");
@@ -58,3 +62,11 @@ export const readBasicSdl = (variables: BasicSdlTemplateVariables = {}): string
5862

5963
return createYML(ymlVars);
6064
};
65+
66+
const jsonTemplate =
67+
<T extends Record<string, any>>(template: T) =>
68+
(variables: Record<string, any> = {}) =>
69+
merge({}, template, variables);
70+
71+
export const createManifestWith = jsonTemplate(manifestBasicSnapshot);
72+
export const createGroupsWith = jsonTemplate(groupsBasicSnapshot);

0 commit comments

Comments
 (0)