|
| 1 | +import { afterEach, describe, expect, it } from 'vitest'; |
| 2 | +import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; |
| 3 | +import { tmpdir } from 'node:os'; |
| 4 | +import { join } from 'node:path'; |
| 5 | +import { loadConfig } from '../index.js'; |
| 6 | + |
| 7 | +function writeConfig(contents: string): string { |
| 8 | + const dir = mkdtempSync(join(tmpdir(), 'raiflow-config-')); |
| 9 | + const path = join(dir, 'raiflow.yml'); |
| 10 | + writeFileSync(path, contents, 'utf8'); |
| 11 | + return path; |
| 12 | +} |
| 13 | + |
| 14 | +const tempPaths: string[] = []; |
| 15 | + |
| 16 | +afterEach(() => { |
| 17 | + for (const path of tempPaths.splice(0)) { |
| 18 | + rmSync(path, { recursive: true, force: true }); |
| 19 | + } |
| 20 | +}); |
| 21 | + |
| 22 | +describe('loadConfig nano transport arrays', () => { |
| 23 | + it('accepts an empty nano block', () => { |
| 24 | + const path = writeConfig('nano: {}\n'); |
| 25 | + tempPaths.push(path.replace(/\/raiflow\.yml$/, '')); |
| 26 | + |
| 27 | + const config = loadConfig(path); |
| 28 | + expect(config.nano).toEqual({ rpc: [], ws: [], work: [] }); |
| 29 | + }); |
| 30 | + |
| 31 | + it('accepts flat rpc override list', () => { |
| 32 | + const path = writeConfig('nano:\n rpc: ["https://rpc.example.com"]\n'); |
| 33 | + tempPaths.push(path.replace(/\/raiflow\.yml$/, '')); |
| 34 | + |
| 35 | + const config = loadConfig(path); |
| 36 | + expect(config.nano).toEqual({ rpc: ['https://rpc.example.com'], ws: [], work: [] }); |
| 37 | + }); |
| 38 | + |
| 39 | + it('accepts flat rpc, ws, and work override lists', () => { |
| 40 | + const path = writeConfig('nano:\n rpc: ["https://rpc.example.com"]\n ws: ["wss://ws.example.com"]\n work: ["https://work.example.com"]\n'); |
| 41 | + tempPaths.push(path.replace(/\/raiflow\.yml$/, '')); |
| 42 | + |
| 43 | + const config = loadConfig(path); |
| 44 | + expect(config.nano).toEqual({ rpc: ['https://rpc.example.com'], ws: ['wss://ws.example.com'], work: ['https://work.example.com'] }); |
| 45 | + }); |
| 46 | +}); |
0 commit comments