| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package run
- import (
- "testing"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- "github.com/stretchr/testify/suite"
- "github.com/docker/api/containers"
- )
- type RunOptsSuite struct {
- suite.Suite
- }
- func (s *RunOptsSuite) TestPortParse() {
- testCases := []struct {
- in string
- expected []containers.Port
- }{
- {
- in: "80",
- expected: []containers.Port{
- {
- HostPort: 80,
- ContainerPort: 80,
- Protocol: "tcp",
- },
- },
- },
- {
- in: "80:80",
- expected: []containers.Port{
- {
- HostPort: 80,
- ContainerPort: 80,
- Protocol: "tcp",
- },
- },
- },
- {
- in: "80:80/udp",
- expected: []containers.Port{
- {
- ContainerPort: 80,
- HostPort: 80,
- Protocol: "udp",
- },
- },
- },
- {
- in: "8080:80",
- expected: []containers.Port{
- {
- HostPort: 8080,
- ContainerPort: 80,
- Protocol: "tcp",
- },
- },
- },
- {
- in: "192.168.0.2:8080:80",
- expected: []containers.Port{
- {
- HostPort: 8080,
- ContainerPort: 80,
- Protocol: "tcp",
- HostIP: "192.168.0.2",
- },
- },
- },
- {
- in: "80-81:80-81",
- expected: []containers.Port{
- {
- HostPort: 80,
- ContainerPort: 80,
- Protocol: "tcp",
- },
- {
- HostPort: 81,
- ContainerPort: 81,
- Protocol: "tcp",
- },
- },
- },
- }
- for _, testCase := range testCases {
- opts := Opts{
- Publish: []string{testCase.in},
- }
- result, err := opts.toPorts()
- require.Nil(s.T(), err)
- assert.ElementsMatch(s.T(), testCase.expected, result)
- }
- }
- func TestExampleTestSuite(t *testing.T) {
- suite.Run(t, new(RunOptsSuite))
- }
|