github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/specgenutil/ports_test.go (about)

     1  package specgenutil
     2  
     3  import "testing"
     4  
     5  func Test_verifyExpose(t *testing.T) {
     6  	type args struct {
     7  		expose []string
     8  	}
     9  	tests := []struct {
    10  		name    string
    11  		args    args
    12  		wantErr bool
    13  	}{
    14  		{
    15  			name: "single port with tcp",
    16  			args: args{
    17  				expose: []string{"53/tcp"},
    18  			},
    19  			wantErr: false,
    20  		},
    21  		{
    22  			name: "single port with udp",
    23  			args: args{
    24  				expose: []string{"53/udp"},
    25  			},
    26  			wantErr: false,
    27  		},
    28  		{
    29  			name: "good port range",
    30  			args: args{
    31  				expose: []string{"100-133"},
    32  			},
    33  			wantErr: false,
    34  		},
    35  		{
    36  			name: "high to low should fail",
    37  			args: args{
    38  				expose: []string{"100-99"},
    39  			},
    40  			wantErr: true,
    41  		},
    42  		{
    43  			name: "range with protocol",
    44  			args: args{
    45  				expose: []string{"53/tcp-55/tcp"},
    46  			},
    47  			wantErr: false,
    48  		},
    49  	}
    50  	for _, tt := range tests {
    51  		t.Run(tt.name, func(t *testing.T) {
    52  			if err := verifyExpose(tt.args.expose); (err != nil) != tt.wantErr {
    53  				t.Errorf("verifyExpose() error = %v, wantErr %v", err, tt.wantErr)
    54  			}
    55  		})
    56  	}
    57  }