Feat: HEALTH_ADDRESS_TO_PING variable
- Defaults to `1.1.1.1` - Add more Ping integration tests with different addresses - Add unit test pinging 127.0.0.1 - Add comment explaining why we need to use ICMP instead of UDP
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -69,7 +70,7 @@ func Test_healthCheck(t *testing.T) {
|
||||
t.Run("canceled real pinger", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
pinger := newPinger()
|
||||
pinger := newPinger("1.1.1.1")
|
||||
|
||||
canceledCtx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
@@ -78,4 +79,18 @@ func Test_healthCheck(t *testing.T) {
|
||||
|
||||
assert.ErrorIs(t, context.Canceled, err)
|
||||
})
|
||||
|
||||
t.Run("ping 127.0.0.1", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
pinger := newPinger("127.0.0.1")
|
||||
|
||||
const timeout = 100 * time.Millisecond
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
||||
err := healthCheck(ctx, pinger)
|
||||
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user