@@ -90,6 +90,81 @@ func TestGetNetworkSettingsPorts(t *testing.T) {
90
90
}
91
91
}
92
92
93
+ func TestGetConfigExposedPorts (t * testing.T ) {
94
+ tests := []struct {
95
+ tainr * types.Container
96
+ endp EndpointConfig
97
+ out gin.H
98
+ portfw bool
99
+ }{
100
+ {
101
+ tainr : & types.Container {
102
+ HostIP : "" ,
103
+ MappedPorts : map [int ]int {303 : 101 },
104
+ },
105
+ out : gin.H {},
106
+ portfw : true ,
107
+ },
108
+ {
109
+ tainr : & types.Container {
110
+ HostIP : "127.0.0.1" ,
111
+ MappedPorts : map [int ]int {303 : 101 },
112
+ },
113
+ out : gin.H {"101/tcp" : gin.H {}},
114
+ portfw : true ,
115
+ },
116
+ {
117
+ tainr : & types.Container {
118
+ HostIP : "127.0.0.1" ,
119
+ HostPorts : map [int ]int {303 : 101 },
120
+ },
121
+ out : gin.H {"101/tcp" : gin.H {}},
122
+ portfw : true ,
123
+ },
124
+ {
125
+ tainr : & types.Container {
126
+ HostIP : "127.0.0.1" ,
127
+ MappedPorts : map [int ]int {303 : 101 },
128
+ HostPorts : map [int ]int {303 : 101 },
129
+ },
130
+ out : gin.H {"101/tcp" : gin.H {}},
131
+ portfw : true ,
132
+ },
133
+ {
134
+ tainr : & types.Container {
135
+ HostIP : "127.0.0.1" ,
136
+ MappedPorts : map [int ]int {- 303 : 303 },
137
+ },
138
+ out : gin.H {},
139
+ portfw : true ,
140
+ },
141
+ {
142
+ tainr : & types.Container {
143
+ HostIP : "127.0.0.1" ,
144
+ MappedPorts : map [int ]int {303 : 101 },
145
+ HostPorts : map [int ]int {202 : 101 },
146
+ },
147
+ out : gin.H {"101/tcp" : gin.H {}},
148
+ portfw : true ,
149
+ },
150
+ {
151
+ tainr : & types.Container {
152
+ HostIP : "127.0.0.1" ,
153
+ MappedPorts : map [int ]int {303 : 101 },
154
+ },
155
+ out : gin.H {"101/tcp" : gin.H {}},
156
+ portfw : false ,
157
+ },
158
+ }
159
+ for i , tst := range tests {
160
+ cr := & common.ContextRouter {Config : common.Config {PortForward : tst .portfw }}
161
+ res := getConfigExposedPorts (cr , tst .tainr )
162
+ if ! reflect .DeepEqual (res , tst .out ) {
163
+ t .Errorf ("failed test %d - expected %s, but got %s" , i , tst .out , res )
164
+ }
165
+ }
166
+ }
167
+
93
168
func TestGetContainerPorts (t * testing.T ) {
94
169
tests := []struct {
95
170
tainr * types.Container
0 commit comments