summaryrefslogtreecommitdiff
path: root/pkg/specgenutil/ports_test.go
blob: 3f62c619ca55a0124e26f339286e6cc7e3470bf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package specgenutil

import "testing"

func Test_verifyExpose(t *testing.T) {
	type args struct {
		expose []string
	}
	tests := []struct {
		name    string
		args    args
		wantErr bool
	}{
		{
			name: "single port with tcp",
			args: args{
				expose: []string{"53/tcp"},
			},
			wantErr: false,
		},
		{
			name: "single port with udp",
			args: args{
				expose: []string{"53/udp"},
			},
			wantErr: false,
		},
		{
			name: "good port range",
			args: args{
				expose: []string{"100-133"},
			},
			wantErr: false,
		},
		{
			name: "high to low should fail",
			args: args{
				expose: []string{"100-99"},
			},
			wantErr: true,
		},
		{
			name: "range with protocol",
			args: args{
				expose: []string{"53/tcp-55/tcp"},
			},
			wantErr: false,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if err := verifyExpose(tt.args.expose); (err != nil) != tt.wantErr {
				t.Errorf("verifyExpose() error = %v, wantErr %v", err, tt.wantErr)
			}
		})
	}
}