(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func TestValidateEndpoints(t *testing.T) { |
| 27 | |
| 28 | duplicateNameErr := "multiple endpoint entries with same name" |
| 29 | duplicatePortErr := "devfile contains multiple containers with same endpoint targetPort" |
| 30 | |
| 31 | tests := []struct { |
| 32 | name string |
| 33 | endpoints []v1alpha2.Endpoint |
| 34 | processedEndpointName map[string]bool |
| 35 | processedEndpointPort map[int]bool |
| 36 | wantErr []string |
| 37 | }{ |
| 38 | { |
| 39 | name: "Duplicate endpoint name", |
| 40 | endpoints: []v1alpha2.Endpoint{ |
| 41 | generateDummyEndpoint("url1", 8080), |
| 42 | generateDummyEndpoint("url1", 8081), |
| 43 | }, |
| 44 | processedEndpointName: map[string]bool{}, |
| 45 | processedEndpointPort: map[int]bool{}, |
| 46 | wantErr: []string{duplicateNameErr}, |
| 47 | }, |
| 48 | { |
| 49 | name: "Duplicate endpoint name across components", |
| 50 | endpoints: []v1alpha2.Endpoint{ |
| 51 | generateDummyEndpoint("url1", 8080), |
| 52 | }, |
| 53 | processedEndpointName: map[string]bool{ |
| 54 | "url1": true, |
| 55 | }, |
| 56 | processedEndpointPort: map[int]bool{}, |
| 57 | wantErr: []string{duplicateNameErr}, |
| 58 | }, |
| 59 | { |
| 60 | name: "Duplicate endpoint port within same component", |
| 61 | endpoints: []v1alpha2.Endpoint{ |
| 62 | generateDummyEndpoint("url1", 8080), |
| 63 | generateDummyEndpoint("url2", 8080), |
| 64 | }, |
| 65 | processedEndpointName: map[string]bool{}, |
| 66 | processedEndpointPort: map[int]bool{}, |
| 67 | }, |
| 68 | { |
| 69 | name: "Duplicate endpoint port across components", |
| 70 | endpoints: []v1alpha2.Endpoint{ |
| 71 | generateDummyEndpoint("url1", 8080), |
| 72 | generateDummyEndpoint("url2", 8081), |
| 73 | }, |
| 74 | processedEndpointName: map[string]bool{}, |
| 75 | processedEndpointPort: map[int]bool{ |
| 76 | 8080: true, |
| 77 | }, |
| 78 | wantErr: []string{duplicatePortErr}, |
| 79 | }, |
| 80 | { |
| 81 | name: "Multiple errors: Duplicate endpoint name, duplicate endpoint port", |
| 82 | endpoints: []v1alpha2.Endpoint{ |
| 83 | generateDummyEndpoint("url1", 8080), |
nothing calls this directly
no test coverage detected