| 1 | import test from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs'; |
| 4 | import { tmpdir } from 'node:os'; |
| 5 | import { join, resolve } from 'node:path'; |
| 6 | import { spawnSync } from 'node:child_process'; |
| 7 | |
| 8 | test('fresh-cache Mac core build downloads VZ source before copying and builds its patched binding', () => { |
| 9 | const root = mkdtempSync(join(tmpdir(), 'cage-vz-fresh-cache-')); |
| 10 | try { |
| 11 | const bin = join(root, 'bin'), module = join(root, 'module'); |
| 12 | mkdirSync(bin); mkdirSync(module); |
| 13 | writeFileSync(join(module, 'go.mod'), 'module github.com/Code-Hex/vz/v3\n'); |
| 14 | writeFileSync(join(bin, 'go'), `#!/bin/sh |
| 15 | set -eu |
| 16 | if test "$1 $2" = 'mod download'; then touch "$CAGE_VZ_FIXTURE/downloaded"; exit; fi |
| 17 | if test "$1 $2" = 'mod edit'; then exit; fi |
| 18 | case "$*" in |
| 19 | *Version*) printf v3.7.1 ;; |
| 20 | *Dir*) if test -f "$CAGE_VZ_FIXTURE/downloaded"; then printf '%s/module' "$CAGE_VZ_FIXTURE"; fi ;; |
| 21 | *) exit 2 ;; |
| 22 | esac |
| 23 | `, { mode: 0o755 }); |
| 24 | writeFileSync(join(bin, 'make'), `#!/bin/sh |
| 25 | set -eu |
| 26 | trial=$(printf '%s' "$GOFLAGS" | sed 's/.*-modfile=//') |
| 27 | test -f "$(dirname "$trial")/vz/cage_view_object_darwin.go" |
| 28 | grep -q CageViewObject "$(dirname "$trial")/vz/cage_view_object_darwin.go" |
| 29 | test "$1" = cage |
| 30 | printf patched-binding-built |
| 31 | `, { mode: 0o755 }); |
| 32 | const result = spawnSync('/bin/bash', [resolve('scripts/guest-os/build-macos-guest-core.sh'), '0.1.7-rc.1'], { |
| 33 | encoding: 'utf8', env: { ...process.env, PATH: `${bin}:${process.env.PATH}`, CAGE_VZ_FIXTURE: root }, |
| 34 | }); |
| 35 | assert.equal(result.status, 0, result.stderr); |
| 36 | assert.match(result.stdout, /patched-binding-built/); |
| 37 | } finally { rmSync(root, { recursive: true, force: true }); } |
| 38 | }); |