tailscale/safesocket/basic_test.go
James Tucker 8dec1a8724 .github/workflows: reenable Windows CI, disable broken tests
We accidentally switched to ./tool/go in
4022796484 which resulted in no longer
running Windows builds, as this is attempting to run a bash script.

I was unable to quickly fix the various tests that have regressed, so
instead I've added skips referencing #7876, which we need to back and
fix.

Updates #7262
Updates #7876

Signed-off-by: James Tucker <james@tailscale.com>
2023-04-14 14:13:53 -07:00

85 lines
1.5 KiB
Go

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package safesocket
import (
"fmt"
"path/filepath"
"runtime"
"testing"
)
func TestBasics(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("TODO(#7876): test regressed on windows while CI was broken")
}
// Make the socket in a temp dir rather than the cwd
// so that the test can be run from a mounted filesystem (#2367).
dir := t.TempDir()
var sock string
if runtime.GOOS != "windows" {
sock = filepath.Join(dir, "test")
} else {
sock = fmt.Sprintf(`\\.\pipe\tailscale-test`)
}
l, err := Listen(sock)
if err != nil {
t.Fatal(err)
}
errs := make(chan error, 2)
go func() {
s, err := l.Accept()
if err != nil {
errs <- err
return
}
l.Close()
s.Write([]byte("hello"))
b := make([]byte, 1024)
n, err := s.Read(b)
if err != nil {
errs <- err
return
}
t.Logf("server read %d bytes.", n)
if string(b[:n]) != "world" {
errs <- fmt.Errorf("got %#v, expected %#v\n", string(b[:n]), "world")
return
}
s.Close()
errs <- nil
}()
go func() {
s := DefaultConnectionStrategy(sock)
c, err := Connect(s)
if err != nil {
errs <- err
return
}
c.Write([]byte("world"))
b := make([]byte, 1024)
n, err := c.Read(b)
if err != nil {
errs <- err
return
}
if string(b[:n]) != "hello" {
errs <- fmt.Errorf("got %#v, expected %#v\n", string(b[:n]), "hello")
}
c.Close()
errs <- nil
}()
for i := 0; i < 2; i++ {
if err := <-errs; err != nil {
t.Fatal(err)
}
}
}