File: mappers_test.go

package info (click to toggle)
android-platform-tools 35.0.2-1~exp6
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 211,716 kB
  • sloc: cpp: 995,749; java: 290,495; ansic: 145,647; xml: 58,531; python: 39,608; sh: 14,500; javascript: 5,198; asm: 4,866; makefile: 3,115; yacc: 769; awk: 368; ruby: 183; sql: 140; perl: 88; lex: 67
file content (89 lines) | stat: -rw-r--r-- 2,692 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package mappers

import (
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
	c "repodiff/constants"
	e "repodiff/entities"
)

func TestCSVLineToDiffRow(t *testing.T) {
	exampleLine := "2018/02/20,platform/vendor/unbundled_google/packages/Ears,platform/vendor/unbundled_google/packages/Ears,Modified Projects,34,7,25,32,0"
	columns := strings.Split(exampleLine, ",")
	diffRow, err := CSVLineToDiffRow(columns)

	expected := e.DiffRow{
		Date:                 "2018/02/20",
		DownstreamProject:    "platform/vendor/unbundled_google/packages/Ears",
		UpstreamProject:      "platform/vendor/unbundled_google/packages/Ears",
		DiffStatus:           3,
		FilesChanged:         34,
		LineInsertions:       7,
		LineDeletions:        25,
		LineChanges:          32,
		CommitsNotUpstreamed: 0,
	}
	assert.Equal(t, nil, err, "Error should be nil")
	assert.Equal(t, expected, *diffRow, "Entities should be identical")
}

func TestCSVLineToCommitRow(t *testing.T) {
	exampleLine := "2018/02/20,61d5e61b6b6dfbf52d0d433759da964db31cc106,platform/tools/external/gradle,alruiz@google.com,Added Gradle 1.8 to prebuilts."
	columns := strings.Split(exampleLine, ",")
	commitRow, err := CSVLineToCommitRow(columns)

	expected := e.CommitRow{
		Date:              "2018/02/20",
		Commit:            "61d5e61b6b6dfbf52d0d433759da964db31cc106",
		DownstreamProject: "platform/tools/external/gradle",
		Author:            "alruiz@google.com",
		Subject:           "Added Gradle 1.8 to prebuilts.",
	}
	assert.Equal(t, nil, err, "Error should be nil")
	assert.Equal(t, expected, *commitRow, "Entities should be identical")
}

func TestDiffRowsToAggregateChangesOverTime(t *testing.T) {
	rows := DiffRowsToAggregateChangesOverTime(
		[]e.AnalyzedDiffRow{
			makeDiffRow(3, 1, 2),
			makeDiffRow(3, 3, 4),
			makeDiffRow(2, 7, 6),
		},
	)
	cols := rows[0]

	expected := []interface{}{
		"2018022315",
		2,
		11,
		12,
	}
	assert.Equal(t, expected, cols, "Columns should be equal")
}

func makeDiffRow(status, lineChanges, filesChanged int) e.AnalyzedDiffRow {
	return e.AnalyzedDiffRow{
		DiffRow: e.DiffRow{
			DiffStatus:        status,
			LineChanges:       lineChanges,
			FilesChanged:      filesChanged,
			DBInsertTimestamp: 1519427445,
		},
		Type: c.Empty,
	}
}

func TestGetAuthorTechAreaUnknown(t *testing.T) {
	fakeAuthor := "arthur.digby.sellers@google.com"
	techArea := GetAuthorTechArea(fakeAuthor)
	assert.Equal(t, "Unknown", techArea, "Author tech area should be unknown")
}

func TestGetAuthorTechAreaKnown(t *testing.T) {
	fakeAuthor := "jeffrey.lebowski@google.com"
	techArea := GetAuthorTechArea(fakeAuthor)
	assert.Equal(t, "Build", techArea, "Jeffrey Lebowski is on the Build team")
}