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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user