Skip to content

Commit

Permalink
Merge pull request #349 from mrproliu/fix-gateway-ip-wrong
Browse files Browse the repository at this point in the history
Fix default network is not initialize when get gateway ip
  • Loading branch information
gianarb authored Aug 24, 2021
2 parents 5963181 + 46cf72a commit 31fb76b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,13 @@ func (p *DockerProvider) GetNetwork(ctx context.Context, req NetworkRequest) (ty

func (p *DockerProvider) GetGatewayIP(ctx context.Context) (string, error) {
// Use a default network as defined in the DockerProvider
if p.defaultNetwork == "" {
var err error
p.defaultNetwork, err = getDefaultNetwork(ctx, p.client)
if err != nil {
return "", err
}
}
nw, err := p.GetNetwork(ctx, NetworkRequest{Name: p.defaultNetwork})
if err != nil {
return "", err
Expand Down
16 changes: 16 additions & 0 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,22 @@ func TestContainerWithReaperNetwork(t *testing.T) {
assert.NotNil(t, cnt.NetworkSettings.Networks[networks[1]])
}

func TestGetGatewayIP(t *testing.T) {
// When using docker-compose with DinD mode, and using host port or http wait strategy
// It's need to invoke GetGatewayIP for get the host
provider, err := NewDockerProvider()
if err != nil {
t.Fatal(err)
}
ip, err := provider.GetGatewayIP(context.Background())
if err != nil {
t.Fatal(err)
}
if ip == "" {
t.Fatal("could not get gateway ip")
}
}

func randomString() string {
rand.Seed(time.Now().UnixNano())
chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
Expand Down

0 comments on commit 31fb76b

Please sign in to comment.