(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func TestPortSimple(t *testing.T) { |
| 28 | tests := []struct { |
| 29 | item string |
| 30 | wantHost string |
| 31 | wantContainer string |
| 32 | wantProtocol string |
| 33 | wantErr bool |
| 34 | }{ |
| 35 | {item: "\"3000\"", wantHost: "3000", wantErr: false}, |
| 36 | {item: "3000:6000", wantHost: "3000", wantContainer: "6000", wantErr: false}, |
| 37 | {item: "3000-4000:6000", wantHost: "3000-4000", wantContainer: "6000", wantErr: false}, |
| 38 | {item: "3000:6000/udp", wantHost: "3000", wantContainer: "6000", wantProtocol: "udp", wantErr: false}, |
| 39 | {item: "3000-4000:6000/udp", wantHost: "3000-4000", wantContainer: "6000", wantProtocol: "udp", wantErr: false}, |
| 40 | {item: "3000-4000:6000-7000/udp", wantHost: "3000-4000", wantContainer: "6000-7000", wantProtocol: "udp", wantErr: false}, |
| 41 | {item: "127.0.0.1:3000-4000:6000-7000/udp", wantHost: "127.0.0.1:3000-4000", wantContainer: "6000-7000", wantProtocol: "udp", wantErr: false}, |
| 42 | } |
| 43 | for i, tt := range tests { |
| 44 | t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { |
| 45 | // MarshalYaml |
| 46 | if !tt.wantErr { |
| 47 | item := PortSimple{Host: tt.wantHost, Container: tt.wantContainer, Protocol: tt.wantProtocol} |
| 48 | content := MarshalYaml(item) |
| 49 | content = strings.TrimRight(content, "\n") |
| 50 | if content != tt.item { |
| 51 | t.Logf("%d %d", len(content), len(tt.item)) |
| 52 | t.Errorf("PortSimple.MarshalYAML() content = %v, wantContent %v", content, tt.item) |
| 53 | return |
| 54 | } |
| 55 | } |
| 56 | // UnmarshalYaml |
| 57 | var item PortSimple |
| 58 | err := UnmarshalYaml(tt.item, &item) |
| 59 | if (err != nil) != tt.wantErr { |
| 60 | t.Errorf("PortSimple.UnarshalYAML() error = %v, wantErr %v", err, tt.wantErr) |
| 61 | return |
| 62 | } |
| 63 | if item.Host != tt.wantHost { |
| 64 | t.Errorf("PortSimple.UnarshalYAML() host = %v, wantHost %v", item.Host, tt.wantHost) |
| 65 | return |
| 66 | } |
| 67 | if item.Container != tt.wantContainer { |
| 68 | t.Errorf("Image.UnarshalYAML() container = %v, wantContainer %v", item.Container, tt.wantContainer) |
| 69 | return |
| 70 | } |
| 71 | if item.Protocol != tt.wantProtocol { |
| 72 | t.Errorf("PortSimple.UnarshalYAML() protocol = %v, wantProtocol %v", item.Protocol, tt.wantProtocol) |
| 73 | return |
| 74 | } |
| 75 | }) |
| 76 | } |
| 77 | } |
nothing calls this directly
no test coverage detected