|
| 1 | +import { spawnSync } from 'node:child_process' |
| 2 | +import { |
| 3 | + mkdirSync, |
| 4 | + mkdtempSync, |
| 5 | + readFileSync, |
| 6 | + rmSync, |
| 7 | + writeFileSync, |
| 8 | +} from 'node:fs' |
| 9 | +import { tmpdir } from 'node:os' |
| 10 | +import { join } from 'node:path' |
| 11 | +import { describe, expect, it } from 'vitest' |
| 12 | +import { REPO_ROOT } from './lib/repo-root.mjs' |
| 13 | + |
| 14 | +describe('Go binding script test flags', () => { |
| 15 | + for (const platform of ['Darwin', 'Linux']) { |
| 16 | + for (const producer of [false, true]) { |
| 17 | + it(`${platform}, artifact producer=${producer}`, () => { |
| 18 | + const root = mkdtempSync(join(tmpdir(), 'go-binding-script-')) |
| 19 | + try { |
| 20 | + const bin = join(root, 'bin') |
| 21 | + const module = join(root, 'module with spaces') |
| 22 | + const log = join(root, 'commands.log') |
| 23 | + mkdirSync(bin) |
| 24 | + mkdirSync(module) |
| 25 | + writeFileSync(join(module, 'guest.wasm'), 'test guest') |
| 26 | + writeFileSync(join(bin, 'gofmt'), '#!/bin/sh\nexit 0\n', { |
| 27 | + mode: 0o755, |
| 28 | + }) |
| 29 | + writeFileSync( |
| 30 | + join(bin, 'uname'), |
| 31 | + `#!/bin/sh\nprintf '%s\\n' '${platform}'\n`, |
| 32 | + { mode: 0o755 }, |
| 33 | + ) |
| 34 | + writeFileSync( |
| 35 | + join(bin, 'go'), |
| 36 | + `#!/bin/sh |
| 37 | +printf '%s|%s|%s\\n' "\${GOOS:-}" "\${GOARCH:-}" "$*" >> "$GO_BINDING_LOG" |
| 38 | +`, |
| 39 | + { mode: 0o755 }, |
| 40 | + ) |
| 41 | + // /bin/bash is the CI shell, including Bash 3.2 on macOS. Do not |
| 42 | + // accidentally test only a newer Homebrew shell found on PATH. |
| 43 | + const result = spawnSync( |
| 44 | + '/bin/bash', |
| 45 | + [ |
| 46 | + join(REPO_ROOT, 'scripts/go-binding-test.sh'), |
| 47 | + module, |
| 48 | + 'guest.wasm', |
| 49 | + ], |
| 50 | + { |
| 51 | + env: { |
| 52 | + ...process.env, |
| 53 | + PATH: `${bin}:${process.env.PATH}`, |
| 54 | + GO_BINDING_LOG: log, |
| 55 | + GOOS: '', |
| 56 | + GOARCH: '', |
| 57 | + STACK_CONFORMANCE_OUTPUT: producer |
| 58 | + ? join(root, 'artifact.json') |
| 59 | + : '', |
| 60 | + }, |
| 61 | + encoding: 'utf8', |
| 62 | + }, |
| 63 | + ) |
| 64 | + expect(result.status, result.stderr).toBe(0) |
| 65 | + const flags = producer ? '-count=1 ' : '' |
| 66 | + expect(readFileSync(log, 'utf8').trim().split('\n')).toEqual([ |
| 67 | + '||vet ./...', |
| 68 | + '||test -v ./auth -run ^TestDeviceRefresh', |
| 69 | + `||test ${flags}./...`, |
| 70 | + platform === 'Linux' |
| 71 | + ? `linux|386|test ${flags}./...` |
| 72 | + : 'linux|386|vet ./...', |
| 73 | + ]) |
| 74 | + } finally { |
| 75 | + rmSync(root, { recursive: true, force: true }) |
| 76 | + } |
| 77 | + }) |
| 78 | + } |
| 79 | + } |
| 80 | +}) |
0 commit comments