Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make cross-platform EADDRINUSE check #116

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
os:
- ubuntu-latest
- macos-latest
# - windows-latest
- windows-latest

name: test
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
os:
- ubuntu-latest
- macos-latest
# - windows-latest
- windows-latest

name: lint
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions cmd/humanlog/localhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
"github.com/rs/cors"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"golang.org/x/sys/unix"

// imported for side-effect
internal_errors "github.com/humanlogio/humanlog/internal/errors"
_ "github.com/humanlogio/humanlog/internal/memstorage"
)

Expand All @@ -51,7 +51,7 @@ func isEADDRINUSE(err error) bool {
if !ok {
return false
}
return nserrno == unix.EADDRINUSE
return internal_errors.IsSocketInUse(nserrno)
}

func startLocalhostServer(
Expand Down
14 changes: 14 additions & 0 deletions e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"encoding/json"
"os"
"path/filepath"
"runtime"
"strings"
"testing"

"github.com/humanlogio/humanlog/internal/pkg/config"
Expand Down Expand Up @@ -38,6 +40,13 @@ func TestHarness(t *testing.T) {
if err != nil {
t.Fatalf("reading config: %v", err)
}

if runtime.GOOS == "windows" {
input = replaceCRLF(input, "\r\n", "\n")
want = replaceCRLF(want, "\r\n", "\n")
cfgjson = replaceCRLF(cfgjson, "\r\n", "\n")
}

var cfg config.Config
if err := json.Unmarshal(cfgjson, &cfg); err != nil {
t.Fatalf("unmarshaling config: %v", err)
Expand Down Expand Up @@ -109,6 +118,11 @@ type byteranges struct {
ranges []*byterange
}

func replaceCRLF(org []byte, oldCRLF string, newCRLF string) []byte {
replaced := strings.ReplaceAll(string(org), oldCRLF, newCRLF)
return []byte(replaced)
}

func newByteRanges() *byteranges {
return &byteranges{}
}
Expand Down
13 changes: 13 additions & 0 deletions internal/errors/errors_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !windows

package errors

import (
"syscall"

"golang.org/x/sys/unix"
)

func IsSocketInUse(errno syscall.Errno) bool {
return errno == unix.EADDRINUSE
}
13 changes: 13 additions & 0 deletions internal/errors/errors_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build windows

package errors

import (
"syscall"

"golang.org/x/sys/windows"
)

func IsSocketInUse(errno syscall.Errno) bool {
return errno == windows.WSAEADDRINUSE
}
Loading