Skip to content

Commit f165bcc

Browse files
committed
Fix test failures on windows, mostly paths
Signed-off-by: Anders F Björklund <[email protected]>
1 parent de9f354 commit f165bcc

File tree

6 files changed

+46
-19
lines changed

6 files changed

+46
-19
lines changed

pkg/cidata/template.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"io/fs"
9-
"path/filepath"
9+
"path"
1010

1111
"github.com/lima-vm/lima/pkg/iso9660util"
1212

@@ -82,7 +82,7 @@ func ValidateTemplateArgs(args TemplateArgs) error {
8282
}
8383
for i, m := range args.Mounts {
8484
f := m.MountPoint
85-
if !filepath.IsAbs(f) {
85+
if !path.IsAbs(f) {
8686
return fmt.Errorf("field mounts[%d] must be absolute, got %q", i, f)
8787
}
8888
}

pkg/hostagent/dns/dns_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package dns
22

33
import (
4+
"fmt"
45
"io"
56
"log"
67
"net"
78
"regexp"
9+
"runtime"
810
"testing"
911

1012
"github.com/foxcpp/go-mockdns"
1113
"github.com/miekg/dns"
1214
"gotest.tools/v3/assert"
15+
"gotest.tools/v3/assert/cmp"
1316
)
1417

1518
var (
@@ -43,6 +46,10 @@ func TestTXTRecords(t *testing.T) {
4346
}, log.New(io.Discard, "mockdns server: ", log.LstdFlags), false)
4447
defer srv.Close()
4548

49+
if runtime.GOOS == "windows" {
50+
// "On Windows, the resolver always uses C library functions, such as GetAddrInfo and DnsQuery."
51+
t.Skip()
52+
}
4653
srv.PatchNet(net.DefaultResolver)
4754
defer mockdns.UnpatchNet(net.DefaultResolver)
4855

@@ -56,8 +63,17 @@ func TestTXTRecords(t *testing.T) {
5663
req := new(dns.Msg)
5764
req.SetQuestion(dns.Fqdn(testDomains[i]), dns.TypeTXT)
5865
h.ServeDNS(w, req)
59-
regex_check := regexp.MustCompile(expectedResults[i]).MatchString(dnsResult.String())
60-
assert.Assert(t, regex_check)
66+
regex_match := func(value string, pattern string) cmp.Comparison {
67+
return func() cmp.Result {
68+
re := regexp.MustCompile(pattern)
69+
if re.MatchString(value) {
70+
return cmp.ResultSuccess
71+
}
72+
return cmp.ResultFailure(
73+
fmt.Sprintf("%q did not match pattern %q", value, pattern))
74+
}
75+
}
76+
assert.Assert(t, regex_match(dnsResult.String(), expectedResults[i]))
6177
}
6278
}
6379
})

pkg/limayaml/defaults.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"net"
88
"os"
9-
osuser "os/user"
109
"path/filepath"
1110
"runtime"
1211
"strconv"
@@ -569,7 +568,7 @@ func FillPortForwardDefaults(rule *PortForward, instDir string) {
569568
if rule.HostSocket != "" {
570569
tmpl, err := template.New("").Parse(rule.HostSocket)
571570
if err == nil {
572-
user, _ := osuser.Current()
571+
user, _ := osutil.LimaUser(false)
573572
home, _ := os.UserHomeDir()
574573
limaHome, _ := dirnames.LimaDir()
575574
data := map[string]string{

pkg/limayaml/validate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"net"
66
"os"
7+
"path"
78
"path/filepath"
89
"runtime"
910
"strings"
@@ -217,7 +218,7 @@ func Validate(y LimaYAML, warn bool) error {
217218
return fmt.Errorf("field `%s.hostPortRange` must specify the same number of ports as field `%s.guestPortRange`", field, field)
218219
}
219220
if rule.GuestSocket != "" {
220-
if !filepath.IsAbs(rule.GuestSocket) {
221+
if !path.IsAbs(rule.GuestSocket) {
221222
return fmt.Errorf("field `%s.guestSocket` must be an absolute path", field)
222223
}
223224
if rule.HostSocket == "" && rule.HostPortRange[1]-rule.HostPortRange[0] > 0 {

pkg/networks/commands.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package networks
22

33
import (
44
"fmt"
5+
"path/filepath"
56

67
"github.com/lima-vm/lima/pkg/osutil"
78
"github.com/lima-vm/lima/pkg/store/dirnames"
@@ -23,16 +24,16 @@ func (config *NetworksConfig) Check(name string) error {
2324
}
2425

2526
func (config *NetworksConfig) VDESock(name string) string {
26-
return fmt.Sprintf("%s/%s.ctl", config.Paths.VarRun, name)
27+
return filepath.Join(config.Paths.VarRun, fmt.Sprintf("%s.ctl", name))
2728
}
2829

2930
func (config *NetworksConfig) PIDFile(name, daemon string) string {
30-
return fmt.Sprintf("%s/%s_%s.pid", config.Paths.VarRun, name, daemon)
31+
return filepath.Join(config.Paths.VarRun, fmt.Sprintf("%s_%s.pid", name, daemon))
3132
}
3233

3334
func (config *NetworksConfig) LogFile(name, daemon, stream string) string {
3435
networksDir, _ := dirnames.LimaNetworksDir()
35-
return fmt.Sprintf("%s/%s_%s.%s.log", networksDir, name, daemon, stream)
36+
return filepath.Join(networksDir, fmt.Sprintf("%s_%s.%s.log", name, daemon, stream))
3637
}
3738

3839
func (config *NetworksConfig) User(daemon string) (osutil.User, error) {

pkg/networks/commands_test.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ func TestVDESock(t *testing.T) {
2626
assert.NilError(t, err)
2727

2828
vdeSock := config.VDESock("foo")
29-
assert.Equal(t, vdeSock, "/private/var/run/lima/foo.ctl")
29+
varRunDir := filepath.Join("/", "private", "var", "run", "lima")
30+
assert.Equal(t, vdeSock, filepath.Join(varRunDir, "foo.ctl"))
3031
}
3132

3233
func TestPIDFile(t *testing.T) {
3334
config, err := DefaultConfig()
3435
assert.NilError(t, err)
3536

3637
pidFile := config.PIDFile("name", "daemon")
37-
assert.Equal(t, pidFile, "/private/var/run/lima/name_daemon.pid")
38+
varRunDir := filepath.Join("/", "private", "var", "run", "lima")
39+
assert.Equal(t, pidFile, filepath.Join(varRunDir, "name_daemon.pid"))
3840
}
3941

4042
func TestLogFile(t *testing.T) {
@@ -54,6 +56,10 @@ func TestUser(t *testing.T) {
5456
// The "everyone" group is a specific macOS feature to include non-local accounts.
5557
config.Group = "staff"
5658
}
59+
if runtime.GOOS == "windows" {
60+
// unimplemented
61+
t.Skip()
62+
}
5763

5864
user, err := config.User(Switch)
5965
assert.NilError(t, err)
@@ -87,23 +93,27 @@ func TestStartCmd(t *testing.T) {
8793
config, err := DefaultConfig()
8894
assert.NilError(t, err)
8995

96+
varRunDir := filepath.Join("/", "private", "var", "run", "lima")
97+
9098
cmd := config.StartCmd("shared", Switch)
91-
assert.Equal(t, cmd, "/opt/vde/bin/vde_switch --pidfile=/private/var/run/lima/shared_switch.pid "+
92-
"--sock=/private/var/run/lima/shared.ctl --group=everyone --dirmode=0770 --nostdin")
99+
assert.Equal(t, cmd, "/opt/vde/bin/vde_switch --pidfile="+filepath.Join(varRunDir, "shared_switch.pid")+" "+
100+
"--sock="+filepath.Join(varRunDir, "shared.ctl")+" --group=everyone --dirmode=0770 --nostdin")
93101

94102
cmd = config.StartCmd("shared", VMNet)
95-
assert.Equal(t, cmd, "/opt/vde/bin/vde_vmnet --pidfile=/private/var/run/lima/shared_vmnet.pid --vde-group=everyone --vmnet-mode=shared "+
96-
"--vmnet-gateway=192.168.105.1 --vmnet-dhcp-end=192.168.105.254 --vmnet-mask=255.255.255.0 /private/var/run/lima/shared.ctl")
103+
assert.Equal(t, cmd, "/opt/vde/bin/vde_vmnet --pidfile="+filepath.Join(varRunDir, "shared_vmnet.pid")+" --vde-group=everyone --vmnet-mode=shared "+
104+
"--vmnet-gateway=192.168.105.1 --vmnet-dhcp-end=192.168.105.254 --vmnet-mask=255.255.255.0 "+filepath.Join(varRunDir, "shared.ctl"))
97105

98106
cmd = config.StartCmd("bridged", VMNet)
99-
assert.Equal(t, cmd, "/opt/vde/bin/vde_vmnet --pidfile=/private/var/run/lima/bridged_vmnet.pid --vde-group=everyone --vmnet-mode=bridged "+
100-
"--vmnet-interface=en0 /private/var/run/lima/bridged.ctl")
107+
assert.Equal(t, cmd, "/opt/vde/bin/vde_vmnet --pidfile="+filepath.Join(varRunDir, "bridged_vmnet.pid")+" --vde-group=everyone --vmnet-mode=bridged "+
108+
"--vmnet-interface=en0 "+filepath.Join(varRunDir, "bridged.ctl"))
101109
}
102110

103111
func TestStopCmd(t *testing.T) {
104112
config, err := DefaultConfig()
105113
assert.NilError(t, err)
106114

115+
varRunDir := filepath.Join("/", "private", "var", "run", "lima")
116+
107117
cmd := config.StopCmd("name", "daemon")
108-
assert.Equal(t, cmd, "/usr/bin/pkill -F /private/var/run/lima/name_daemon.pid")
118+
assert.Equal(t, cmd, "/usr/bin/pkill -F "+filepath.Join(varRunDir, "name_daemon.pid"))
109119
}

0 commit comments

Comments
 (0)