Skip to content

Commit

Permalink
ufsv tests: add support for UNFURL_TEST_TMPDIR and UNFURL_CMD env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
aszs committed Jan 11, 2024
1 parent cdcbb7b commit 90ba5a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion ufsv-patch/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const OC_NAMESPACE = process.env.OC_NAMESPACE || 'onecommons/blueprints'
const OC_URL = process.env.OC_URL || 'https://unfurl.cloud'
const PORT = process.env.PORT || '5001'
const UNFURL_SERVER_URL = `http://localhost:${PORT}`
const TMP_DIR = process.env.UNFURL_TEST_TMPDIR || "./tmp"

import {expect, jest} from '@jest/globals'
import axios from '~/lib/utils/axios_utils'
Expand Down Expand Up @@ -186,7 +187,7 @@ class Fixture {
response = await interceptMethod(newUrl, ...args)
const fnameUrl = new URL(newUrl)

fs.writeFileSync(`/tmp/ufsv-intercepted/${Date.now()}-${encodeURIComponent(fnameUrl.pathname.slice(1) + fnameUrl.search)}`, JSON.stringify({
fs.writeFileSync(`${TMP_DIR}/ufsv-intercepted/${Date.now()}-${encodeURIComponent(fnameUrl.pathname.slice(1) + fnameUrl.search)}`, JSON.stringify({
req: [
newUrl,
...args
Expand Down
2 changes: 1 addition & 1 deletion ufsv-patch/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rm -r $UNFURL_SERVER_CWD/*

set -e

tar --owner $(id -u) --group $(id -g) -xvf ufsv-patch/test-dashboard.tgz -C $UNFURL_SERVER_CWD
tar -xvf ufsv-patch/test-dashboard.tgz -C $UNFURL_SERVER_CWD
back=$PWD
cd $UNFURL_SERVER_CWD
git checkout .
Expand Down
20 changes: 11 additions & 9 deletions ufsv-patch/ufsv-patch.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {sleep} from 'oc_vue_shared/client_utils/misc'
import glob from 'glob'
const globSync = glob.sync

const TMP_DIR = process.env.UNFURL_TEST_TMPDIR || "/tmp"
const SPEC_GLOBS = process.env.SPEC_GLOBS || ''
const TEST_VERSIONS = process.env.TEST_VERSIONS || 'v2'
const UNFURL_SERVER_CWD = '/tmp/ufsv'
const UNFURL_CMD = process.env.UNFURL_CMD || 'unfurl'
const UNFURL_SERVER_CWD = TMP_DIR + '/ufsv'
const OC_URL = process.env.OC_URL || 'https://unfurl.cloud'
const PORT = process.env.PORT || '5001'
const UNFURL_SERVER_URL = `http://localhost:${PORT}`
Expand Down Expand Up @@ -43,26 +45,26 @@ function setupCmd() {
}

function testToUfsvLogPath(testName) {
return `/tmp/${testName}-ufsv.log`
return `${TMP_DIR}/${testName}-ufsv.log`
}

function testToDryrunLogPath(testName) {
return `/tmp/${testName}-ufdryrun.log`
return `${TMP_DIR}/${testName}-ufdryrun.log`
}

function testToArtifactPath(testName) {
return `/tmp/ufartifacts/${testName}`
return `${TMP_DIR}/ufartifacts/${testName}`
}

function spawnUnfurlServer(testName) {
const outfile = fs.openSync(testToUfsvLogPath(testName), 'w')
const cmd = '/usr/bin/env'
const args = [
'unfurl',
UNFURL_CMD,
'serve', '.',
'--cloud-server', OC_URL,
'--port', PORT,
'--clone-root', '/tmp/repos'
'--clone-root', `${TMP_DIR}/repos`
]

writeLine('serve command: ', [cmd, ...args].join(' '))
Expand Down Expand Up @@ -100,7 +102,7 @@ function spawnDryrunSync(fixture) {
const cmd = '/usr/bin/env'

const args = [
'unfurl',
UNFURL_CMD,
'deploy',
'--dryrun',
'--use-environment', fixture.environment,
Expand Down Expand Up @@ -157,7 +159,7 @@ function sectionEnd(name) {
}

function setupTestDirectories() {
for(const requiredDir of ['/tmp/ufsv', '/tmp/ufartifacts', '/tmp/repos', '/tmp/ufsv-intercepted']) {
for(const requiredDir of [`${TMP_DIR}/ufsv`, `${TMP_DIR}/ufartifacts`, `${TMP_DIR}/repos`, `${TMP_DIR}/ufsv-intercepted`]) {
try {
fs.mkdirSync(requiredDir)
} catch(e) {}
Expand Down Expand Up @@ -216,7 +218,7 @@ async function runSpecs() {
} catch(e) {}

try {
fs.renameSync(`/tmp/ufsv/${fixture.deploymentDir}`, testToArtifactPath(testName))
fs.renameSync(`${TMP_DIR}/ufsv/${fixture.deploymentDir}`, testToArtifactPath(testName))
} catch(e) { console.error(e.message) }

expect(dryrun.status).toBe(0)
Expand Down

0 comments on commit 90ba5a0

Please sign in to comment.