1 | import DockerParser from '../src/DockerParser'
|
2 | import { Person, SoftwareEnvironment } from '@stencila/schema'
|
3 | import { fixture } from './test-functions'
|
4 | import MockUrlFetcher from './MockUrlFetcher'
|
5 |
|
6 | const urlFetcher = new MockUrlFetcher()
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | test('parse:strings', async () => {
|
13 | const parser = new DockerParser(urlFetcher, '')
|
14 | let environ
|
15 |
|
16 | environ = await parser.parse('FROM ubuntu') as SoftwareEnvironment
|
17 | expect(environ.authors).toEqual([])
|
18 |
|
19 |
|
20 | environ = await parser.parse('LABEL maintainer="Joe Bloggs <joe@bloggs.com> (https://bloggs.com/joe)"') as SoftwareEnvironment
|
21 | expect(environ.authors && environ.authors[0].name).toEqual('Joe Bloggs')
|
22 | const author = environ.authors && environ.authors[0] as Person
|
23 | expect(author).toBeDefined()
|
24 | expect(author && author.givenNames).toEqual(['Joe'])
|
25 | expect(author && author.familyNames).toEqual(['Bloggs'])
|
26 | expect(author && author.emails).toEqual(['joe@bloggs.com'])
|
27 | expect(author && author.urls).toEqual(['https://bloggs.com/joe'])
|
28 |
|
29 |
|
30 | environ = await parser.parse('LABEL maintainer="Joe Bloggs" description="My image"') as SoftwareEnvironment
|
31 | expect(environ.description).toEqual('My image')
|
32 | expect(environ.authors && environ.authors[0].name).toEqual('Joe Bloggs')
|
33 |
|
34 |
|
35 | environ = await parser.parse('LABEL maintainer="Joe Bloggs" maintainer="Peter Pan"') as SoftwareEnvironment
|
36 | expect(environ.authors && environ.authors[0].name).toEqual('Peter Pan')
|
37 |
|
38 |
|
39 | environ = await parser.parse('LABEL maintainer=Joe\\ Bloggs \\\ndescription="My image"') as SoftwareEnvironment
|
40 | expect(environ.description).toEqual('My image')
|
41 | expect(environ.authors && environ.authors[0].name).toEqual('Joe Bloggs')
|
42 |
|
43 |
|
44 | for (let prefix of ['org.opencontainers.image', 'org.label-schema']) {
|
45 | environ = await parser.parse(`LABEL ${prefix}.description="My image"`) as SoftwareEnvironment
|
46 | expect(environ.description).toEqual('My image')
|
47 | }
|
48 |
|
49 |
|
50 | environ = await parser.parse('MAINTAINER Peter Pan') as SoftwareEnvironment
|
51 | expect(environ.authors && environ.authors[0].name).toEqual('Peter Pan')
|
52 |
|
53 |
|
54 | environ = await parser.parse('LABEL maintainer="Joe Bloggs"\n MAINTAINER Peter Pan\n MAINTAINER Capt Hook') as SoftwareEnvironment
|
55 | expect(environ.authors && environ.authors.length).toEqual(3)
|
56 | expect(environ.authors && environ.authors[0].name).toEqual('Joe Bloggs')
|
57 | expect(environ.authors && environ.authors[1].name).toEqual('Peter Pan')
|
58 | expect(environ.authors && environ.authors[2].name).toEqual('Capt Hook')
|
59 | })
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | test('parse:empty', async () => {
|
65 | const parser = new DockerParser(urlFetcher, fixture('empty'))
|
66 | expect(await parser.parse()).toBeNull()
|
67 | })
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | test('parse:r-date', async () => {
|
73 | const parser = new DockerParser(urlFetcher, fixture('r-date'))
|
74 | expect(await parser.parse()).toBeNull()
|
75 | })
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | test('parse:dockerfile-date', async () => {
|
82 | const parser = new DockerParser(urlFetcher, fixture('dockerfile-date'))
|
83 | const environ = await parser.parse() as SoftwareEnvironment
|
84 | expect(environ.description && environ.description.substring(0, 23)).toEqual('Prints the current date')
|
85 | expect(environ.authors && environ.authors[0].name).toEqual('Nokome Bentley')
|
86 | })
|