Skip to content

Commit

Permalink
fix: nodejs test adapt OPENDAL_DISABLE_RANDOM_ROOT (#3456)
Browse files Browse the repository at this point in the history
* fix: nodejs test adapt `OPENDAL_DISABLE_RANDOM_ROOT`

Signed-off-by: suyanhanx <[email protected]>

* fix

Signed-off-by: suyanhanx <[email protected]>

* fix

Signed-off-by: suyanhanx <[email protected]>

* fix

Signed-off-by: suyanhanx <[email protected]>

* format

Signed-off-by: suyanhanx <[email protected]>

* fix workflow

Signed-off-by: suyanhanx <[email protected]>

* fix set toolchain

Signed-off-by: suyanhanx <[email protected]>

---------

Signed-off-by: suyanhanx <[email protected]>
  • Loading branch information
suyanhanx authored Nov 1, 2023
1 parent 82802b1 commit 6e44078
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ indent_size = 2
[*.{ts,tsx}]
indent_size = 2

[*.{js,jsx}]
[*.{mjs,js,jsx}]
indent_size = 2

[*.css]
Expand Down
44 changes: 22 additions & 22 deletions .github/actions/behavior_test_binding_nodejs/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ inputs:
runs:
using: "composite"
steps:
- name: Setup
shell: bash
run: |
mkdir -p ./dynamic_test_binding_nodejs &&
cat <<EOF >./dynamic_test_binding_nodejs/action.yml
runs:
using: composite
steps:
- name: Setup Test
uses: ./.github/services/${{ inputs.service }}/${{ inputs.setup }}
- name: Run Test Binding NodeJS
shell: bash
working-directory: bindings/nodejs
run: |
yarn build:debug
yarn test
env:
NAPI_FEATURES: ${{ inputs.feature }}
OPENDAL_TEST: ${{ inputs.service }}
EOF
- name: Run
uses: ./dynamic_test_binding_nodejs
- name: Setup
shell: bash
run: |
mkdir -p ./dynamic_test_binding_nodejs &&
cat <<EOF >./dynamic_test_binding_nodejs/action.yml
runs:
using: composite
steps:
- name: Setup Test
uses: ./.github/services/${{ inputs.service }}/${{ inputs.setup }}
- name: Run Test Binding NodeJS
shell: bash
working-directory: bindings/nodejs
run: |
yarn build:debug
yarn test
env:
NAPI_FEATURES: ${{ inputs.feature }}
OPENDAL_TEST: ${{ inputs.service }}
EOF
- name: Run
uses: ./dynamic_test_binding_nodejs
8 changes: 4 additions & 4 deletions .github/services/azdls/azdls/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ runs:
with:
export-env: true
env:
OPENDAL_AZDLS_FILESYSTEM: op://services/azdls/filesystem
OPENDAL_AZDLS_ENDPOINT: op://services/azdls/endpoint
OPENDAL_AZDLS_ACCOUNT_NAME: op://services/azdls/account_name
OPENDAL_AZDLS_ACCOUNT_KEY: op://services/azdls/account_key
OPENDAL_AZDLS_FILESYSTEM: op://services/azdls/filesystem
OPENDAL_AZDLS_ENDPOINT: op://services/azdls/endpoint
OPENDAL_AZDLS_ACCOUNT_NAME: op://services/azdls/account_name
OPENDAL_AZDLS_ACCOUNT_KEY: op://services/azdls/account_key
- name: Add extra settings
shell: bash
run: |
Expand Down
17 changes: 4 additions & 13 deletions .github/workflows/bindings_nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: ./.github/actions/setup
with:
need-nextest: true
- name: Setup node
uses: actions/setup-node@v4
with:
Expand All @@ -63,14 +65,11 @@ jobs:
- name: Check format
run: yarn run prettier --check .

- name: Build
run: yarn build:debug

- name: Check diff
run: git diff --exit-code

- name: Test bindings
run: yarn test
- name: Unit test
run: cargo nextest run --no-fail-fast

linux:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -107,8 +106,6 @@ jobs:
with:
name: bindings-linux
path: bindings/nodejs/*.node
- name: Test bindings
run: yarn test

windows:
runs-on: windows-latest
Expand Down Expand Up @@ -137,8 +134,6 @@ jobs:
with:
name: bindings-windows
path: bindings/nodejs/*.node
- name: Test bindings
run: yarn test

macos:
runs-on: macos-latest
Expand Down Expand Up @@ -190,10 +185,6 @@ jobs:
with:
name: bindings-macos-${{ matrix.settings.target }}
path: bindings/nodejs/*.node
- name: Test bindings
if: ${{ matrix.settings.test }}
run: ${{ matrix.settings.test }}
shell: bash

release:
name: Release
Expand Down
5 changes: 0 additions & 5 deletions bindings/nodejs/.env.example

This file was deleted.

7 changes: 4 additions & 3 deletions bindings/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@
{
"files": "./**/*.{js,ts,mjs}",
"options": {
"arrowParens": "always",
"parser": "typescript",
"printWidth": 120,
"semi": false,
"trailingComma": "all",
"singleQuote": true,
"arrowParens": "always",
"parser": "typescript"
"tabWidth": 2,
"trailingComma": "all"
}
}
]
Expand Down
6 changes: 6 additions & 0 deletions bindings/nodejs/tests/service.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
* under the License.
*/

import path from 'path'

import dotenv from 'dotenv'

import { runner } from './suites/index.mjs'
import { loadTestSchemeFromEnv } from './utils.mjs'

dotenv.config({ path: path.resolve(__dirname, '../../../.env'), debug: true })

runner('Behavior Test', loadTestSchemeFromEnv())
16 changes: 8 additions & 8 deletions bindings/nodejs/tests/suites/async.suite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import { expect, test } from 'vitest'
import { generateBytes } from '../utils.mjs'

export function run(operator) {
test('async stat not exist files', async () => {
const filename = `random_file_${randomUUID()}`
test('async stat not exist files', async () => {
const filename = `random_file_${randomUUID()}`

try {
await operator.stat(filename)
} catch (error) {
assert.ok(error.message.includes('NotFound'))
}
})
try {
await operator.stat(filename)
} catch (error) {
assert.ok(error.message.includes('NotFound'))
}
})
}
28 changes: 15 additions & 13 deletions bindings/nodejs/tests/suites/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,27 @@

import { describe } from 'vitest'
import { Operator } from '../../index.js'
import { loadConfigFromEnv } from '../utils.mjs'
import { checkRandomRootEnabled, generateRandomRoot, loadConfigFromEnv } from '../utils.mjs'

import { run as AsyncIOTestRun } from './async.suite.mjs'
import { run as SyncIOTestRun } from './sync.suite.mjs'

export function runner(testName, scheme) {
if (testName === null || testName === undefined) {
throw new Error('The scheme should not be `null` or `undefined`. ')
}
if (!scheme) {
console.warn('The scheme is empty. Test will be skipped.')
return
}

if (testName === '') {
return
}
const config = loadConfigFromEnv(scheme)

const config = loadConfigFromEnv(scheme)
const operator = scheme ? new Operator(scheme, config) : undefined
if (checkRandomRootEnabled()) {
config.root = generateRandomRoot(config.root)
}

describe.skipIf(!operator)(testName, () => {
AsyncIOTestRun(operator)
SyncIOTestRun(operator)
})
const operator = scheme ? new Operator(scheme, config) : null

describe.skipIf(!operator)(testName, () => {
AsyncIOTestRun(operator)
SyncIOTestRun(operator)
})
}
16 changes: 8 additions & 8 deletions bindings/nodejs/tests/suites/sync.suite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import { expect, test } from 'vitest'
import { generateBytes } from '../utils.mjs'

export function run(operator) {
test('sync stat not exist files', () => {
const filename = `random_file_${randomUUID()}`
test('sync stat not exist files', () => {
const filename = `random_file_${randomUUID()}`

try {
operator.statSync(filename)
} catch (error) {
assert.ok(error.message.includes('NotFound'))
}
})
try {
operator.statSync(filename)
} catch (error) {
assert.ok(error.message.includes('NotFound'))
}
})
}
41 changes: 24 additions & 17 deletions bindings/nodejs/tests/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,40 @@
* under the License.
*/

const path = require('path')
import crypto from 'node:crypto'

export function generateBytes() {
const size = Math.floor(Math.random() * 1024) + 1
const content = []
const size = Math.floor(Math.random() * 1024) + 1
const content = []

for (let i = 0; i < size; i++) {
content.push(Math.floor(Math.random() * 256))
}
for (let i = 0; i < size; i++) {
content.push(Math.floor(Math.random() * 256))
}

return Buffer.from(content)
return Buffer.from(content)
}

export function loadTestSchemeFromEnv() {
require('dotenv').config({ path: path.resolve(__dirname, '../../../.env'), debug: true })
return process.env.OPENDAL_TEST
return process.env.OPENDAL_TEST
}

export function checkRandomRootEnabled() {
return process.env.OPENDAL_DISABLE_RANDOM_ROOT !== 'true'
}

export function generateRandomRoot(baseRoot) {
return `${baseRoot}/opendal_${crypto.randomUUID()}`
}

export function loadConfigFromEnv(scheme) {
if (!scheme) return {}
if (!scheme) return {}

const prefix = `opendal_${scheme}_`
const prefix = `opendal_${scheme}_`

return Object.fromEntries(
Object.entries(process.env)
.map(([key, value]) => [key.toLowerCase(), value])
.filter(([key]) => key.startsWith(prefix))
.map(([key, value]) => [key.replace(prefix, ''), value]),
)
return Object.fromEntries(
Object.entries(process.env)
.map(([key, value]) => [key.toLowerCase(), value])
.filter(([key]) => key.startsWith(prefix))
.map(([key, value]) => [key.replace(prefix, ''), value]),
)
}
10 changes: 2 additions & 8 deletions fixtures/sftp/docker-compose-sftp-with-default-root.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ services:
hard: 65536
command: foo::::upload
healthcheck:
test:
[
"CMD-SHELL",
"bash",
"-c",
"/health-check.sh"
]
test: ["CMD-SHELL", "bash", "-c", "/health-check.sh"]
interval: 10s
timeout: 10s
retries: 5
retries: 5
10 changes: 2 additions & 8 deletions fixtures/sftp/docker-compose-sftp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ services:
hard: 65536
command: foo::::upload
healthcheck:
test:
[
"CMD-SHELL",
"bash",
"-c",
"/health-check.sh"
]
test: ["CMD-SHELL", "bash", "-c", "/health-check.sh"]
interval: 10s
timeout: 10s
retries: 5
retries: 5

0 comments on commit 6e44078

Please sign in to comment.