mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 01:08:47 +02:00
refactor: remove net.URL and net.CIDR types, improved unmarshal handling
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/yusing/go-proxy/internal/common"
|
||||
@@ -21,7 +21,7 @@ const (
|
||||
testDockerIP = "172.17.0.123"
|
||||
)
|
||||
|
||||
func makeRoutes(cont *types.Container, dockerHostIP ...string) route.Routes {
|
||||
func makeRoutes(cont *container.Summary, dockerHostIP ...string) route.Routes {
|
||||
var p DockerProvider
|
||||
var host string
|
||||
if len(dockerHostIP) > 0 {
|
||||
@@ -64,7 +64,7 @@ func TestApplyLabel(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
entries := makeRoutes(&types.Container{
|
||||
entries := makeRoutes(&container.Summary{
|
||||
Names: dummyNames,
|
||||
Labels: map[string]string{
|
||||
D.LabelAliases: "a,b",
|
||||
@@ -135,7 +135,7 @@ func TestApplyLabel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestApplyLabelWithAlias(t *testing.T) {
|
||||
entries := makeRoutes(&types.Container{
|
||||
entries := makeRoutes(&container.Summary{
|
||||
Names: dummyNames,
|
||||
State: "running",
|
||||
Labels: map[string]string{
|
||||
@@ -162,7 +162,7 @@ func TestApplyLabelWithAlias(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestApplyLabelWithRef(t *testing.T) {
|
||||
entries := makeRoutes(&types.Container{
|
||||
entries := makeRoutes(&container.Summary{
|
||||
Names: dummyNames,
|
||||
State: "running",
|
||||
Labels: map[string]string{
|
||||
@@ -190,7 +190,7 @@ func TestApplyLabelWithRef(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestApplyLabelWithRefIndexError(t *testing.T) {
|
||||
c := D.FromDocker(&types.Container{
|
||||
c := D.FromDocker(&container.Summary{
|
||||
Names: dummyNames,
|
||||
State: "running",
|
||||
Labels: map[string]string{
|
||||
@@ -204,7 +204,7 @@ func TestApplyLabelWithRefIndexError(t *testing.T) {
|
||||
_, err := p.routesFromContainerLabels(c)
|
||||
ExpectError(t, ErrAliasRefIndexOutOfRange, err)
|
||||
|
||||
c = D.FromDocker(&types.Container{
|
||||
c = D.FromDocker(&container.Summary{
|
||||
Names: dummyNames,
|
||||
State: "running",
|
||||
Labels: map[string]string{
|
||||
@@ -217,7 +217,7 @@ func TestApplyLabelWithRefIndexError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDynamicAliases(t *testing.T) {
|
||||
c := &types.Container{
|
||||
c := &container.Summary{
|
||||
Names: []string{"app1"},
|
||||
State: "running",
|
||||
Labels: map[string]string{
|
||||
@@ -240,7 +240,7 @@ func TestDynamicAliases(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDisableHealthCheck(t *testing.T) {
|
||||
c := &types.Container{
|
||||
c := &container.Summary{
|
||||
Names: dummyNames,
|
||||
State: "running",
|
||||
Labels: map[string]string{
|
||||
@@ -254,7 +254,7 @@ func TestDisableHealthCheck(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPublicIPLocalhost(t *testing.T) {
|
||||
c := &types.Container{Names: dummyNames, State: "running"}
|
||||
c := &container.Summary{Names: dummyNames, State: "running"}
|
||||
r, ok := makeRoutes(c)["a"]
|
||||
ExpectTrue(t, ok)
|
||||
ExpectEqual(t, r.Container.PublicHostname, "127.0.0.1")
|
||||
@@ -262,7 +262,7 @@ func TestPublicIPLocalhost(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPublicIPRemote(t *testing.T) {
|
||||
c := &types.Container{Names: dummyNames, State: "running"}
|
||||
c := &container.Summary{Names: dummyNames, State: "running"}
|
||||
raw, ok := makeRoutes(c, testIP)["a"]
|
||||
ExpectTrue(t, ok)
|
||||
ExpectEqual(t, raw.Container.PublicHostname, testIP)
|
||||
@@ -270,9 +270,9 @@ func TestPublicIPRemote(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPrivateIPLocalhost(t *testing.T) {
|
||||
c := &types.Container{
|
||||
c := &container.Summary{
|
||||
Names: dummyNames,
|
||||
NetworkSettings: &types.SummaryNetworkSettings{
|
||||
NetworkSettings: &container.NetworkSettingsSummary{
|
||||
Networks: map[string]*network.EndpointSettings{
|
||||
"network": {
|
||||
IPAddress: testDockerIP,
|
||||
@@ -287,10 +287,10 @@ func TestPrivateIPLocalhost(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPrivateIPRemote(t *testing.T) {
|
||||
c := &types.Container{
|
||||
c := &container.Summary{
|
||||
Names: dummyNames,
|
||||
State: "running",
|
||||
NetworkSettings: &types.SummaryNetworkSettings{
|
||||
NetworkSettings: &container.NetworkSettingsSummary{
|
||||
Networks: map[string]*network.EndpointSettings{
|
||||
"network": {
|
||||
IPAddress: testDockerIP,
|
||||
@@ -309,17 +309,17 @@ func TestStreamDefaultValues(t *testing.T) {
|
||||
privPort := uint16(1234)
|
||||
pubPort := uint16(4567)
|
||||
privIP := "172.17.0.123"
|
||||
cont := &types.Container{
|
||||
cont := &container.Summary{
|
||||
Names: []string{"a"},
|
||||
State: "running",
|
||||
NetworkSettings: &types.SummaryNetworkSettings{
|
||||
NetworkSettings: &container.NetworkSettingsSummary{
|
||||
Networks: map[string]*network.EndpointSettings{
|
||||
"network": {
|
||||
IPAddress: privIP,
|
||||
},
|
||||
},
|
||||
},
|
||||
Ports: []types.Port{
|
||||
Ports: []container.Port{
|
||||
{Type: "udp", PrivatePort: privPort, PublicPort: pubPort},
|
||||
},
|
||||
}
|
||||
@@ -346,7 +346,7 @@ func TestStreamDefaultValues(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExplicitExclude(t *testing.T) {
|
||||
r, ok := makeRoutes(&types.Container{
|
||||
r, ok := makeRoutes(&container.Summary{
|
||||
Names: dummyNames,
|
||||
Labels: map[string]string{
|
||||
D.LabelAliases: "a",
|
||||
@@ -360,9 +360,9 @@ func TestExplicitExclude(t *testing.T) {
|
||||
|
||||
func TestImplicitExcludeDatabase(t *testing.T) {
|
||||
t.Run("mount path detection", func(t *testing.T) {
|
||||
r, ok := makeRoutes(&types.Container{
|
||||
r, ok := makeRoutes(&container.Summary{
|
||||
Names: dummyNames,
|
||||
Mounts: []types.MountPoint{
|
||||
Mounts: []container.MountPoint{
|
||||
{Source: "/data", Destination: "/var/lib/postgresql/data"},
|
||||
},
|
||||
})["a"]
|
||||
@@ -370,9 +370,9 @@ func TestImplicitExcludeDatabase(t *testing.T) {
|
||||
ExpectTrue(t, r.ShouldExclude())
|
||||
})
|
||||
t.Run("exposed port detection", func(t *testing.T) {
|
||||
r, ok := makeRoutes(&types.Container{
|
||||
r, ok := makeRoutes(&container.Summary{
|
||||
Names: dummyNames,
|
||||
Ports: []types.Port{
|
||||
Ports: []container.Port{
|
||||
{Type: "tcp", PrivatePort: 5432, PublicPort: 5432},
|
||||
},
|
||||
})["a"]
|
||||
|
||||
@@ -128,7 +128,7 @@ func (p *Provider) loadRoutes() (routes route.Routes, err gperr.Error) {
|
||||
if err != nil && len(routes) == 0 {
|
||||
return route.Routes{}, err
|
||||
}
|
||||
errs := gperr.NewBuilder("routes error")
|
||||
errs := gperr.NewBuilder()
|
||||
errs.Add(err)
|
||||
// check for exclusion
|
||||
// set alias and provider, then validate
|
||||
|
||||
Reference in New Issue
Block a user