mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 09:18:31 +02:00
fix(tests): updated docker types in tests
This commit is contained in:
@@ -36,7 +36,7 @@ func TestContainerExplicit(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
c := FromDocker(&container.SummaryTrimmed{Names: []string{"test"}, State: "test", Labels: tt.labels}, "")
|
c := FromDocker(&container.Summary{Names: []string{"test"}, State: "test", Labels: tt.labels}, "")
|
||||||
ExpectEqual(t, c.IsExplicit, tt.isExplicit)
|
ExpectEqual(t, c.IsExplicit, tt.isExplicit)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -45,25 +45,27 @@ func TestContainerExplicit(t *testing.T) {
|
|||||||
func TestContainerHostNetworkMode(t *testing.T) {
|
func TestContainerHostNetworkMode(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
container *container.SummaryTrimmed
|
container *container.Summary
|
||||||
isHostNetworkMode bool
|
isHostNetworkMode bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "host network mode",
|
name: "host network mode",
|
||||||
container: &container.SummaryTrimmed{
|
container: &container.Summary{
|
||||||
Names: []string{"test"},
|
Names: []string{"test"},
|
||||||
State: "test",
|
State: "test",
|
||||||
HostConfig: struct {
|
HostConfig: struct {
|
||||||
NetworkMode string `json:",omitempty"`
|
NetworkMode string "json:\",omitempty\""
|
||||||
|
Annotations map[string]string "json:\",omitempty\""
|
||||||
}{
|
}{
|
||||||
NetworkMode: "host",
|
NetworkMode: "host",
|
||||||
|
Annotations: map[string]string{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
isHostNetworkMode: true,
|
isHostNetworkMode: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "not host network mode",
|
name: "not host network mode",
|
||||||
container: &container.SummaryTrimmed{
|
container: &container.Summary{
|
||||||
Names: []string{"test"},
|
Names: []string{"test"},
|
||||||
State: "test",
|
State: "test",
|
||||||
},
|
},
|
||||||
@@ -105,7 +107,7 @@ func TestImageNameParsing(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.full, func(t *testing.T) {
|
t.Run(tt.full, func(t *testing.T) {
|
||||||
helper := containerHelper{&container.SummaryTrimmed{Image: tt.full}}
|
helper := containerHelper{&container.Summary{Image: tt.full}}
|
||||||
im := helper.parseImage()
|
im := helper.parseImage()
|
||||||
ExpectEqual(t, im.Author, tt.author)
|
ExpectEqual(t, im.Author, tt.author)
|
||||||
ExpectEqual(t, im.Name, tt.image)
|
ExpectEqual(t, im.Name, tt.image)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func TestParseDockerLabels(t *testing.T) {
|
|||||||
ExpectNoError(t, yaml.Unmarshal(testDockerLabelsYAML, &labels))
|
ExpectNoError(t, yaml.Unmarshal(testDockerLabelsYAML, &labels))
|
||||||
|
|
||||||
routes, err := provider.routesFromContainerLabels(
|
routes, err := provider.routesFromContainerLabels(
|
||||||
docker.FromDocker(&container.SummaryTrimmed{
|
docker.FromDocker(&container.Summary{
|
||||||
Names: []string{"container"},
|
Names: []string{"container"},
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
State: "running",
|
State: "running",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
|
"github.com/docker/docker/api/types/network"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
D "github.com/yusing/go-proxy/internal/docker"
|
D "github.com/yusing/go-proxy/internal/docker"
|
||||||
"github.com/yusing/go-proxy/internal/route"
|
"github.com/yusing/go-proxy/internal/route"
|
||||||
@@ -19,7 +20,7 @@ const (
|
|||||||
testDockerIP = "172.17.0.123"
|
testDockerIP = "172.17.0.123"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeRoutes(cont *container.SummaryTrimmed, dockerHostIP ...string) route.Routes {
|
func makeRoutes(cont *container.Summary, dockerHostIP ...string) route.Routes {
|
||||||
var p DockerProvider
|
var p DockerProvider
|
||||||
var host string
|
var host string
|
||||||
if len(dockerHostIP) > 0 {
|
if len(dockerHostIP) > 0 {
|
||||||
@@ -62,7 +63,7 @@ func TestApplyLabel(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
entries := makeRoutes(&container.SummaryTrimmed{
|
entries := makeRoutes(&container.Summary{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
D.LabelAliases: "a,b",
|
D.LabelAliases: "a,b",
|
||||||
@@ -133,7 +134,7 @@ func TestApplyLabel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestApplyLabelWithAlias(t *testing.T) {
|
func TestApplyLabelWithAlias(t *testing.T) {
|
||||||
entries := makeRoutes(&container.SummaryTrimmed{
|
entries := makeRoutes(&container.Summary{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
State: "running",
|
State: "running",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
@@ -160,7 +161,7 @@ func TestApplyLabelWithAlias(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestApplyLabelWithRef(t *testing.T) {
|
func TestApplyLabelWithRef(t *testing.T) {
|
||||||
entries := makeRoutes(&container.SummaryTrimmed{
|
entries := makeRoutes(&container.Summary{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
State: "running",
|
State: "running",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
@@ -188,7 +189,7 @@ func TestApplyLabelWithRef(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestApplyLabelWithRefIndexError(t *testing.T) {
|
func TestApplyLabelWithRefIndexError(t *testing.T) {
|
||||||
c := D.FromDocker(&container.SummaryTrimmed{
|
c := D.FromDocker(&container.Summary{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
State: "running",
|
State: "running",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
@@ -202,7 +203,7 @@ func TestApplyLabelWithRefIndexError(t *testing.T) {
|
|||||||
_, err := p.routesFromContainerLabels(c)
|
_, err := p.routesFromContainerLabels(c)
|
||||||
expect.ErrorIs(t, ErrAliasRefIndexOutOfRange, err)
|
expect.ErrorIs(t, ErrAliasRefIndexOutOfRange, err)
|
||||||
|
|
||||||
c = D.FromDocker(&container.SummaryTrimmed{
|
c = D.FromDocker(&container.Summary{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
State: "running",
|
State: "running",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
@@ -215,7 +216,7 @@ func TestApplyLabelWithRefIndexError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDynamicAliases(t *testing.T) {
|
func TestDynamicAliases(t *testing.T) {
|
||||||
c := &container.SummaryTrimmed{
|
c := &container.Summary{
|
||||||
Names: []string{"app1"},
|
Names: []string{"app1"},
|
||||||
State: "running",
|
State: "running",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
@@ -238,7 +239,7 @@ func TestDynamicAliases(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDisableHealthCheck(t *testing.T) {
|
func TestDisableHealthCheck(t *testing.T) {
|
||||||
c := &container.SummaryTrimmed{
|
c := &container.Summary{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
State: "running",
|
State: "running",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
@@ -252,7 +253,7 @@ func TestDisableHealthCheck(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPublicIPLocalhost(t *testing.T) {
|
func TestPublicIPLocalhost(t *testing.T) {
|
||||||
c := &container.SummaryTrimmed{Names: dummyNames, State: "running"}
|
c := &container.Summary{Names: dummyNames, State: "running"}
|
||||||
r, ok := makeRoutes(c)["a"]
|
r, ok := makeRoutes(c)["a"]
|
||||||
expect.True(t, ok)
|
expect.True(t, ok)
|
||||||
expect.Equal(t, r.Container.PublicHostname, "127.0.0.1")
|
expect.Equal(t, r.Container.PublicHostname, "127.0.0.1")
|
||||||
@@ -260,7 +261,7 @@ func TestPublicIPLocalhost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPublicIPRemote(t *testing.T) {
|
func TestPublicIPRemote(t *testing.T) {
|
||||||
c := &container.SummaryTrimmed{Names: dummyNames, State: "running"}
|
c := &container.Summary{Names: dummyNames, State: "running"}
|
||||||
raw, ok := makeRoutes(c, testIP)["a"]
|
raw, ok := makeRoutes(c, testIP)["a"]
|
||||||
expect.True(t, ok)
|
expect.True(t, ok)
|
||||||
expect.Equal(t, raw.Container.PublicHostname, testIP)
|
expect.Equal(t, raw.Container.PublicHostname, testIP)
|
||||||
@@ -268,10 +269,10 @@ func TestPublicIPRemote(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrivateIPLocalhost(t *testing.T) {
|
func TestPrivateIPLocalhost(t *testing.T) {
|
||||||
c := &container.SummaryTrimmed{
|
c := &container.Summary{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
NetworkSettings: &container.NetworkSettingsSummaryTrimmed{
|
NetworkSettings: &container.NetworkSettingsSummary{
|
||||||
Networks: map[string]*struct{ IPAddress string }{
|
Networks: map[string]*network.EndpointSettings{
|
||||||
"network": {
|
"network": {
|
||||||
IPAddress: testDockerIP,
|
IPAddress: testDockerIP,
|
||||||
},
|
},
|
||||||
@@ -285,11 +286,11 @@ func TestPrivateIPLocalhost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrivateIPRemote(t *testing.T) {
|
func TestPrivateIPRemote(t *testing.T) {
|
||||||
c := &container.SummaryTrimmed{
|
c := &container.Summary{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
State: "running",
|
State: "running",
|
||||||
NetworkSettings: &container.NetworkSettingsSummaryTrimmed{
|
NetworkSettings: &container.NetworkSettingsSummary{
|
||||||
Networks: map[string]*struct{ IPAddress string }{
|
Networks: map[string]*network.EndpointSettings{
|
||||||
"network": {
|
"network": {
|
||||||
IPAddress: testDockerIP,
|
IPAddress: testDockerIP,
|
||||||
},
|
},
|
||||||
@@ -307,11 +308,11 @@ func TestStreamDefaultValues(t *testing.T) {
|
|||||||
privPort := uint16(1234)
|
privPort := uint16(1234)
|
||||||
pubPort := uint16(4567)
|
pubPort := uint16(4567)
|
||||||
privIP := "172.17.0.123"
|
privIP := "172.17.0.123"
|
||||||
cont := &container.SummaryTrimmed{
|
cont := &container.Summary{
|
||||||
Names: []string{"a"},
|
Names: []string{"a"},
|
||||||
State: "running",
|
State: "running",
|
||||||
NetworkSettings: &container.NetworkSettingsSummaryTrimmed{
|
NetworkSettings: &container.NetworkSettingsSummary{
|
||||||
Networks: map[string]*struct{ IPAddress string }{
|
Networks: map[string]*network.EndpointSettings{
|
||||||
"network": {
|
"network": {
|
||||||
IPAddress: privIP,
|
IPAddress: privIP,
|
||||||
},
|
},
|
||||||
@@ -344,7 +345,7 @@ func TestStreamDefaultValues(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExplicitExclude(t *testing.T) {
|
func TestExplicitExclude(t *testing.T) {
|
||||||
r, ok := makeRoutes(&container.SummaryTrimmed{
|
r, ok := makeRoutes(&container.Summary{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
D.LabelAliases: "a",
|
D.LabelAliases: "a",
|
||||||
@@ -358,9 +359,9 @@ func TestExplicitExclude(t *testing.T) {
|
|||||||
|
|
||||||
func TestImplicitExcludeDatabase(t *testing.T) {
|
func TestImplicitExcludeDatabase(t *testing.T) {
|
||||||
t.Run("mount path detection", func(t *testing.T) {
|
t.Run("mount path detection", func(t *testing.T) {
|
||||||
r, ok := makeRoutes(&container.SummaryTrimmed{
|
r, ok := makeRoutes(&container.Summary{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
Mounts: []container.MountPointTrimmed{
|
Mounts: []container.MountPoint{
|
||||||
{Destination: "/var/lib/postgresql/data"},
|
{Destination: "/var/lib/postgresql/data"},
|
||||||
},
|
},
|
||||||
})["a"]
|
})["a"]
|
||||||
@@ -368,7 +369,7 @@ func TestImplicitExcludeDatabase(t *testing.T) {
|
|||||||
expect.True(t, r.ShouldExclude())
|
expect.True(t, r.ShouldExclude())
|
||||||
})
|
})
|
||||||
t.Run("exposed port detection", func(t *testing.T) {
|
t.Run("exposed port detection", func(t *testing.T) {
|
||||||
r, ok := makeRoutes(&container.SummaryTrimmed{
|
r, ok := makeRoutes(&container.Summary{
|
||||||
Names: dummyNames,
|
Names: dummyNames,
|
||||||
Ports: []container.Port{
|
Ports: []container.Port{
|
||||||
{Type: "tcp", PrivatePort: 5432, PublicPort: 5432},
|
{Type: "tcp", PrivatePort: 5432, PublicPort: 5432},
|
||||||
|
|||||||
Reference in New Issue
Block a user