1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-22 20:06:21 +02:00

Fix server related tests (different error messages) on Windows

This commit is contained in:
toimtoimtoim 2022-02-01 20:15:37 +02:00
parent 829ddef710
commit 3d2da856e3
No known key found for this signature in database
GPG Key ID: 468EA66F309CF886
2 changed files with 17 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import (
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"os" "os"
"runtime"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -965,7 +966,11 @@ func TestEcho_Start(t *testing.T) {
case <-time.After(250 * time.Millisecond): case <-time.After(250 * time.Millisecond):
t.Fatal("start did not error out") t.Fatal("start did not error out")
case err := <-errChan: 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)
} }
} }

View File

@ -15,6 +15,7 @@ import (
"net" "net"
"net/http" "net/http"
"os" "os"
"runtime"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -119,7 +120,11 @@ func TestStartConfig_Start(t *testing.T) {
t.Errorf("missing error") t.Errorf("missing error")
return 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) { func TestStartConfig_GracefulShutdown(t *testing.T) {
@ -207,7 +212,11 @@ func TestStartConfig_GracefulShutdown(t *testing.T) {
code, body, err = doGet(fmt.Sprintf("http://%v/ok", addr)) code, body, err = doGet(fmt.Sprintf("http://%v/ok", addr))
assert.Error(t, err) assert.Error(t, err)
if err != nil { 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, 0, code)
assert.Equal(t, "", body) assert.Equal(t, "", body)