mirror of
https://github.com/docker/compose.git
synced 2025-07-24 06:04:57 +02:00
Add ports convet tests
This commit is contained in:
parent
5effbdc31f
commit
6fd290e2b1
2
Makefile
2
Makefile
@ -62,7 +62,7 @@ cache-clear: ## Clear the builder cache
|
|||||||
@docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h
|
@docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h
|
||||||
|
|
||||||
lint: ## run linter(s)
|
lint: ## run linter(s)
|
||||||
docker run -t -v $(PWD):/app -w /app golangci/golangci-lint:v1.27-alpine golangci-lint run ./...
|
docker run --rm -t -v $(PWD):/app -w /app golangci/golangci-lint:v1.27-alpine golangci-lint run ./...
|
||||||
|
|
||||||
help: ## Show help
|
help: ## Show help
|
||||||
@echo Please specify a build target. The choices are:
|
@echo Please specify a build target. The choices are:
|
||||||
|
89
azure/convert/ports_test.go
Normal file
89
azure/convert/ports_test.go
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
package convert
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Azure/azure-sdk-for-go/profiles/latest/containerinstance/mgmt/containerinstance"
|
||||||
|
"github.com/Azure/go-autorest/autorest/to"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/docker/api/containers"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPortConvert(t *testing.T) {
|
||||||
|
expectedPorts := []containers.Port{
|
||||||
|
{
|
||||||
|
HostPort: 80,
|
||||||
|
ContainerPort: 80,
|
||||||
|
HostIP: "10.0.0.1",
|
||||||
|
Protocol: "tcp",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
ip *containerinstance.IPAddress
|
||||||
|
ports []containerinstance.ContainerPort
|
||||||
|
expected []containers.Port
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "convert port",
|
||||||
|
ip: &containerinstance.IPAddress{
|
||||||
|
IP: to.StringPtr("10.0.0.1"),
|
||||||
|
},
|
||||||
|
ports: []containerinstance.ContainerPort{
|
||||||
|
{
|
||||||
|
Protocol: "tcp",
|
||||||
|
Port: to.Int32Ptr(80),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: expectedPorts,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with nil ip",
|
||||||
|
ip: nil,
|
||||||
|
ports: []containerinstance.ContainerPort{
|
||||||
|
{
|
||||||
|
Protocol: "tcp",
|
||||||
|
Port: to.Int32Ptr(80),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []containers.Port{
|
||||||
|
{
|
||||||
|
HostPort: 80,
|
||||||
|
ContainerPort: 80,
|
||||||
|
HostIP: "",
|
||||||
|
Protocol: "tcp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "skip nil ports",
|
||||||
|
ip: nil,
|
||||||
|
ports: []containerinstance.ContainerPort{
|
||||||
|
{
|
||||||
|
Protocol: "tcp",
|
||||||
|
Port: to.Int32Ptr(80),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Protocol: "tcp",
|
||||||
|
Port: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []containers.Port{
|
||||||
|
{
|
||||||
|
HostPort: 80,
|
||||||
|
ContainerPort: 80,
|
||||||
|
HostIP: "",
|
||||||
|
Protocol: "tcp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
ports := ToPorts(testCase.ip, testCase.ports)
|
||||||
|
assert.Equal(t, testCase.expected, ports)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -6,11 +6,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/stringid"
|
|
||||||
|
|
||||||
"github.com/docker/api/cli/formatter"
|
"github.com/docker/api/cli/formatter"
|
||||||
"github.com/docker/api/client"
|
"github.com/docker/api/client"
|
||||||
)
|
)
|
||||||
|
@ -17,9 +17,11 @@ type portGroup struct {
|
|||||||
// PortsString returns a human readable published ports
|
// PortsString returns a human readable published ports
|
||||||
func PortsString(ports []containers.Port) string {
|
func PortsString(ports []containers.Port) string {
|
||||||
groupMap := make(map[string]*portGroup)
|
groupMap := make(map[string]*portGroup)
|
||||||
var result []string
|
var (
|
||||||
var hostMappings []string
|
result []string
|
||||||
var groupMapKeys []string
|
hostMappings []string
|
||||||
|
groupMapKeys []string
|
||||||
|
)
|
||||||
|
|
||||||
sort.Slice(ports, func(i int, j int) bool {
|
sort.Slice(ports, func(i int, j int) bool {
|
||||||
return comparePorts(ports[i], ports[j])
|
return comparePorts(ports[i], ports[j])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user