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:
Quentin McGaw (desktop)
2021-09-11 22:22:55 +00:00
parent cade2732b0
commit 6627cda96c
8 changed files with 109 additions and 10 deletions

View File

@@ -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)
})
}