UNPKG

1.48 kBPlain TextView Raw
1import { SoftwareEnvironment, SoftwarePackage } from '@stencila/schema'
2
3import DockerGenerator from '../src/DockerGenerator'
4import MockUrlFetcher from './MockUrlFetcher'
5
6const urlFetcher = new MockUrlFetcher()
7
8/**
9 * When applied to an empty environment, generate should return
10 * Dockerfile with just FROM
11 */
12test('generate:empty', async () => {
13 const environ = new SoftwareEnvironment()
14 const generator = new DockerGenerator(urlFetcher, environ)
15 expect(await generator.generate(false)).toEqual(`FROM ubuntu:18.04
16
17RUN useradd --create-home --uid 1001 -s /bin/bash dockteruser
18WORKDIR /home/dockteruser
19
20USER dockteruser
21`)
22})
23
24/**
25 * When applied to an environment with packages from several languages, generate should return
26 * Dockerfile with R and the packages installed
27 */
28test('generate:packages', async () => {
29 const pkg0 = new SoftwarePackage()
30 pkg0.name = 'libxml2-dev'
31 pkg0.runtimePlatform = 'deb'
32
33 const pkg1 = new SoftwarePackage()
34 pkg1.name = 'xml2'
35 pkg1.runtimePlatform = 'R'
36 pkg1.softwareRequirements = [pkg0]
37
38 const pkg2 = new SoftwarePackage()
39 pkg2.name = 'bokeh'
40 pkg2.runtimePlatform = 'Python'
41 pkg2.softwareRequirements = []
42
43 const environ = new SoftwareEnvironment()
44 environ.datePublished = '2017-01-01'
45 environ.softwareRequirements = [pkg1, pkg2]
46
47 const generator = new DockerGenerator(urlFetcher, environ)
48 expect(generator.aptPackages('18.04')).toEqual(['libxml2-dev', 'python3', 'python3-pip', 'r-base'])
49})