diff --git a/net/interfaces/interfaces_linux_test.go b/net/interfaces/interfaces_linux_test.go index dde9987b0..8ae48adad 100644 --- a/net/interfaces/interfaces_linux_test.go +++ b/net/interfaces/interfaces_linux_test.go @@ -73,6 +73,32 @@ func TestExtremelyLongProcNetRoute(t *testing.T) { } } +// test the specific /proc/net/route path as found on AWS App Runner instances +func TestAwsAppRunnerDefaultRouteInterface(t *testing.T) { + dir := t.TempDir() + savedProcNetRoutePath := procNetRoutePath + defer func() { procNetRoutePath = savedProcNetRoutePath }() + procNetRoutePath = filepath.Join(dir, "CloudRun") + buf := []byte("Iface\tDestination\tGateway\tFlags\tRefCnt\tUse\tMetric\tMask\tMTU\tWindow\tIRTT\n" + + "eth0\t00000000\tF9AFFEA9\t0003\t0\t0\t0\t00000000\t0\t0\t0\n" + + "*\tFEA9FEA9\t00000000\t0005\t0\t0\t0\tFFFFFFFF\t0\t0\t0\n" + + "ecs-eth0\t02AAFEA9\t01ACFEA9\t0007\t0\t0\t0\tFFFFFFFF\t0\t0\t0\n" + + "ecs-eth0\t00ACFEA9\t00000000\t0001\t0\t0\t0\t00FFFFFF\t0\t0\t0\n" + + "eth0\t00AFFEA9\t00000000\t0001\t0\t0\t0\t00FFFFFF\t0\t0\t0\n") + err := ioutil.WriteFile(procNetRoutePath, buf, 0644) + if err != nil { + t.Fatal(err) + } + got, err := DefaultRouteInterface() + if err != nil { + t.Fatal(err) + } + + if got != "eth0" { + t.Fatalf("got %s, want eth0", got) + } +} + func BenchmarkDefaultRouteInterface(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ {