| 26 | } |
| 27 | |
| 28 | func TestServerExprValidate(t *testing.T) { |
| 29 | const ( |
| 30 | foo = "foo" |
| 31 | bar = "bar" |
| 32 | ) |
| 33 | var ( |
| 34 | validURI = URIExpr("http://example.com") |
| 35 | validURIs = []URIExpr{ |
| 36 | validURI, |
| 37 | } |
| 38 | errNoURI = fmt.Errorf("host must define at least one URI") |
| 39 | errServiceUndefined = fmt.Errorf("service %q undefined", bar) |
| 40 | ) |
| 41 | |
| 42 | cases := map[string]struct { |
| 43 | hosts []*HostExpr |
| 44 | services []string |
| 45 | expected *eval.ValidationErrors |
| 46 | }{ |
| 47 | "no error": { |
| 48 | hosts: []*HostExpr{ |
| 49 | { |
| 50 | URIs: validURIs, |
| 51 | }, |
| 52 | }, |
| 53 | services: []string{ |
| 54 | foo, |
| 55 | }, |
| 56 | expected: &eval.ValidationErrors{ |
| 57 | Errors: []error{}, |
| 58 | }, |
| 59 | }, |
| 60 | "error only in hosts": { |
| 61 | hosts: []*HostExpr{ |
| 62 | { |
| 63 | URIs: []URIExpr{}, |
| 64 | }, |
| 65 | }, |
| 66 | expected: &eval.ValidationErrors{ |
| 67 | Errors: []error{ |
| 68 | errNoURI, |
| 69 | }, |
| 70 | }, |
| 71 | }, |
| 72 | "error only in services": { |
| 73 | services: []string{ |
| 74 | bar, |
| 75 | }, |
| 76 | expected: &eval.ValidationErrors{ |
| 77 | Errors: []error{ |
| 78 | errServiceUndefined, |
| 79 | }, |
| 80 | }, |
| 81 | }, |
| 82 | "error in both": { |
| 83 | hosts: []*HostExpr{ |
| 84 | { |
| 85 | URIs: []URIExpr{}, |