Kaynağa Gözat

Add a smoke test for BurndownAnalysis.Consume

Vadim Markovtsev 7 yıl önce
ebeveyn
işleme
3834a77c85
2 değiştirilmiş dosya ile 80 ekleme ve 3 silme
  1. 3 3
      burndown.go
  2. 77 0
      burndown_test.go

+ 3 - 3
burndown.go

@@ -46,7 +46,7 @@ type BurndownAnalysis struct {
 	fileHistories map[string][][]int64
 	// peopleHistories is the weekly snapshots of each person's status.
 	peopleHistories [][][]int64
-	// fiales is the mapping <file path> -> hercules.File.
+	// files is the mapping <file path> -> *File.
 	files map[string]*File
 	// matrix is the mutual deletions and self insertions.
 	matrix []map[int]int64
@@ -276,11 +276,11 @@ func (analyser *BurndownAnalysis) newFile(
 	matrix []map[int]int64) *File {
 	if analyser.PeopleNumber == 0 {
 		return NewFile(day, size, NewStatus(global, analyser.updateStatus),
-			NewStatus(make(map[int]int64), analyser.updateStatus))
+			NewStatus(map[int]int64{}, analyser.updateStatus))
 	}
 	return NewFile(analyser.packPersonWithDay(author, day), size,
 		NewStatus(global, analyser.updateStatus),
-		NewStatus(make(map[int]int64), analyser.updateStatus),
+		NewStatus(map[int]int64{}, analyser.updateStatus),
 		NewStatus(people, analyser.updatePeople),
 		NewStatus(matrix, analyser.updateMatrix))
 }

+ 77 - 0
burndown_test.go

@@ -4,6 +4,8 @@ import (
 	"testing"
 
 	"github.com/stretchr/testify/assert"
+	"gopkg.in/src-d/go-git.v4/plumbing/object"
+	"gopkg.in/src-d/go-git.v4/plumbing"
 )
 
 func TestBurndownMeta(t *testing.T) {
@@ -15,3 +17,78 @@ func TestBurndownMeta(t *testing.T) {
 		assert.Contains(t, burndown.Requires(), name)
 	}
 }
+
+func TestBurndownConsume(t *testing.T) {
+	burndown := BurndownAnalysis{
+		Granularity: 30,
+		Sampling: 30,
+		PeopleNumber: 1,
+	}
+	burndown.Initialize(testRepository)
+	deps := map[string]interface{}{}
+	deps["author"] = 0
+	deps["day"] = 0
+	cache := map[plumbing.Hash]*object.Blob{}
+	hash := plumbing.NewHash("291286b4ac41952cbd1389fda66420ec03c1a9fe")
+	cache[hash], _ = testRepository.BlobObject(hash)
+	hash = plumbing.NewHash("334cde09da4afcb74f8d2b3e6fd6cce61228b485")
+	cache[hash], _ = testRepository.BlobObject(hash)
+	hash = plumbing.NewHash("dc248ba2b22048cc730c571a748e8ffcf7085ab9")
+	cache[hash], _ = testRepository.BlobObject(hash)
+	deps["blob_cache"] = cache
+	changes := make(object.Changes, 2)
+  treeFrom, _ := testRepository.TreeObject(plumbing.NewHash(
+		"a1eb2ea76eb7f9bfbde9b243861474421000eb96"))
+	treeTo, _ := testRepository.TreeObject(plumbing.NewHash(
+		"4d3f9500c2b9dc10925ad1705926b67f0f9101ca"))
+	changes[0] = &object.Change{From: object.ChangeEntry{
+		Name: "analyser.go",
+		Tree: treeFrom,
+		TreeEntry: object.TreeEntry{
+			Name: "analyser.go",
+			Mode: 0100644,
+			Hash: plumbing.NewHash("dc248ba2b22048cc730c571a748e8ffcf7085ab9"),
+		},
+	}, To: object.ChangeEntry{
+		Name: "analyser.go",
+		Tree: treeTo,
+		TreeEntry: object.TreeEntry{
+			Name: "analyser.go",
+			Mode: 0100644,
+			Hash: plumbing.NewHash("334cde09da4afcb74f8d2b3e6fd6cce61228b485"),
+		},
+	}}
+	changes[1] = &object.Change{From: object.ChangeEntry{}, To: object.ChangeEntry{
+		Name: ".travis.yml",
+		Tree: treeTo,
+		TreeEntry: object.TreeEntry{
+			Name: ".travis.yml",
+			Mode: 0100644,
+			Hash: plumbing.NewHash("291286b4ac41952cbd1389fda66420ec03c1a9fe"),
+		},
+	},
+	}
+	deps["renamed_changes"] = changes
+	result, err := burndown.Consume(deps)
+	assert.Nil(t, result)
+	assert.Nil(t, err)
+	assert.Equal(t, burndown.previousDay, 0)
+	assert.Equal(t, len(burndown.files), 2)
+	assert.Equal(t, burndown.files[".travis.yml"].Len(), 12)
+	assert.Equal(t, burndown.files["analyser.go"].Len(), 309)
+	assert.Equal(t, len(burndown.people), 1)
+	assert.Equal(t, burndown.people[0][0], int64(12 + 309))
+	assert.Equal(t, len(burndown.globalStatus), 1)
+	assert.Equal(t, burndown.globalStatus[0], int64(12 + 309))
+	assert.Equal(t, len(burndown.globalHistory), 0)
+	assert.Equal(t, len(burndown.fileHistories), 0)
+	burndown = BurndownAnalysis{
+		Granularity: 30,
+		Sampling: 0,
+		PeopleNumber: 0,
+	}
+	burndown.Initialize(testRepository)
+	_, err = burndown.Consume(deps)
+	assert.Nil(t, err)
+	assert.Equal(t, len(burndown.people), 0)
+}