2022-01-21 02:43:48 +00:00
|
|
|
import { Eltro as t, assert, stub } from 'eltro'
|
|
|
|
import Util from '../../core/util.mjs'
|
|
|
|
import fs from 'fs/promises'
|
|
|
|
import GitProvider from '../../core/providers/git.mjs'
|
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
t.after(function() {
|
|
|
|
return fs.rm('./test/providers/file.7z')
|
|
|
|
.catch(function() { })
|
|
|
|
})
|
2022-01-21 02:43:48 +00:00
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
t.timeout(5000).describe('#getLatestVersion()', function() {
|
|
|
|
t.test('should return latest version in a valid repository', async function() {
|
|
|
|
let provider = new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/thething/sc-helloworld/releases' })
|
|
|
|
let version = await provider.getLatestVersion()
|
|
|
|
assert.ok(version)
|
|
|
|
assert.ok(version.version)
|
|
|
|
assert.ok(version.description)
|
|
|
|
assert.ok(version.link)
|
|
|
|
assert.match(version.link, /\/attachments\//)
|
2022-01-21 02:43:48 +00:00
|
|
|
})
|
2022-02-11 13:59:10 +00:00
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
t.test('should fail if link does not return json repository object', async function() {
|
2022-08-13 01:47:05 +00:00
|
|
|
let err = await assert.isRejected(new GitProvider({ url: 'http://git.nfp.is/api/v1/repos/thething/ProgramQueuer' }).getLatestVersion())
|
2022-02-18 08:16:36 +00:00
|
|
|
assert.match(err.message, /valid/i)
|
|
|
|
assert.match(err.message, /repository/i)
|
2022-08-13 01:47:05 +00:00
|
|
|
err = await assert.isRejected(new GitProvider({ url: 'http://git.nfp.is/api/v1/orgs/nfp/repos' }).getLatestVersion())
|
2022-02-18 08:16:36 +00:00
|
|
|
assert.match(err.message, /service-core/i)
|
|
|
|
assert.match(err.message, /release/i)
|
|
|
|
})
|
2022-02-11 13:59:10 +00:00
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
t.test('should fail if no active release repository with assets', async function() {
|
2022-08-13 01:47:05 +00:00
|
|
|
let err = await assert.isRejected(new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/thething/eltro/releases' }).getLatestVersion())
|
2022-02-18 08:16:36 +00:00
|
|
|
assert.match(err.message, /service-core/i)
|
|
|
|
assert.match(err.message, /release/i)
|
|
|
|
})
|
2022-02-11 13:59:10 +00:00
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
t.test('should fail on private repositories', async function() {
|
2022-08-13 01:47:05 +00:00
|
|
|
let err = await assert.isRejected(new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/TheThing/privateexample/releases' }).getLatestVersion())
|
2022-02-18 08:16:36 +00:00
|
|
|
assert.match(err.message, /fail/i)
|
|
|
|
assert.match(err.message, /404/i)
|
|
|
|
assert.match(err.message, /release/i)
|
|
|
|
})
|
2022-01-21 02:43:48 +00:00
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
t.test('should otherwise succeed', function() {
|
2022-02-18 13:31:56 +00:00
|
|
|
return new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/TheThing/sc-helloworld/releases' })
|
2022-08-13 01:47:05 +00:00
|
|
|
.getLatestVersion()
|
2022-02-18 08:16:36 +00:00
|
|
|
})
|
2022-01-21 02:43:48 +00:00
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
let test = t
|
|
|
|
if (!process.env.gittesttoken) {
|
2022-08-13 01:47:05 +00:00
|
|
|
console.log('Skipping "git.test.integration: #getLatestVersion() should succeed on private repo with token"')
|
2022-02-18 08:16:36 +00:00
|
|
|
test = test.skip()
|
|
|
|
}
|
|
|
|
test.test('should succeed on private repo with token', function() {
|
|
|
|
return new GitProvider({
|
|
|
|
token: process.env.gittesttoken.trim(),
|
|
|
|
url: 'https://git.nfp.is/api/v1/repos/TheThing/privateexample/releases',
|
2022-08-13 01:47:05 +00:00
|
|
|
}).getLatestVersion()
|
2022-01-21 02:43:48 +00:00
|
|
|
})
|
2022-02-18 08:16:36 +00:00
|
|
|
})
|
2022-01-21 02:43:48 +00:00
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
t.timeout(5000).describe('#downloadVersion()', function() {
|
|
|
|
const util = new Util(import.meta.url)
|
2022-01-21 02:43:48 +00:00
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
let test = t
|
|
|
|
if (!process.env.gittesttoken) {
|
|
|
|
console.log('Skipping "git.test.integration: #downloadVersion() should successfully download release"')
|
|
|
|
test = test.skip()
|
|
|
|
}
|
|
|
|
test.test('should successfully download release', async function() {
|
|
|
|
let provider = new GitProvider({
|
|
|
|
token: process.env.gittesttoken.trim(),
|
|
|
|
url: 'https://git.nfp.is/api/v1/repos/TheThing/privateexample/releases',
|
|
|
|
})
|
|
|
|
await provider.checkConfig()
|
|
|
|
let version = await provider.getLatestVersion()
|
|
|
|
assert.ok(version.version)
|
|
|
|
assert.ok(version.filename)
|
|
|
|
assert.ok(version.link)
|
2022-01-21 02:43:48 +00:00
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
let path = util.getPathFromRoot('./file.7z')
|
|
|
|
await provider.downloadVersion(version, path)
|
2022-01-21 02:43:48 +00:00
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
let stat = await fs.stat(path)
|
|
|
|
assert.ok(stat.size > 0)
|
|
|
|
stat = await fs.stat('./test/providers/file.7z')
|
|
|
|
assert.ok(stat.size > 0)
|
2022-01-21 02:43:48 +00:00
|
|
|
|
2022-02-18 08:16:36 +00:00
|
|
|
let output = ''
|
|
|
|
await util.runCommand(util.get7zipExecutable(), ['l', 'file.7z'], util.getPathFromRoot('./'), function(chunk) {
|
|
|
|
output += chunk + '\n'
|
2022-01-21 02:43:48 +00:00
|
|
|
})
|
2022-02-18 08:16:36 +00:00
|
|
|
assert.ok(output.indexOf('file1.txt'))
|
|
|
|
assert.ok(output.indexOf('file2.txt'))
|
2022-01-21 02:43:48 +00:00
|
|
|
})
|
|
|
|
})
|