From 6ab4bed97343e62b6ecf5525157b8ac1a7517dc8 Mon Sep 17 00:00:00 2001 From: devily <86979425@qq.com> Date: Tue, 31 Jul 2018 10:25:57 +0800 Subject: [PATCH] Add prots_test.go test case. --- apis/opts/ports_test.go | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/apis/opts/ports_test.go b/apis/opts/ports_test.go index ac55e27d2..5a74dee33 100644 --- a/apis/opts/ports_test.go +++ b/apis/opts/ports_test.go @@ -16,7 +16,45 @@ func TestParseExposedPorts(t *testing.T) { want map[string]interface{} wantErr bool }{ - // TODO: Add test cases. + //Correct test case + //Use '-' represent multiple addresses + //The default method is '/tcp' + { + name: "test1", + args: args{ + portList: []string{"8080-8081/udp", "22"}, + expose: []string{"8082", "22-24/tcp"}, + }, + want: map[string]interface{}{ + "8080/udp": struct{}{}, + "8081/udp": struct{}{}, + "8082/tcp": struct{}{}, + "22/tcp": struct{}{}, + "23/tcp": struct{}{}, + "24/tcp": struct{}{}, + }, + wantErr: false, + }, + //Input format error + { + name: "test2", + args: args{ + portList: []string{"0.0.0.0:8080", "0.0.0.0:22"}, + expose: []string{"0.0.0.0:8080", "0.0.0.0:22"}, + }, + want: nil, + wantErr: true, + }, + //Input contains illegal characters (Chinese characters) + { + name: "test3", + args: args{ + portList: []string{"8080", "8081"}, + expose: []string{"8082/udp", "8081"}, + }, + want: nil, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {