1package mappers
2
3import (
4	"strings"
5	"testing"
6
7	"github.com/stretchr/testify/assert"
8	c "repodiff/constants"
9	e "repodiff/entities"
10)
11
12func TestCSVLineToDiffRow(t *testing.T) {
13	exampleLine := "2018/02/20,platform/vendor/unbundled_google/packages/Ears,platform/vendor/unbundled_google/packages/Ears,Modified Projects,34,7,25,32,0"
14	columns := strings.Split(exampleLine, ",")
15	diffRow, err := CSVLineToDiffRow(columns)
16
17	expected := e.DiffRow{
18		Date:                 "2018/02/20",
19		DownstreamProject:    "platform/vendor/unbundled_google/packages/Ears",
20		UpstreamProject:      "platform/vendor/unbundled_google/packages/Ears",
21		DiffStatus:           3,
22		FilesChanged:         34,
23		LineInsertions:       7,
24		LineDeletions:        25,
25		LineChanges:          32,
26		CommitsNotUpstreamed: 0,
27	}
28	assert.Equal(t, nil, err, "Error should be nil")
29	assert.Equal(t, expected, *diffRow, "Entities should be identical")
30}
31
32func TestCSVLineToCommitRow(t *testing.T) {
33	exampleLine := "2018/02/20,61d5e61b6b6dfbf52d0d433759da964db31cc106,platform/tools/external/gradle,alruiz@google.com,Added Gradle 1.8 to prebuilts."
34	columns := strings.Split(exampleLine, ",")
35	commitRow, err := CSVLineToCommitRow(columns)
36
37	expected := e.CommitRow{
38		Date:              "2018/02/20",
39		Commit:            "61d5e61b6b6dfbf52d0d433759da964db31cc106",
40		DownstreamProject: "platform/tools/external/gradle",
41		Author:            "alruiz@google.com",
42		Subject:           "Added Gradle 1.8 to prebuilts.",
43	}
44	assert.Equal(t, nil, err, "Error should be nil")
45	assert.Equal(t, expected, *commitRow, "Entities should be identical")
46}
47
48func TestDiffRowsToAggregateChangesOverTime(t *testing.T) {
49	rows := DiffRowsToAggregateChangesOverTime(
50		[]e.AnalyzedDiffRow{
51			makeDiffRow(3, 1, 2),
52			makeDiffRow(3, 3, 4),
53			makeDiffRow(2, 7, 6),
54		},
55	)
56	cols := rows[0]
57
58	expected := []interface{}{
59		"2018022315",
60		2,
61		11,
62		12,
63	}
64	assert.Equal(t, expected, cols, "Columns should be equal")
65}
66
67func makeDiffRow(status, lineChanges, filesChanged int) e.AnalyzedDiffRow {
68	return e.AnalyzedDiffRow{
69		DiffRow: e.DiffRow{
70			DiffStatus:        status,
71			LineChanges:       lineChanges,
72			FilesChanged:      filesChanged,
73			DBInsertTimestamp: 1519427445,
74		},
75		Type: c.Empty,
76	}
77}
78
79func TestGetAuthorTechAreaUnknown(t *testing.T) {
80	fakeAuthor := "arthur.digby.sellers@google.com"
81	techArea := GetAuthorTechArea(fakeAuthor)
82	assert.Equal(t, "Unknown", techArea, "Author tech area should be unknown")
83}
84
85func TestGetAuthorTechAreaKnown(t *testing.T) {
86	fakeAuthor := "jeffrey.lebowski@google.com"
87	techArea := GetAuthorTechArea(fakeAuthor)
88	assert.Equal(t, "Build", techArea, "Jeffrey Lebowski is on the Build team")
89}
90