Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
knbr13 committed Mar 1, 2024
1 parent 8e75f2f commit 64a27f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
13 changes: 10 additions & 3 deletions print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ func TestPrintTable(t *testing.T) {
13: 0,
}

since = time.Date(2024, 2, 7, 0, 0, 0, 0, time.UTC)
until = time.Date(2024, 2, 19, 0, 0, 0, 0, time.UTC)
since := time.Date(2024, 2, 7, 0, 0, 0, 0, time.UTC)
until := time.Date(2024, 2, 19, 0, 0, 0, 0, time.UTC)

oldStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w

printTable(commits)
printTable(commits, since, until)
w.Close()

dat, err := io.ReadAll(r)
Expand All @@ -173,6 +173,13 @@ func TestPrintTable(t *testing.T) {
var buf strings.Builder
_, _ = fmt.Fprint(&buf, string(dat))

for since.Weekday() != time.Sunday {
since = since.AddDate(0, 0, -1)
}
for until.Weekday() != time.Saturday {
until = until.AddDate(0, 0, 1)
}

s := strings.Builder{}
s1 := since

Expand Down
10 changes: 8 additions & 2 deletions stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ func TestFillCommits(t *testing.T) {
},
}

since := time.Now().AddDate(0, 0, -1)
until := time.Now().AddDate(0, 0, 1)

for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
commits := map[int]int{}
err = fillCommits(tt.Path, tt.Email, commits)
err = fillCommits(tt.Path, tt.Email, commits, since, until)
if err != nil {
t.Fatalf("failed to fill commits in %q: %v", tt.Path, err)
}
Expand Down Expand Up @@ -94,9 +97,12 @@ func TestProcessRepos(t *testing.T) {
},
}

since := time.Now().AddDate(0, 0, -1)
until := time.Now().AddDate(0, 0, 1)

for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
commits := processRepos(tt.Repos, tt.Email)
commits := processRepos(tt.Repos, tt.Email, since, until)
if len(commits) != len(tt.Expected) {
t.Errorf("processRepos11() = %v, want %v", commits, tt.Expected)
}
Expand Down
10 changes: 5 additions & 5 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func TestSetTimeFlags(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := setTimeFlags(tt.sinceflag, tt.untilflag)
b, err := setTimeFlags(tt.sinceflag, tt.untilflag)

if err != nil {
if err.Error() != tt.expectedError {
Expand All @@ -261,12 +261,12 @@ func TestSetTimeFlags(t *testing.T) {
return
}

if since != tt.expectedSince {
t.Errorf("Unexpected value of 'since'. Expected: %v, Got: %v", tt.expectedSince, since)
if b.Since != tt.expectedSince {
t.Errorf("Unexpected value of 'since'. Expected: %v, Got: %v", tt.expectedSince, b.Since)
}

if until != tt.expectedUntil {
t.Errorf("Unexpected value of 'until'. Expected: %v, Got: %v", tt.expectedUntil, until)
if b.Until != tt.expectedUntil {
t.Errorf("Unexpected value of 'until'. Expected: %v, Got: %v", tt.expectedUntil, b.Until)
}
})
}
Expand Down

0 comments on commit 64a27f5

Please sign in to comment.