Skip to content

Commit

Permalink
test(e2e) be more precise when getting the IPv6 address
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Nikolaev <nikolay.nikolaev@konghq.com>
  • Loading branch information
Nikolay Nikolaev committed Apr 8, 2021
1 parent ea8eb67 commit afd568f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions test/framework/universal_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"bytes"
"fmt"
"io"
"net"
"os"
"os/exec"
"strconv"
"strings"

"github.com/asaskevich/govalidator"

"github.com/gruntwork-io/terratest/modules/retry"
"github.com/pkg/errors"

Expand Down Expand Up @@ -381,14 +382,16 @@ func (s *UniversalApp) getIP(isipv6 bool) (string, error) {
return "invalid", errors.Wrapf(err, "getent failed with %s", string(bytes))
}
lines := strings.Split(string(bytes), "\n")
// search ipv4
// search for the requested IP
for _, line := range lines {
split := strings.Split(line, " ")
testInput := net.ParseIP(split[0])
ip := split[0]
if isipv6 {
return split[0], nil
} else if testInput.To4() != nil {
return split[0], nil
if govalidator.IsIPv6(ip) {
return ip, nil
}
} else if govalidator.IsIPv4(ip) {
return ip, nil
}
}
return "", errors.Errorf("No IPv4 address found")
Expand Down

0 comments on commit afd568f

Please sign in to comment.