-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest.js
More file actions
135 lines (94 loc) · 4.74 KB
/
test.js
File metadata and controls
135 lines (94 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import path from 'node:path'
import os from 'node:os'
import fs from 'node:fs'
import { expect } from 'chai'
import { GDF, defaults } from '../gdf.js'
import '../fly.js'
for (const group of fs.readdirSync('test', { withFileTypes: true })) {
if (!group.isDirectory()) continue
process.env.NODE_ENV = 'test'
for (const entry of fs.readdirSync(path.join('test', group.name), { withFileTypes: true })) {
if (!fs.existsSync(path.join('test', group.name, entry.name, 'package.json'))) continue
describe(`${group.name}: ${entry.name}`, function() {
const workdir = path.join(os.tmpdir(), group.name, entry.name)
const testdir = path.join('test', group.name, entry.name)
if (fs.existsSync(workdir)) fs.rmSync(workdir, { recursive: true })
fs.cpSync(testdir, workdir, { recursive: true })
const pj = fs.readFileSync(path.join(testdir, 'package.json'), 'utf-8')
const options = { ...defaults, ...(JSON.parse(pj).dockerfile || {}) }
if (options.envs) options.vars = options.envs
options.force = true
it('should produce a dockerfile', async function() {
await new GDF().run(workdir, options)
let argmask = /^(ARG\s+\w+\s*=).*?(\s*\\?)$/gm
if (entry.name === 'version') argmask = /()xxx()/g
const actualResults = fs.readFileSync(path.join(workdir, 'Dockerfile'), 'utf-8')
.replaceAll(argmask, '$1xxx$2')
if (process.env.TEST_CAPTURE) {
fs.writeFileSync(path.join(testdir, 'Dockerfile'), actualResults)
}
const expectedResults = fs.readFileSync(path.join(testdir, 'Dockerfile'), 'utf-8')
.replaceAll(argmask, '$1xxx$2')
expect(expectedResults).to.equal(actualResults)
})
it('should produce a .dockerignore', async function() {
await new GDF().run(workdir, options)
const actualResults = fs.readFileSync(path.join(workdir, '.dockerignore'), 'utf-8')
if (process.env.TEST_CAPTURE) {
fs.writeFileSync(path.join(testdir, '.dockerignore'), actualResults)
}
const expectedResults = fs.readFileSync(path.join(testdir, '.dockerignore'), 'utf-8')
expect(expectedResults).to.equal(actualResults)
})
if (fs.existsSync(path.join(testdir, 'docker-entrypoint.js'))) {
it('should produce a docker-entrypoint', async function() {
await new GDF().run(workdir, options)
let entrypoint = path.join(workdir, 'docker-entrypoint.js')
const other = path.join(workdir, 'other', 'docker-entrypoint.js')
if (fs.existsSync(other)) entrypoint = other
const actualResults = fs.readFileSync(entrypoint, 'utf-8')
if (process.env.TEST_CAPTURE) {
fs.writeFileSync(path.join(testdir, 'docker-entrypoint.js'), actualResults)
}
const expectedResults = fs.readFileSync(path.join(testdir, 'docker-entrypoint.js'), 'utf-8')
expect(expectedResults).to.equal(actualResults)
})
}
if (fs.existsSync(path.join(testdir, 'litefs.yml'))) {
it('should produce a litefs.yml', async function() {
await new GDF().run(workdir, options)
const actualResults = fs.readFileSync(path.join(workdir, 'litefs.yml'), 'utf-8')
if (process.env.TEST_CAPTURE) {
fs.writeFileSync(path.join(testdir, 'litefs.yml'), actualResults)
}
const expectedResults = fs.readFileSync(path.join(testdir, 'litefs.yml'), 'utf-8')
expect(expectedResults).to.equal(actualResults)
})
}
if (fs.existsSync(path.join(testdir, 'litestream.yml'))) {
it('should produce a litestream.yml', async function() {
await new GDF().run(workdir, options)
const actualResults = fs.readFileSync(path.join(workdir, 'litestream.yml'), 'utf-8')
if (process.env.TEST_CAPTURE) {
fs.writeFileSync(path.join(testdir, 'litestream.yml'), actualResults)
}
const expectedResults = fs.readFileSync(path.join(testdir, 'litestream.yml'), 'utf-8')
expect(expectedResults).to.equal(actualResults)
})
}
if (fs.existsSync(path.join(testdir, 'fly.toml'))) {
it('should produce a fly.toml', async function() {
let expectedResults = fs.readFileSync(path.join(testdir, 'fly.toml'), 'utf-8')
fs.writeFileSync(path.join(workdir, 'fly.toml'), '')
await new GDF().run(workdir, options)
const actualResults = fs.readFileSync(path.join(workdir, 'fly.toml'), 'utf-8')
if (process.env.TEST_CAPTURE) {
fs.writeFileSync(path.join(testdir, 'fly.toml'), actualResults)
expectedResults = actualResults
}
expect(expectedResults).to.equal(actualResults)
})
}
})
}
}