(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestCodeExportData(t *testing.T) { |
| 15 | tests := []struct { |
| 16 | name string |
| 17 | fields []string |
| 18 | code Code |
| 19 | output string |
| 20 | }{ |
| 21 | { |
| 22 | name: "exports requested fields", |
| 23 | fields: []string{"path", "textMatches"}, |
| 24 | code: Code{ |
| 25 | Repository: Repository{ |
| 26 | Name: "repo", |
| 27 | }, |
| 28 | Path: "path", |
| 29 | Name: "name", |
| 30 | TextMatches: []TextMatch{ |
| 31 | { |
| 32 | Fragment: "fragment", |
| 33 | Matches: []Match{ |
| 34 | { |
| 35 | Text: "fr", |
| 36 | Indices: []int{ |
| 37 | 0, |
| 38 | 1, |
| 39 | }, |
| 40 | }, |
| 41 | }, |
| 42 | Property: "property", |
| 43 | Type: "type", |
| 44 | }, |
| 45 | }, |
| 46 | }, |
| 47 | output: `{"path":"path","textMatches":[{"fragment":"fragment","matches":[{"indices":[0,1],"text":"fr"}],"property":"property","type":"type"}]}`, |
| 48 | }, |
| 49 | } |
| 50 | for _, tt := range tests { |
| 51 | t.Run(tt.name, func(t *testing.T) { |
| 52 | exported := tt.code.ExportData(tt.fields) |
| 53 | buf := bytes.Buffer{} |
| 54 | enc := json.NewEncoder(&buf) |
| 55 | require.NoError(t, enc.Encode(exported)) |
| 56 | assert.Equal(t, tt.output, strings.TrimSpace(buf.String())) |
| 57 | }) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | func TestCommitExportData(t *testing.T) { |
| 62 | var authoredAt = time.Date(2021, 2, 27, 11, 30, 0, 0, time.UTC) |
nothing calls this directly
no test coverage detected