Skip to content

Commit

Permalink
Fix server related tests (different error messages) on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
aldas committed Feb 1, 2022
1 parent c0c00e6 commit ed2888c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http/httptest"
"net/url"
"os"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -927,7 +928,11 @@ func TestEcho_Start(t *testing.T) {
case <-time.After(250 * time.Millisecond):
t.Fatal("start did not error out")
case err := <-errChan:
assert.Contains(t, err.Error(), "bind: address already in use")
expectContains := "bind: address already in use"
if runtime.GOOS == "windows" {
expectContains = "bind: Only one usage of each socket address"
}
assert.Contains(t, err.Error(), expectContains)
}
}

Expand Down
13 changes: 11 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"net"
"net/http"
"os"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -119,7 +120,11 @@ func TestStartConfig_Start(t *testing.T) {
t.Errorf("missing error")
return
}
assert.True(t, strings.Contains(err.Error(), "connect: connection refused"))
expectContains := "connect: connection refused"
if runtime.GOOS == "windows" {
expectContains = "No connection could be made"
}
assert.True(t, strings.Contains(err.Error(), expectContains))
}

func TestStartConfig_GracefulShutdown(t *testing.T) {
Expand Down Expand Up @@ -207,7 +212,11 @@ func TestStartConfig_GracefulShutdown(t *testing.T) {
code, body, err = doGet(fmt.Sprintf("http://%v/ok", addr))
assert.Error(t, err)
if err != nil {
assert.True(t, strings.Contains(err.Error(), "connect: connection refused"))
expectContains := "connect: connection refused"
if runtime.GOOS == "windows" {
expectContains = "No connection could be made"
}
assert.True(t, strings.Contains(err.Error(), expectContains))
}
assert.Equal(t, 0, code)
assert.Equal(t, "", body)
Expand Down

0 comments on commit ed2888c

Please sign in to comment.