internal/pkg: compare interfaces for host net
All checks were successful
Test / Create distribution (push) Successful in 46s
Test / Sandbox (push) Successful in 2m59s
Test / ShareFS (push) Successful in 4m45s
Test / Hpkg (push) Successful in 5m4s
Test / Hakurei (push) Successful in 5m22s
Test / Sandbox (race detector) (push) Successful in 5m21s
Test / Hakurei (race detector) (push) Successful in 7m31s
Test / Flake checks (push) Successful in 1m40s
All checks were successful
Test / Create distribution (push) Successful in 46s
Test / Sandbox (push) Successful in 2m59s
Test / ShareFS (push) Successful in 4m45s
Test / Hpkg (push) Successful in 5m4s
Test / Hakurei (push) Successful in 5m22s
Test / Sandbox (race detector) (push) Successful in 5m21s
Test / Hakurei (race detector) (push) Successful in 7m31s
Test / Flake checks (push) Successful in 1m40s
An upcoming improvement in the container init makes the current host net check return the same result for both cases. This change Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -4,7 +4,9 @@ package pkg_test
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"slices"
|
||||
@@ -263,6 +265,27 @@ func newTesttool() (
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ift, err := net.Interfaces(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
var f *os.File
|
||||
if f, err = os.Create(t.GetWorkDir().Append(
|
||||
"ift",
|
||||
).String()); err != nil {
|
||||
return err
|
||||
} else {
|
||||
err = gob.NewEncoder(f).Encode(ift)
|
||||
closeErr := f.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if closeErr != nil {
|
||||
return closeErr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return os.WriteFile(t.GetWorkDir().Append(
|
||||
"bin",
|
||||
"testtool",
|
||||
|
||||
47
internal/pkg/testdata/main.go
vendored
47
internal/pkg/testdata/main.go
vendored
@@ -3,14 +3,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"encoding/gob"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"hakurei.app/container/check"
|
||||
"hakurei.app/container/fhs"
|
||||
@@ -60,9 +60,13 @@ func main() {
|
||||
wantExec = "/opt/bin/testtool"
|
||||
wantExecWork = "/work/bin/testtool"
|
||||
)
|
||||
var iftPath string
|
||||
if got, err := os.Executable(); err != nil {
|
||||
log.Fatalf("Executable: error = %v", err)
|
||||
} else if got != wantExec {
|
||||
} else {
|
||||
iftPath = path.Join(path.Dir(path.Dir(got)), "ift")
|
||||
|
||||
if got != wantExec {
|
||||
switch got {
|
||||
case wantExecWork:
|
||||
overlayWork = true
|
||||
@@ -72,6 +76,7 @@ func main() {
|
||||
log.Fatalf("Executable: %q, want %q", got, wantExec)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wantHostname := "cure"
|
||||
if hostNet {
|
||||
@@ -98,15 +103,37 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := net.Dial("tcp", "127.0.0.1:0"); err == nil {
|
||||
log.Fatal("Dial unexpectedly succeeded")
|
||||
} else if hostNet {
|
||||
if !errors.Is(err, syscall.ECONNREFUSED) {
|
||||
log.Fatalf("Dial: error = %v", err)
|
||||
if ift, err := net.Interfaces(); err != nil {
|
||||
log.Fatal(err)
|
||||
} else if !hostNet {
|
||||
if len(ift) != 1 || ift[0].Name != "lo" {
|
||||
log.Fatalln("got interfaces", strings.Join(slices.Collect(func(yield func(ifn string) bool) {
|
||||
for _, ifi := range ift {
|
||||
if !yield(ifi.Name) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}), ", "))
|
||||
}
|
||||
} else {
|
||||
if !errors.Is(err, syscall.ENETUNREACH) {
|
||||
log.Fatalf("Dial: error = %v", err)
|
||||
var iftParent []net.Interface
|
||||
|
||||
var r *os.File
|
||||
if r, err = os.Open(iftPath); err != nil {
|
||||
log.Fatal(err)
|
||||
} else {
|
||||
err = gob.NewDecoder(r).Decode(&iftParent)
|
||||
closeErr := r.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if closeErr != nil {
|
||||
log.Fatal(closeErr)
|
||||
}
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(ift, iftParent) {
|
||||
log.Fatalf("Interfaces: %#v, want %#v", ift, iftParent)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user