| 15 | ) |
| 16 | |
| 17 | func TestBuildInfo(t *testing.T) { |
| 18 | const ( |
| 19 | title = "test title" |
| 20 | description = "test description" |
| 21 | terms = "test terms of service" |
| 22 | version = "test version" |
| 23 | contactName = "test contact name" |
| 24 | contactEmail = "test contact email" |
| 25 | contactURL = "test contact URL" |
| 26 | licenseName = "test license name" |
| 27 | licenseURL = "test license URL" |
| 28 | ) |
| 29 | cases := []struct { |
| 30 | Name string |
| 31 | Title string |
| 32 | Description string |
| 33 | TermsOfService string |
| 34 | Version string |
| 35 | ContactName string |
| 36 | ContactEmail string |
| 37 | ContactURL string |
| 38 | LicenseName string |
| 39 | LicenseURL string |
| 40 | }{{ |
| 41 | Name: "simple", |
| 42 | Title: title, |
| 43 | Description: description, |
| 44 | TermsOfService: terms, |
| 45 | Version: version, |
| 46 | ContactName: contactName, |
| 47 | ContactEmail: contactEmail, |
| 48 | ContactURL: contactURL, |
| 49 | LicenseName: licenseName, |
| 50 | LicenseURL: licenseURL, |
| 51 | }, { |
| 52 | Name: "empty version", |
| 53 | Title: title, |
| 54 | }, { |
| 55 | Name: "empty title", |
| 56 | Version: version, |
| 57 | }} |
| 58 | for _, c := range cases { |
| 59 | t.Run(c.Name, func(t *testing.T) { |
| 60 | api := &expr.APIExpr{ |
| 61 | Name: c.Name, |
| 62 | Title: c.Title, |
| 63 | Description: c.Description, |
| 64 | TermsOfService: c.TermsOfService, |
| 65 | Version: c.Version, |
| 66 | Contact: &expr.ContactExpr{Name: contactName, Email: contactEmail, URL: contactURL}, |
| 67 | License: &expr.LicenseExpr{Name: licenseName, URL: licenseURL}, |
| 68 | } |
| 69 | |
| 70 | info := buildInfo(api) |
| 71 | |
| 72 | expected := c.Title |
| 73 | if api.Title == "" { |
| 74 | expected = "Goa API" |