Update create-matrix.js

This commit is contained in:
Aleksandr Statciuk 2022-02-07 06:11:40 +03:00
parent 091d43c4f7
commit 002d8804df
2 changed files with 8 additions and 11 deletions

View File

@ -1,7 +1,8 @@
const { logger, db } = require('../core') const { logger, db } = require('../core')
async function main() { async function main() {
const docs = await db.find({}).sort({ cluster_id: 1 }) await db.streams.load()
const docs = await db.streams.find({}).sort({ cluster_id: 1 })
const cluster_id = docs.reduce((acc, curr) => { const cluster_id = docs.reduce((acc, curr) => {
if (!acc.includes(curr.cluster_id)) acc.push(curr.cluster_id) if (!acc.includes(curr.cluster_id)) acc.push(curr.cluster_id)
return acc return acc

View File

@ -1,20 +1,16 @@
const fs = require('fs') const fs = require('fs-extra')
const path = require('path') const path = require('path')
const { execSync } = require('child_process') const { execSync } = require('child_process')
beforeEach(() => { beforeEach(() => {
fs.copyFileSync('tests/__data__/input/streams.db', 'tests/__data__/temp/streams.db') fs.emptyDirSync('tests/__data__/temp')
})
afterEach(() => { fs.copyFileSync('tests/__data__/input/database/streams.db', 'tests/__data__/temp/streams.db')
fs.rmdirSync('tests/__data__/temp', { recursive: true })
fs.mkdirSync('tests/__data__/temp')
}) })
it('can create valid matrix', () => { it('can create valid matrix', () => {
const result = execSync( const result = execSync('DB_DIR=tests/__data__/temp node scripts/commands/create-matrix.js', {
'DB_FILEPATH=tests/__data__/temp/streams.db node scripts/commands/create-matrix.js', encoding: 'utf8'
{ encoding: 'utf8' } })
)
expect(result).toBe('::set-output name=matrix::{"cluster_id":[1,3]}\n') expect(result).toBe('::set-output name=matrix::{"cluster_id":[1,3]}\n')
}) })