Skip to content
Snippets Groups Projects
Commit 0131ccb5 authored by richard.petersen's avatar richard.petersen :sailboat:
Browse files

fixed: OXUIB-1621 /meta does not work with disabled redis

parent 18f0711f
No related branches found
No related tags found
No related merge requests found
...@@ -73,6 +73,7 @@ describe('Responses contain custom headers', function () { ...@@ -73,6 +73,7 @@ describe('Responses contain custom headers', function () {
}) })
it('does not have metadata from ui service when unavailable', async function () { it('does not have metadata from ui service when unavailable', async function () {
await import('../src/cache.js').then(({ clear }) => clear())
const response = await request(app).get('/meta') const response = await request(app).get('/meta')
expect(response.statusCode).to.equal(200) expect(response.statusCode).to.equal(200)
expect(response.body).to.not.deep.contain({ expect(response.body).to.not.deep.contain({
...@@ -81,4 +82,36 @@ describe('Responses contain custom headers', function () { ...@@ -81,4 +82,36 @@ describe('Responses contain custom headers', function () {
}) })
}) })
}) })
describe('without redis disabled', function () {
let prevConfig
beforeEach(async function () {
td.reset()
mockConfig({ urls: ['http://ui-server/'] })
mockFetch(fetchConfig = {
'http://ui-server': {
'/manifest.json': generateSimpleViteManifest({
'example.js': {}
}),
'/example.js': () => new Response('this is example', { headers: { 'content-type': 'application/javascript' } }),
'/meta.json': { name: 'sample-service', version: '1.0' }
}
})
app = await mockApp()
})
afterEach(function () {
fetchConfig['http://ui-server'] = prevConfig
})
it('has metadata', async function () {
const response = await request(app).get('/meta')
expect(response.statusCode).to.equal(200)
expect(response.body).to.deep.contain({
name: 'sample-service',
version: '1.0'
})
})
})
}) })
...@@ -14,6 +14,12 @@ export async function getBuffer (key) { ...@@ -14,6 +14,12 @@ export async function getBuffer (key) {
return get(key, { method: 'getBuffer' }) return get(key, { method: 'getBuffer' })
} }
export async function clear () {
for (const prop of Object.getOwnPropertyNames(cache)) {
delete cache[prop]
}
}
export async function get (key, { method = 'get' } = {}) { export async function get (key, { method = 'get' } = {}) {
if (cache[key]) return cache[key] if (cache[key]) return cache[key]
......
import { config } from './config.js' import { config } from './config.js'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import { client } from './redis.js' import * as cache from './cache.js'
import { getRedisKey } from './util.js' import { getRedisKey } from './util.js'
export async function getMergedMetadata ({ version }) { export async function getMergedMetadata ({ version }) {
const metadata = await client.get(getRedisKey({ version, name: 'mergedMetadata' })) const metadata = await cache.get(getRedisKey({ version, name: 'mergedMetadata' }))
if (metadata) return JSON.parse(metadata) if (metadata) return JSON.parse(metadata)
await config.load() await config.load()
...@@ -29,6 +29,6 @@ export async function getMergedMetadata ({ version }) { ...@@ -29,6 +29,6 @@ export async function getMergedMetadata ({ version }) {
// only return when contains data // only return when contains data
const filtered = newMetadata.filter(Boolean) const filtered = newMetadata.filter(Boolean)
await client.set(getRedisKey({ version, name: 'mergedMetadata' }), JSON.stringify(filtered)) await cache.set(getRedisKey({ version, name: 'mergedMetadata' }), JSON.stringify(filtered))
return filtered return filtered
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment