pshregistry-parser
Version:
Helper for library for accessing image data from the Upsun Registry and generating configuration files.
730 lines (636 loc) • 35.1 kB
JavaScript
'use strict';
const assert = require('assert').strict;
const psh = require('../src/registry-parser.js');
const fs = require('fs');
const yaml = require('js-yaml');
describe('Upsun Registry Parser tests', function() {
before(function(done) {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource, 'test/');
registry.write();
done();
});
describe('Registry source', function() {
it('Test valid local Registry does not throw InvalidRegistryError', function() {
let validRegistrySource = "test/testdata/valid.json";
assert.doesNotThrow(
() => {
let registry = new psh.RegistryParser(validRegistrySource);
},
psh.InvalidRegistryError
);
});
it('Test invalid local Registry throws InvalidRegistryError', function () {
let invalidRegistrySource = "test/testdata/invalid.json";
assert.throws(
() => {
let registry = new psh.RegistryParser(invalidRegistrySource);
},
psh.InvalidRegistryError
);
});
it('Test Registry entry missing type property throws InvalidRegistryError', function () {
let missingTypeSource = "test/testdata/missing-type.json";
assert.throws(
() => {
let registry = new psh.RegistryParser(missingTypeSource);
},
{
name: 'InvalidRegistryError',
message: 'Registry entry "test-image" is missing required property: type'
}
);
});
it('Test filtered Registry for Runtimes only contains runtimes', function () {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(Object.keys(registry.runtimes).length, 9);
assert.equal(Object.keys(registry.runtimes)[0], "dotnet");
});
it('Test filtered Registry for Services only contains services', function () {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(Object.keys(registry.services).length, 18);
assert.equal("golang" in registry.services, false);
});
})
describe('YAML generation', function() {
it('Test that registry YAML file is generated and data is accessible', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
registry.writeRegistryYAML(registrySource);
let yamlRegistry = yaml.load(fs.readFileSync('test/testdata/valid.yaml', 'utf8'));
assert.equal(yamlRegistry.elasticsearch.disk, true);
assert.equal(yamlRegistry.elasticsearch.endpoint, "elasticsearch");
assert.equal(yamlRegistry.golang.runtime, true);
});
})
describe('Supported Versions table generation', function() {
it('Test that Runtimes supported version table content generates', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `
| **Language** | **\`runtime\`** | **Supported \`version\`** |
|----------------------------------|---------------|-------------------------|
| [C#/.Net Core](/languages/dotnet.html) | \`dotnet\` | 2.0, 2.1, 2.2, 3.1 |
| [Elixir](/languages/elixir.html) | \`elixir\` | 1.9, 1.10 |
| [Go](/languages/go.html) | \`golang\` | 1.11, 1.12, 1.13, 1.14 |
| [Java](/languages/java.html) | \`java\` | 11, 12, 8, 13 |
| [Lisp](/languages/lisp.html) | \`lisp\` | 1.5 |
| [Node.js](/languages/nodejs.html) | \`nodejs\` | 6, 8, 10, 12 |
| [PHP](/languages/php.html) | \`php\` | 7.2, 7.3, 7.4 |
| [Python](/languages/python.html) | \`python\` | 2.7, 3.5, 3.6, 3.7, 3.8 |
| [Ruby](/languages/ruby.html) | \`ruby\` | 2.3, 2.4, 2.5, 2.6, 2.7 |`.trim();
assert.equal(registry.makeSupportedVersionsTable("runtimes"), expected);
});
it('Test that Services supported version table content generates', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `
| **Service** | **\`type\`** | **Supported \`version\`** |
|----------------------------------|---------------|-------------------------|
| [Headless Chrome](/configuration/services/headless-chrome.html) | \`chrome-headless\` | 73 |
| [Dedicated](/configuration/services/dedicated.html) | \`dedicated\` | |
| [Deprecated](/configuration/services/deprecated.html) | \`deprecated\` | |
| [Elasticsearch](/configuration/services/elasticsearch.html) | \`elasticsearch\` | 6.5, 7.2 |
| [InfluxDB](/configuration/services/influxdb.html) | \`influxdb\` | 1.2, 1.3, 1.7 |
| [Kafka](/configuration/services/kafka.html) | \`kafka\` | 2.1, 2.2, 2.3, 2.4 |
| [MariaDB](/configuration/services/mysql.html) | \`mariadb\` | 10.0, 10.1, 10.2, 10.3, 10.4, 10.5 |
| [Memcached](/configuration/services/memcached.html) | \`memcached\` | 1.4, 1.5, 1.6 |
| [MongoDB](/configuration/services/mongodb.html) | \`mongodb\` | 3.0, 3.2, 3.4, 3.6 |
| [Network Storage](/configuration/services/network-storage.html) | \`network-storage\` | 1.0 |
| [Oracle MySQL](/configuration/services/mysql.html) | \`oracle-mysql\` | 5.7, 8.0 |
| [PostgreSQL](/configuration/services/postgresql.html) | \`postgresql\` | 9.6, 10, 11, 12 |
| [RabbitMQ](/configuration/services/rabbitmq.html) | \`rabbitmq\` | 3.5, 3.6, 3.7, 3.8 |
| [Redis](/configuration/services/redis.html) | \`redis\` | 3.2, 4.0, 5.0 |
| [Solr](/configuration/services/solr.html) | \`solr\` | 3.6, 4.1, 6.3, 6.6, 7.6, 7.7, 8.0, 8.4 |
| [Varnish](/configuration/services/varnish.html) | \`varnish\` | 5.6, 6.0 |`.trim();
assert.equal(registry.makeSupportedVersionsTable("services"), expected);
});
})
describe('Save directories', function() {
it('Test empty saveDir creates local saveLocations', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let saveLocations = registry.saveLocations;
assert.equal(registry.saveLocations.commented, "test/testdata/examples/commented/");
assert.equal(registry.saveLocations.full, "test/testdata/examples/full/");
assert.equal(registry.saveLocations.snippet, "test/testdata/examples/snippet/");
assert.equal(registry.saveLocations.tables, "test/testdata/tables/");
});
it('Test given saveDir creates valid saveLocations', function() {
let registrySource = "test/testdata/valid.json";
let saveDir = "test/";
let registry = new psh.RegistryParser(registrySource, saveDir);
let saveLocations = registry.saveLocations;
assert.equal(registry.saveLocations.commented, "test/examples/commented/");
assert.equal(registry.saveLocations.full, "test/examples/full/");
assert.equal(registry.saveLocations.snippet, "test/examples/snippet/");
assert.equal(registry.saveLocations.tables, "test/tables/");
});
})
describe('Service image property access', function() {
it('Test service property runtime is false', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["elasticsearch"].runtime, false);
assert.equal(registry.services["elasticsearch"].runtime, false);
});
it('Test service property disk is true', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["elasticsearch"].disk, true);
assert.equal(registry.services["elasticsearch"].disk, true);
});
it('Test service property min_disk_size is set', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["elasticsearch"].min_disk_size, 256);
assert.equal(registry.services["elasticsearch"].min_disk_size, 256);
});
})
describe('Runtime image property access', function() {
it('Test runtime property runtime is true', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["golang"].runtime, true);
assert.equal(registry.runtimes["golang"].runtime, true);
});
it('Test runtime property disk is false', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["golang"].disk, false);
assert.equal(registry.runtimes["golang"].disk, false);
});
it('Test golang type is golang', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.strictEqual(registry.images["golang"].type, 'golang');
assert.strictEqual(registry.runtimes["golang"].type, 'golang');
});
})
describe('Additional type property access', function() {
it('Test mysql uses the mariadb baseImage', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["mysql"].endpoint, "mysql");
assert.equal(registry.images["mysql"].name, "MariaDB");
assert.equal(registry.services["mysql"].endpoint, "mysql");
assert.equal(registry.services["mysql"].name, "MariaDB");
});
it('Test mysql update properties have been changed', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["mysql"].type, "mysql");
assert.equal(registry.services["mysql"].type, "mysql");
});
it('Test persistent-redis uses the redis baseImage', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["redis-persistent"].endpoint, "redis");
assert.equal(registry.images["redis-persistent"].repo_name, "redis");
assert.equal(registry.services["redis-persistent"].endpoint, "redis");
assert.equal(registry.services["redis-persistent"].repo_name, "redis");
});
it('Test persistent-redis update properties have been changed', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["redis-persistent"].type, "redis-persistent");
assert.equal(registry.images["redis-persistent"].disk, true);
assert.equal(registry.images["redis-persistent"].docs.relationship_name, "redisdata");
assert.equal(registry.images["redis-persistent"].docs.service_name, "data");
assert.equal(registry.services["redis-persistent"].type, "redis-persistent");
assert.equal(registry.services["redis-persistent"].disk, true);
assert.equal(registry.services["redis-persistent"].docs.relationship_name, "redisdata");
assert.equal(registry.services["redis-persistent"].docs.service_name, "data");
});
})
describe('Supported and deprecated image versions', function() {
it('Test supportedString is a raw string for a valid image', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["elasticsearch"].supportedString, "6.5, 7.2");
});
it('Test deprecatedString is a raw string for a valid image', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["golang"].deprecatedString, "1.10, 1.8, 1.9");
});
it('Test supportedHTML is a html unordered list for a valid image', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["elasticsearch"].supportedHTML, "<ul><li>6.5</li><li>7.2</li></ul>");
});
it('Test deprecatedHTML is a html unordered list for a valid image', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["golang"].deprecatedHTML, "<ul><li>1.10</li><li>1.8</li><li>1.9</li></ul>");
});
})
describe('Recommended image versions', function() {
it('Recommends higher of two dotted versions', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["elasticsearch"].recommended, "7.2");
assert.equal(registry.services["elasticsearch"].recommended, "7.2");
});
it('Recommends higher version when it is 1.10', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.equal(registry.images["elixir"].recommended, "1.10");
assert.equal(registry.runtimes["elixir"].recommended, "1.10");
});
it('Recommends a Dedicated version if no ordinary supported available', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.strictEqual(registry.images["dedicated-only"].recommended, "1.10");
assert.strictEqual(registry.services["dedicated-only"].recommended, "1.10");
});
it('Recommends a deprecated version if no supported available', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.strictEqual(registry.images["deprecated-only"].recommended, "2.4");
assert.strictEqual(registry.services["deprecated-only"].recommended, "2.4");
});
})
describe('Writing files: individual', function() {
it('Test writing individual invalid image throws NotValidImageError', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let invalid_image = "something"
assert.throws(
() => {
throw registry.write(invalid_image);
},
psh.NotValidImageError
);
});
it('Test writing valid images does not throw', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
assert.doesNotThrow(
() => {
registry.write("elasticsearch");
},
psh.NotValidImageError
);
assert.doesNotThrow(
() => {
registry.write("golang");
},
psh.NotValidImageError
);
});
})
describe('Writing files: all images', function() {
it('Test writing files for all images writes valid content.json files', function(done) {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
registry.write();
let commentedContents = JSON.parse(fs.readFileSync('test/testdata/examples/commented/content.json', 'utf8'));
let fullContents = JSON.parse(fs.readFileSync('test/testdata/examples/full/content.json', 'utf8'));
let snippetContents = JSON.parse(fs.readFileSync('test/testdata/examples/snippet/content.json', 'utf8'));
assert.deepStrictEqual(commentedContents.files, registry.directoryContent.commented);
assert.deepStrictEqual(fullContents.files, registry.directoryContent.full);
assert.deepStrictEqual(snippetContents.files, registry.directoryContent.snippet);
done();
});
it('Test commented app.yaml content is correct', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `# The runtime the application uses. The 'type' key defines the base container
# image that will be used to run the application. There is a separate base
# container image for each primary language for the application,
# in multiple versions. Check the Go documentation
# (https://docs.upsun.com/anchors/fixed/languages/golang/#supported-versions)
# to find the supported versions for the 'golang' type.
type: 'golang:1.14'`;
assert.equal(expected, registry.images["golang"].config.app.commented);
assert.equal(expected, fs.readFileSync('test/testdata/examples/commented/golang.app.yaml', 'utf8'))
});
it('Test commented services.yaml content is correct', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `# The name given to the Elasticsearch service (lowercase alphanumeric only).
searchelastic:
# The type of your service (elasticsearch), which uses the format
# 'type:version'. Be sure to consult the Elasticsearch documentation
# (https://docs.upsun.com/anchors/fixed/services/elasticsearch/#supported-versions)
# when choosing a version. If you specify a version number which is not available,
# the CLI will return an error.
type: elasticsearch:7.2
# The disk attribute is the size of the persistent disk (in MB) allocated to the service.
disk: 256`;
assert.equal(expected, registry.images["elasticsearch"].config.services.commented);
assert.equal(expected, fs.readFileSync('test/testdata/examples/commented/elasticsearch.services.yaml', 'utf8'));
});
it('Test full app.yaml is correct', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `relationships:
essearch: "searchelastic:elasticsearch"`;
assert.equal(expected, registry.images["elasticsearch"].config.app.full)
assert.equal(expected, fs.readFileSync('test/testdata/examples/full/elasticsearch.app.yaml', 'utf8'));
});
it('Test full services.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `searchelastic:
type: elasticsearch:7.2
disk: 256`
assert.equal(expected, registry.images["elasticsearch"].config.services.full);
assert.equal(expected, fs.readFileSync('test/testdata/examples/full/elasticsearch.services.yaml', 'utf8'));
});
it('Test snippet app.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = ` essearch: "searchelastic:elasticsearch"`;
assert.equal(expected, registry.images["elasticsearch"].config.app.snippet);
assert.equal(expected, fs.readFileSync('test/testdata/examples/snippet/elasticsearch.app.yaml', 'utf8'));
});
it('Test snippet services.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `searchelastic:
type: elasticsearch:7.2
disk: 256`;
assert.equal(expected, registry.images["elasticsearch"].config.services.snippet);
assert.equal(expected, fs.readFileSync('test/testdata/examples/snippet/elasticsearch.services.yaml', 'utf8'));
});
it('Test snippet services.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `searchelastic:
type: elasticsearch:7.2
disk: 256`;
assert.equal(expected, registry.images["elasticsearch"].config.services.snippet);
assert.equal(expected, fs.readFileSync('test/testdata/examples/snippet/elasticsearch.services.yaml', 'utf8'));
});
it('Test <image>.build.app.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected_commented = `# 'build' defines what happens when building the application. Its only
# property is 'flavor', which specifies a default set of build tasks to run.
# Flavors are language-specific.
# DOCS: https://docs.upsun.com/anchors/fixed/app/reference/build/
build:
flavor: composer`;
let expected_full = `build:
flavor: composer`;
let expected_snippet = `build:
flavor: composer`;
assert.equal(expected_commented, registry.images["php"].config.build.commented);
assert.equal(expected_commented, fs.readFileSync('test/testdata/examples/commented/php.build.app.yaml', 'utf8'));
assert.equal(expected_full, registry.images["php"].config.build.full);
assert.equal(expected_full, fs.readFileSync('test/testdata/examples/full/php.build.app.yaml', 'utf8'));
assert.equal(expected_snippet, registry.images["php"].config.build.snippet);
assert.equal(expected_snippet, fs.readFileSync('test/testdata/examples/snippet/php.build.app.yaml', 'utf8'));
});
it('Test <image>.dependencies.app.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected_commented = `# It is also possible to install additional system-level dependencies as part of
# the build process. These can be installed before the build hook runs using the
# native package manager for several web-focused languages. When specifying
# dependencies for each language, use the appropriate block for that language.
# DOCS: https://docs.upsun.com/anchors/fixed/app/reference/dependencies/
dependencies:
python3:
pipenv: 2018.10.13`;
let expected_full = `dependencies:
python3:
pipenv: 2018.10.13`;
let expected_snippet = `dependencies:
python3:
pipenv: 2018.10.13`;
assert.equal(expected_commented, registry.images["python"].config.dependencies.commented);
assert.equal(expected_commented, fs.readFileSync('test/testdata/examples/commented/python.dependencies.app.yaml', 'utf8'));
assert.equal(expected_full, registry.images["python"].config.dependencies.full);
assert.equal(expected_full, fs.readFileSync('test/testdata/examples/full/python.dependencies.app.yaml', 'utf8'));
assert.equal(expected_snippet, registry.images["python"].config.dependencies.snippet);
assert.equal(expected_snippet, fs.readFileSync('test/testdata/examples/snippet/python.dependencies.app.yaml', 'utf8'));
});
it('Test <image>.hooks.app.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected_commented = `# Upsun Fixed supports three "hooks", or points in the deployment of a new version of an
# application that you can inject a custom script into. Each runs at a different stage
# of the process.
# DOCS: https://docs.upsun.com/anchors/fixed/app/hooks/compare/
hooks:
# The 'build' hook is run after the build flavor (if any). The file system is fully writable,
# but no services (such as a database) are available nor are any persistent file mounts, as the
# application has not yet been deployed.
# DOCS: https://docs.upsun.com/anchors/fixed/app/hooks/compare/build/
build: |
bundle install --without development test
# The 'deploy' hook is run after the application container has been started, but before it
# has started accepting requests. Services are accesible at this stage. The file system is
# read-only from this stage onward excluding defined mounts.
# DOCS: https://docs.upsun.com/anchors/fixed/app/hooks/compare/deploy/
deploy: |
RACK_ENV=production bundle exec rake db:migrate`;
let expected_full = `hooks:
build: |
bundle install --without development test
deploy: |
RACK_ENV=production bundle exec rake db:migrate`;
let expected_snippet = `hooks:
build: |
bundle install --without development test
deploy: |
RACK_ENV=production bundle exec rake db:migrate`;
assert.equal(expected_commented, registry.images["ruby"].config.hooks.commented);
assert.equal(expected_commented, fs.readFileSync('test/testdata/examples/commented/ruby.hooks.app.yaml', 'utf8'));
assert.equal(expected_full, registry.images["ruby"].config.hooks.full);
assert.equal(expected_full, fs.readFileSync('test/testdata/examples/full/ruby.hooks.app.yaml', 'utf8'));
assert.equal(expected_snippet, registry.images["ruby"].config.hooks.snippet);
assert.equal(expected_snippet, fs.readFileSync('test/testdata/examples/snippet/ruby.hooks.app.yaml', 'utf8'));
});
it('Test <image>.web.app.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected_commented = `# The 'web' key defines a single web instance container running a single web server
# process (currently Nginx), behind which runs your application. It configures
# the web server, including what requests should be served directly
# (such as static files) and which should be passed to your application.
# DOCS: https://docs.upsun.com/anchors/fixed/app/reference/web/
web:
# 'upstream' specifies how the front server will connect to your application
# (the process started by 'commands.start').
# DOCS: https://docs.upsun.com/anchors/fixed/app/reference/web/upstream/
upstream:
# Describes whether your application will listen on a Unix socket
# ('unix') or a TCP socket ('tcp'). Default: 'tcp'.
# DOCS: https://docs.upsun.com/anchors/fixed/app/reference/web/upstream/socket-family/
socket_family: tcp
# Specifies whether your application is going to receive incoming requests
# over HTTP ('http') or FastCGI ('fastcgi'). Default is runtime-dependent.
protocol: http
# The 'commands' key defines the command to launch the application.
# DOCS: https://docs.upsun.com/anchors/fixed/app/reference/web/commands/
commands:
# The 'start' key specifies the command to use to launch your application.
# If the command specified by the 'start' key terminates it will
# be restarted automatically.
start: ./bin/app
# 'locations' allows you to control how the application container responds
# to incoming requests at a very fine-grained level.
# DOCS: https://docs.upsun.com/anchors/fixed/app/reference/web/locations/
locations:
/:
# Whether to forward disallowed and missing resources from this
# location to the application. Can be 'true', 'false', or an absolute
# URI path (as in PHP, when it is typically the front controller).
passthru: true
# Whether to allow serving files which don't match a rule. Default 'true'.
allow: false`;
let expected_full = `web:
upstream:
socket_family: tcp
protocol: http
commands:
start: ./bin/app
locations:
/:
passthru: true
allow: false`;
let expected_snippet = `web:
upstream:
socket_family: tcp
protocol: http
commands:
start: ./bin/app
locations:
/:
passthru: true
allow: false`;
assert.equal(expected_commented, registry.images["golang"].config.web.commented);
assert.equal(expected_commented, fs.readFileSync('test/testdata/examples/commented/golang.web.app.yaml', 'utf8'));
assert.equal(expected_full, registry.images["golang"].config.web.full);
assert.equal(expected_full, fs.readFileSync('test/testdata/examples/full/golang.web.app.yaml', 'utf8'));
assert.equal(expected_snippet, registry.images["golang"].config.web.snippet);
assert.equal(expected_snippet, fs.readFileSync('test/testdata/examples/snippet/golang.web.app.yaml', 'utf8'));
});
})
describe('Writing files: Special cases', function() {
it('Varnish: Test commented services.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `# The name given to the Varnish service (lowercase alphanumeric only).
proxy:
# The type of your service (varnish), which uses the format
# 'type:version'. Be sure to consult the Varnish documentation
# (https://docs.upsun.com/anchors/fixed/services/varnish/#supported-versions)
# when choosing a version. If you specify a version number which is not available,
# the CLI will return an error.
type: varnish:6.0
# The 'relationships' block defines a relationship ('application') to the application
# container ('app') using the 'http' endpoint, and is what allows Varnish to
# talk to the application container.
relationships:
application: 'app:http'
# The 'configuration' block is required, and references the VCL file (config.vcl) which
# is relative to the .platform directory.
configuration:
vcl: !include
type: string
path: config.vcl`;
assert.equal(expected, registry.images["varnish"].config.services.commented);
assert.equal(expected, fs.readFileSync('test/testdata/examples/commented/varnish.services.yaml', 'utf8'));
});
it('Varnish: Test full app.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
var expected = `relationships:
varnishstats: "proxy:http+stats"`;
assert.equal(expected, registry.images["varnish"].config.app.full);
assert.equal(expected, fs.readFileSync('test/testdata/examples/full/varnish.app.yaml', 'utf8'));
});
it('Varnish: Test snippet routes.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
var expected = `"https://{default}/":
type: upstream
upstream: "varnish:http"
cache:
enabled: false`;
assert.equal(expected, registry.images["varnish"].config.routes.snippet);
assert.equal(expected, fs.readFileSync('test/testdata/examples/snippet/varnish.routes.yaml', 'utf8'));
});
it('NetworkStorage: Test commented app.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
var expected = `# Network Storage allows you to define a file store that can be shared between different application containers.
# The service enables a new kind of 'mount' that refers to a shared service rather than to a local directory.
# After you have declared the service files in your 'services.yaml' file, add an entry
# to your mounts list for it. Upsun Fixed is read-only by default after the build process is completed, and defining mounts
# is the only way to set aside writable disk on a deployed application. Consult the mounts documentation
# (https://docs.upsun.com/anchors/fixed/app/reference/mounts/) for more details.
# Note that you do not need to add a relationship to point to the files service. That is handled automatically by the system.
mounts:
# Declare the writable mount path 'my/files' on the application container.
'my/files':
# The source for the mount is defined as the service 'files' rather than a local directory.
source: service
service: files
# The source_path specifies the path within the network service that the mount points to. It is
# often easiest to have it match the name of the mount point itself but that is not required.
source_path: files`;
assert.equal(expected, registry.images["network-storage"].config.app.commented);
assert.equal(expected, fs.readFileSync('test/testdata/examples/commented/network-storage.app.yaml', 'utf8'));
});
it('NetworkStorage: Test full services.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
var expected = `files:
type: network-storage:1.0
disk: 256`;
assert.equal(expected, registry.images["network-storage"].config.services.full);
assert.equal(expected, fs.readFileSync('test/testdata/examples/full/network-storage.services.yaml', 'utf8'));
});
it('NetworkStorage: Test snippet app.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
var expected = ` 'my/files':
source: service
service: files
source_path: files`;
assert.equal(expected, registry.images["network-storage"].config.app.snippet);
assert.equal(expected, fs.readFileSync('test/testdata/examples/snippet/network-storage.app.yaml', 'utf8'));
});
})
describe('Writing files: Additional types', function() {
it('Test snippet mysql services.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `db:
type: mysql:10.4
disk: 256`;
assert.equal(expected, registry.images["mysql"].config.services.snippet);
assert.equal(expected, fs.readFileSync('test/testdata/examples/snippet/mysql.services.yaml', 'utf8'));
});
it('Test full persistentRedis services.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `data:
type: redis-persistent:5.0
disk: 256`;
assert.equal(expected, registry.images["redis-persistent"].config.services.snippet);
assert.equal(expected, fs.readFileSync('test/testdata/examples/snippet/redis-persistent.services.yaml', 'utf8'));
});
it('Test commented persistentRedis services.yaml writes correctly', function() {
let registrySource = "test/testdata/valid.json";
let registry = new psh.RegistryParser(registrySource);
let expected = `# The relationships block defines how services are mapped within your application.
relationships:
# The relationship is specified in the form 'service_name:endpoint_name'.
# The 'service_name' is the name of the service given in '.platform.services.yaml'.
# The 'endpoint_name' is the exposed functionality of the service to use. In most
# cases this is simply the same as the service 'type', but there are a few exceptions.
redisdata: "data:redis"`;
assert.equal(expected, registry.images["redis-persistent"].config.app.commented);
assert.equal(expected, fs.readFileSync('test/testdata/examples/commented/redis-persistent.app.yaml', 'utf8'));
});
})
})