Fnlb was moved to its own repo: fnproject/lb (#702)

* Fnlb was moved to its own repo: fnproject/lb

* Clean up fnlb leftovers

* Newer deps
This commit is contained in:
Denis Makogon
2018-01-23 00:17:29 +02:00
committed by Reed Allman
parent 4ffa3d5005
commit d3be603e54
8310 changed files with 457462 additions and 1749312 deletions

View File

@@ -3,7 +3,7 @@ package testing
import (
"bufio"
"context"
"context" // TODO: is issue with go < 1.7?
"encoding/json"
"fmt"
"io"
@@ -12,28 +12,24 @@ import (
"strings"
"testing"
"time"
dockertypes "github.com/docker/docker/api/types"
dockercontainer "github.com/docker/docker/api/types/container"
dockernetwork "github.com/docker/docker/api/types/network"
dockerclient "github.com/docker/docker/client"
)
func NewDockerContainer(t testing.TB, image string, env []string, cmd []string) (*DockerContainer, error) {
func NewDockerContainer(t testing.TB, image string, env []string) (*DockerContainer, error) {
c, err := dockerclient.NewEnvClient()
if err != nil {
return nil, err
}
if cmd == nil {
cmd = make([]string, 0)
}
contr := &DockerContainer{
t: t,
client: c,
ImageName: image,
ENV: env,
Cmd: cmd,
}
if err := contr.PullImage(); err != nil {
@@ -53,7 +49,6 @@ type DockerContainer struct {
client *dockerclient.Client
ImageName string
ENV []string
Cmd []string
ContainerId string
ContainerName string
ContainerJSON dockertypes.ContainerJSON
@@ -92,7 +87,6 @@ func (d *DockerContainer) Start() error {
Image: d.ImageName,
Labels: map[string]string{"migrate_test": "true"},
Env: d.ENV,
Cmd: d.Cmd,
},
&dockercontainer.HostConfig{
PublishAllPorts: true,
@@ -166,7 +160,7 @@ func (d *DockerContainer) Logs() (io.ReadCloser, error) {
})
}
func (d *DockerContainer) portMapping(selectFirst bool, cPort int) (containerPort uint, hostIP string, hostPort uint, err error) {
func (d *DockerContainer) firstPortMapping() (containerPort uint, hostIP string, hostPort uint, err error) {
if !d.containerInspected {
if err := d.Inspect(); err != nil {
d.t.Fatal(err)
@@ -174,10 +168,6 @@ func (d *DockerContainer) portMapping(selectFirst bool, cPort int) (containerPor
}
for port, bindings := range d.ContainerJSON.NetworkSettings.Ports {
if !selectFirst && port.Int() != cPort {
// Skip ahead until we find the port we want
continue
}
for _, binding := range bindings {
hostPortUint, err := strconv.ParseUint(binding.HostPort, 10, 64)
@@ -188,16 +178,11 @@ func (d *DockerContainer) portMapping(selectFirst bool, cPort int) (containerPor
return uint(port.Int()), binding.HostIP, uint(hostPortUint), nil
}
}
if selectFirst {
return 0, "", 0, fmt.Errorf("no port binding")
} else {
return 0, "", 0, fmt.Errorf("specified port not bound")
}
return 0, "", 0, fmt.Errorf("no port binding")
}
func (d *DockerContainer) Host() string {
_, hostIP, _, err := d.portMapping(true, -1)
_, hostIP, _, err := d.firstPortMapping()
if err != nil {
d.t.Fatal(err)
}
@@ -210,26 +195,13 @@ func (d *DockerContainer) Host() string {
}
func (d *DockerContainer) Port() uint {
_, _, port, err := d.portMapping(true, -1)
_, _, port, err := d.firstPortMapping()
if err != nil {
d.t.Fatal(err)
}
return port
}
func (d *DockerContainer) PortFor(cPort int) uint {
_, _, port, err := d.portMapping(false, cPort)
if err != nil {
d.t.Fatal(err)
}
return port
}
func (d *DockerContainer) NetworkSettings() dockertypes.NetworkSettings {
netSettings := d.ContainerJSON.NetworkSettings
return *netSettings
}
type dockerImagePullOutput struct {
Status string `json:"status"`
ProgressDetails struct {

View File

@@ -6,8 +6,6 @@ import (
"strconv"
"testing"
"time"
dockertypes "github.com/docker/docker/api/types"
)
type IsReadyFunc func(Instance) bool
@@ -17,7 +15,6 @@ type TestFunc func(*testing.T, Instance)
type Version struct {
Image string
ENV []string
Cmd []string
}
func ParallelTest(t *testing.T, versions []Version, readyFn IsReadyFunc, testFn TestFunc) {
@@ -39,7 +36,7 @@ func ParallelTest(t *testing.T, versions []Version, readyFn IsReadyFunc, testFn
t.Parallel()
// create new container
container, err := NewDockerContainer(t, version.Image, version.ENV, version.Cmd)
container, err := NewDockerContainer(t, version.Image, version.ENV)
if err != nil {
t.Fatalf("%v\n%s", err, containerLogs(t, container))
}
@@ -49,8 +46,8 @@ func ParallelTest(t *testing.T, versions []Version, readyFn IsReadyFunc, testFn
// wait until database is ready
tick := time.Tick(1000 * time.Millisecond)
timeout := time.After(time.Duration(delay + 60) * time.Second)
outer:
timeout := time.After(time.Duration(delay+60) * time.Second)
outer:
for {
select {
case <-tick:
@@ -90,7 +87,5 @@ func containerLogs(t *testing.T, c *DockerContainer) []byte {
type Instance interface {
Host() string
Port() uint
PortFor(int) uint
NetworkSettings() dockertypes.NetworkSettings
KeepForDebugging()
}