feat: insert stress testing machines into DB

This commit is contained in:
siiky 2025-03-17 23:33:38 +00:00
parent 0a120203be
commit 99dd90d51a
5 changed files with 74 additions and 41 deletions

View file

@ -1,6 +1,6 @@
const fs = require('node:fs')
const os = require('node:os')
const path = require('node:path')
const { readFileSync, writeFileSync } = require('node:fs')
const { EOL } = require('node:os')
const { resolve } = require('node:path')
const dotenv = require('dotenv')
@ -30,10 +30,10 @@ const help = (exit_code) => {
}
const env_read = (path) => {
const envstr = fs.readFileSync(path, { encoding: 'utf8' })
const envstr = readFileSync(path, { encoding: 'utf8' })
return dotenv.parse(envstr)
//const entries = envstr
// .split(os.EOL)
// .split(EOL)
// .flatMap((line) => {
// line = line.trimStart()
// const i = line.indexOf('=')
@ -51,8 +51,8 @@ const env_read = (path) => {
const env_write = (envvars, path) => {
const envcontent = Object.entries(envvars)
.map(([varname, value]) => [varname, value].join('='))
.join(os.EOL) + os.EOL
fs.writeFileSync(path, envcontent)
.join(EOL) + EOL
writeFileSync(path, envcontent)
}
const run = async (args) => {
@ -70,10 +70,10 @@ const run = async (args) => {
return help(EXIT.BADARGS)
}
const inenvpath = path.resolve(process.cwd(), options.inenv ?? ".env")
const inenvpath = resolve(process.cwd(), options.inenv ?? ".env")
const inenvvars = env_read(inenvpath)
const outenvpath = path.resolve(process.cwd(), options.outenv ?? ".stress.env")
const outenvpath = resolve(process.cwd(), options.outenv ?? ".stress.env")
const outenvvars = {
...inenvvars,
POSTGRES_USER: options.dbuser ?? "postgres",