53 lines
2.0 KiB
Go
53 lines
2.0 KiB
Go
package macosdriver
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/Nwflower/reims-go/internal/macos/reims"
|
|
)
|
|
|
|
func TestShouldEnableNetworkAfterInstallPreservesBridgeAndCustom(t *testing.T) {
|
|
t.Run("offline off enables NAT", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
if !shouldEnableNetworkAfterInstall(reims.VMDetail{Directory: dir, Network: false}) {
|
|
t.Fatal("expected offline VM with network=off to enable NAT after install")
|
|
}
|
|
})
|
|
|
|
t.Run("already NAT stays untouched", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
if shouldEnableNetworkAfterInstall(reims.VMDetail{Directory: dir, Network: true}) {
|
|
t.Fatal("expected already-enabled NAT VM not to set network again")
|
|
}
|
|
})
|
|
|
|
t.Run("bridged via network record keeps network=false", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
if err := reims.SaveNetworkRecord(dir, reims.NetworkRecord{Version: 1, Mode: "bridge", UplinkGUID: "{1111}"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if shouldEnableNetworkAfterInstall(reims.VMDetail{Directory: dir, Network: false}) {
|
|
t.Fatal("finishInstall must NOT turn on built-in NAT for bridged VM")
|
|
}
|
|
})
|
|
|
|
t.Run("bridged via legacy extra_args keeps network=false", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
extra := "-netdev stream,id=reimsbridge0,server=off,addr.type=inet,addr.host=127.0.0.1,addr.port=12363,reconnect-ms=1000 -device virtio-net-pci,netdev=reimsbridge0,id=net0,mac=02:00:00:00:00:01,addr=0x3"
|
|
if shouldEnableNetworkAfterInstall(reims.VMDetail{Directory: dir, Network: false, ExtraArgs: extra}) {
|
|
t.Fatal("finishInstall must NOT turn on built-in NAT for legacy bridged VM")
|
|
}
|
|
})
|
|
|
|
t.Run("custom user netdev keeps network=false", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
_ = os.WriteFile(filepath.Join(dir, "vm.toml"), []byte("[network]\nenabled = false\n"), 0o600)
|
|
extra := "-netdev user,id=net0 -device virtio-net-pci,netdev=net0"
|
|
if shouldEnableNetworkAfterInstall(reims.VMDetail{Directory: dir, Network: false, ExtraArgs: extra}) {
|
|
t.Fatal("finishInstall must NOT overwrite custom network topology")
|
|
}
|
|
})
|
|
}
|