test, integration: Add cluster primitives to integration framework

This further extends the integration framework to add some simple
primitives for building clusters. More complex primitives and patterns
can be added in the future, but this should serve the general cases.
This commit is contained in:
James Shubin
2018-03-09 19:28:55 -05:00
parent f3b99b3940
commit 62d1fc7ed3
6 changed files with 527 additions and 36 deletions

View File

@@ -19,10 +19,15 @@ package integration
import (
"fmt"
"net"
"net/url"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
errwrap "github.com/pkg/errors"
)
const (
@@ -73,3 +78,20 @@ func Code(code string) string {
return strings.Join(output, "\n")
}
// ParsePort parses a URL and returns the port that was found.
func ParsePort(input string) (int, error) {
u, err := url.Parse(input)
if err != nil {
return 0, errwrap.Wrapf(err, "could not parse URL")
}
_, sport, err := net.SplitHostPort(u.Host)
if err != nil {
return 0, errwrap.Wrapf(err, "could not get port")
}
port, err := strconv.Atoi(sport)
if err != nil {
return 0, errwrap.Wrapf(err, "could not parse port")
}
return port, nil
}