git: checkConfig no longer checks repo url. Git being down or latest version being unfetchable should not stop services from starting up.

Package: Remove beta flag, is stable enough for now
master
Jonatan Nilsson 2022-08-13 01:47:05 +00:00
parent 33b3d98a37
commit 63a06a2a34
5 changed files with 13 additions and 28 deletions

View File

@ -94,7 +94,7 @@ export default class Core {
hasCluster = true
}
} catch (err) {
this.log.error(err, `Error creating application ${name} with provider ${this.db.config[name].provider}: ${err.message}`)
this.log.error(err, `Error creating application ${name} with provider ${this.db.config[name].provider} with config ${JSON.stringify(this.db.config[name])}: ${err.message}`)
}
}
@ -128,6 +128,7 @@ export default class Core {
}
if (names.length && !this.applications.length) {
this.log.error('None of the application were successful in running')
return Promise.reject(new Error('None of the application were successful in running'))
}
}

View File

@ -55,10 +55,5 @@ export default class GitProvider {
if (typeof(this.config.url) !== 'string') return Promise.reject(new Error('url was not a valid url'))
try { new URL(this.config.url) }
catch (err) { return Promise.reject(new Error('url was not a valid url: ' + err.message)) }
return this.getLatestVersion()
.catch(function(err) {
return Promise.reject(new Error(`Error fetching latest release: ${err.message}`))
})
}
}

View File

@ -1,6 +1,6 @@
{
"name": "service-core",
"version": "3.0.0-beta.16",
"version": "3.0.0",
"description": "Core boiler plate code to install node server as windows service",
"main": "index.mjs",
"scripts": {

View File

@ -18,26 +18,24 @@ t.timeout(5000).describe('#getLatestVersion()', function() {
assert.ok(version.link)
assert.match(version.link, /\/attachments\//)
})
})
t.timeout(5000).describe('#checkConfig()', function() {
t.test('should fail if link does not return json repository object', async function() {
let err = await assert.isRejected(new GitProvider({ url: 'http://git.nfp.is/api/v1/repos/thething/ProgramQueuer' }).checkConfig())
let err = await assert.isRejected(new GitProvider({ url: 'http://git.nfp.is/api/v1/repos/thething/ProgramQueuer' }).getLatestVersion())
assert.match(err.message, /valid/i)
assert.match(err.message, /repository/i)
err = await assert.isRejected(new GitProvider({ url: 'http://git.nfp.is/api/v1/orgs/nfp/repos' }).checkConfig())
err = await assert.isRejected(new GitProvider({ url: 'http://git.nfp.is/api/v1/orgs/nfp/repos' }).getLatestVersion())
assert.match(err.message, /service-core/i)
assert.match(err.message, /release/i)
})
t.test('should fail if no active release repository with assets', async function() {
let err = await assert.isRejected(new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/thething/eltro/releases' }).checkConfig())
let err = await assert.isRejected(new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/thething/eltro/releases' }).getLatestVersion())
assert.match(err.message, /service-core/i)
assert.match(err.message, /release/i)
})
t.test('should fail on private repositories', async function() {
let err = await assert.isRejected(new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/TheThing/privateexample/releases' }).checkConfig())
let err = await assert.isRejected(new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/TheThing/privateexample/releases' }).getLatestVersion())
assert.match(err.message, /fail/i)
assert.match(err.message, /404/i)
assert.match(err.message, /release/i)
@ -45,19 +43,19 @@ t.timeout(5000).describe('#checkConfig()', function() {
t.test('should otherwise succeed', function() {
return new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/TheThing/sc-helloworld/releases' })
.checkConfig()
.getLatestVersion()
})
let test = t
if (!process.env.gittesttoken) {
console.log('Skipping "git.test.integration: #checkConfig() should succeed on private repo with token"')
console.log('Skipping "git.test.integration: #getLatestVersion() should succeed on private repo with token"')
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',
}).checkConfig()
}).getLatestVersion()
})
})

View File

@ -190,19 +190,10 @@ t.describe('#checkConfig()', function() {
}
})
t.test('should call requester with correct config and url', async function() {
const assertError = new Error('Toki wo Koeta Yoru')
const assertRequestConfig = { a: 1 }
t.test('should not call requester with correct config and url', async function() {
const assertUrl = 'http://test'
let provider = new GitProvider({ url: assertUrl }, stub())
provider.requestConfig = assertRequestConfig
provider.requester.rejects(assertError)
let err = await assert.isRejected(provider.checkConfig())
assert.notStrictEqual(err, assertError)
assert.match(err.message, new RegExp(assertError.message))
assert.strict(provider.requester.firstCall[0], assertRequestConfig)
assert.strict(provider.requester.firstCall[1], assertUrl)
let err = await provider.checkConfig()
assert.notOk(provider.requester.called)
})
})