feat: v0.4.0 simplify
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetHTTPSuccess(t *testing.T) {
|
||||
t.Parallel()
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("OK"))
|
||||
}))
|
||||
@@ -22,30 +23,28 @@ func TestGetHTTPSuccess(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
status, err := fn(t.Context())
|
||||
err = fn(t.Context())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if status != watchdog.StatusOK {
|
||||
t.Fatalf("incorrect status %s, expected %s", status, watchdog.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetHTTPError(t *testing.T) {
|
||||
t.Parallel()
|
||||
addr := "https://127.0.0.1:42014"
|
||||
fn, err := watchdog.GetHTTP(addr, time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
status, err := fn(t.Context())
|
||||
if status != watchdog.StatusDown || err == nil {
|
||||
err = fn(t.Context())
|
||||
if err == nil {
|
||||
t.Errorf("incorrect status for unavalable host")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeadHTTPSuccess(t *testing.T) {
|
||||
t.Parallel()
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
@@ -57,30 +56,28 @@ func TestHeadHTTPSuccess(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
status, err := fn(t.Context())
|
||||
err = fn(t.Context())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if status != watchdog.StatusOK {
|
||||
t.Fatalf("incorrect status %s, expected %s", status, watchdog.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeadHTTPError(t *testing.T) {
|
||||
t.Parallel()
|
||||
addr := "https://127.0.0.1:42014"
|
||||
fn, err := watchdog.HeadHTTP(addr, time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
status, err := fn(t.Context())
|
||||
if status != watchdog.StatusDown || err == nil {
|
||||
err = fn(t.Context())
|
||||
if err == nil {
|
||||
t.Errorf("incorrect status for unavalable host")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDialTCPSuccess(t *testing.T) {
|
||||
t.Parallel()
|
||||
addr := "127.0.0.1:42013"
|
||||
lis, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
@@ -101,18 +98,14 @@ func TestDialTCPSuccess(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
status, err := fn(t.Context())
|
||||
err = fn(t.Context())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if status != watchdog.StatusOK {
|
||||
t.Error("incorrect status for available addr")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestDialTCPError(t *testing.T) {
|
||||
t.Parallel()
|
||||
addr := "127.0.0.1:65535"
|
||||
// check for non-existent addr
|
||||
fn, err := watchdog.DialTCP(addr, time.Second)
|
||||
@@ -120,8 +113,8 @@ func TestDialTCPError(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
status, err := fn(t.Context())
|
||||
if (status != watchdog.StatusDown) || (err == nil) {
|
||||
t.Errorf("incorrect status %s, expected %s", status, watchdog.StatusDown)
|
||||
err = fn(t.Context())
|
||||
if err == nil {
|
||||
t.Errorf("incorrect status")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user