Skip to content

Commit

Permalink
fix: validate postgres size
Browse files Browse the repository at this point in the history
  • Loading branch information
mo4islona committed Nov 5, 2024
1 parent 433da0e commit 8aff7ab
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@subsquid/manifest",
"type": "commonjs",
"version": "2.0.0-beta.6",
"version": "2.0.0-beta.7",
"homepage": "https://www.subsquid.io",
"repository": "https://github.com/subsquid/manifest.git",
"license": "GPL-3.0-or-later",
Expand Down Expand Up @@ -66,4 +66,4 @@
}
},
"packageManager": "[email protected]+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
}
}
3 changes: 2 additions & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export class Manifest {
[
'build',
'deploy.api',
'deploy.cors',
'deploy.addons.postgres',
'deploy.addons.hasura',
'deploy.addons.neon',
Expand Down Expand Up @@ -333,4 +334,4 @@ function getError(path: string, expression: string | undefined, error: any) {
`Manifest env variable "${path}" can not be mapped${exprIn}`,
error instanceof Error ? error.message : error.toString(),
].join(': ');
}
}
9 changes: 7 additions & 2 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ export const manifestSchema = Joi.object<ManifestValue>({
dedicated: Joi.boolean(),
addons: Joi.object({
postgres: Joi.object({
storage: Joi.string(),
storage: Joi.string()
.regex(/^\d+[GT]i?$/)
.messages({
'string.pattern.base':
'{#label} with value "{#value}" is invalid. Size must be a number followed by unit. Valid units are "G", "Gi", "T" and "Ti"',
}),
autoresize: Joi.bool(),
autoresize_limit: Joi.string(),
profile: Joi.string().valid('small', 'medium', 'large'),
Expand Down Expand Up @@ -243,4 +248,4 @@ export const manifestSchema = Joi.object<ManifestValue>({
.description('[DEPRECATED] Please use "manifest_version" instead.')
.valid(...AVAILABLE_MANIFEST_VERSIONS)
.meta({ deprecated: true }),
}).oxor('slot', 'version', 'tag');
}).oxor('slot', 'version', 'tag');
52 changes: 50 additions & 2 deletions test/addon_postgres.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Manifest } from '../src';
import { Manifest, ManifestParsingError } from '../src';

describe('Addon Postgres', () => {
it('should add defaults to postgres addon', () => {
Expand Down Expand Up @@ -270,4 +270,52 @@ describe('Addon Postgres', () => {
},
});
});
});

it('should do not allow storage size values w/o units', () => {
const { error, value } = Manifest.parse(`
manifest_version: subsquid.io/v0.1
name: test
version: 1
build:
deploy:
addons:
postgres:
api:
cmd: [ "npx", "squid-graphql-server" ]
processor:
cmd: [ "node", "lib/processor" ]
scale:
addons:
postgres:
storage: 50
`);

expect(error).toEqual(
new ManifestParsingError([
'"scale.addons.postgres.storage" with value "50" is invalid. Size must be a number followed by unit. Valid units are "G", "Gi", "T" and "Ti"',
]),
);
});

it.each(['G', 'Gi', 'T', 'Ti'])(`should allow %v unit`, unit => {
const { error } = Manifest.parse(`
manifest_version: subsquid.io/v0.1
name: test
version: 1
build:
deploy:
addons:
postgres:
api:
cmd: [ "npx", "squid-graphql-server" ]
processor:
cmd: [ "node", "lib/processor" ]
scale:
addons:
postgres:
storage: 100${unit}
`);

expect(error).toBeUndefined();
});
});
25 changes: 25 additions & 0 deletions test/cors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Manifest } from '../src';

describe('Cors', () => {
it('should allow empty cors object', () => {
const { error, value } = Manifest.parse(`
manifest_version: subsquid.io/v0.1
name: test
version: 1
build:
deploy:
cors:
processor:
cmd: [ "node", "lib/processor" ]
`);

expect(error).toBeUndefined();
expect(value).toMatchObject({
deploy: {
cors: {
enabled: true,
},
},
});
});
});

0 comments on commit 8aff7ab

Please sign in to comment.