| 30 | ) |
| 31 | |
| 32 | func TestEntry(t *testing.T) { |
| 33 | tmpl := template.Must( |
| 34 | template. |
| 35 | New("summary.tmpl"). |
| 36 | Funcs(TemplateFuncMap()). |
| 37 | Option("missingkey=error"). |
| 38 | Parse(string(defaultTmpl))) |
| 39 | |
| 40 | testCases := []struct { |
| 41 | name string |
| 42 | entry Entry |
| 43 | requireChangeLog bool |
| 44 | validChangeLogs []string |
| 45 | components []string |
| 46 | changeTypes []string |
| 47 | expectErr string |
| 48 | toString string |
| 49 | }{ |
| 50 | { |
| 51 | name: "empty", |
| 52 | entry: Entry{}, |
| 53 | expectErr: "'' is not a valid 'change_type'. Specify one of [breaking deprecation new_component enhancement bug_fix]\nspecify a 'component'\nspecify a 'note'\nspecify a 'user'", |
| 54 | }, |
| 55 | { |
| 56 | name: "missing_component", |
| 57 | entry: Entry{ |
| 58 | ChangeType: "enhancement", |
| 59 | Note: "enhance!", |
| 60 | Issues: []int{123}, |
| 61 | SubText: "", |
| 62 | User: "octocat", |
| 63 | }, |
| 64 | expectErr: "specify a 'component'", |
| 65 | }, |
| 66 | { |
| 67 | name: "missing_note", |
| 68 | entry: Entry{ |
| 69 | ChangeType: "bug_fix", |
| 70 | Component: "bar", |
| 71 | Issues: []int{123}, |
| 72 | SubText: "", |
| 73 | User: "octocat", |
| 74 | }, |
| 75 | expectErr: "specify a 'note'", |
| 76 | }, |
| 77 | { |
| 78 | // 'issues' is optional and validates when empty; update fails before |
| 79 | // rendering such an entry, so the bare "()" here is never reached in |
| 80 | // practice. |
| 81 | name: "no_issues", |
| 82 | entry: Entry{ |
| 83 | ChangeType: "bug_fix", |
| 84 | Component: "bar", |
| 85 | Note: "fix bar", |
| 86 | SubText: "", |
| 87 | User: "octocat", |
| 88 | }, |
| 89 | toString: "- `bar`: fix bar () (@octocat)", |