-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documents logic and adds tests for the basic scenarios. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package handler | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/go-github/github" | ||
) | ||
|
||
func Test_includePR_AfterCurrentPeriod(t *testing.T) { | ||
now := time.Now() | ||
|
||
prDate := now.Add(time.Hour * 48) | ||
pr := github.PullRequest{ | ||
ClosedAt: &prDate, | ||
MergedAt: &prDate, | ||
} | ||
|
||
previous := now.Add(time.Hour * -24) | ||
current := now.Add(time.Hour * 24) | ||
|
||
got := includePR(pr, previous, current) | ||
want := false | ||
|
||
if got != want { | ||
t.Errorf("Included value for PR %s incorrect for range: [%s-%s] got: %v, want %v", | ||
pr.ClosedAt.String(), previous.String(), current.String(), got, want) | ||
t.Fail() | ||
} | ||
} | ||
|
||
func Test_includePR_WithinCurrentRange(t *testing.T) { | ||
now := time.Now() | ||
|
||
prDate := now.Add(time.Hour) | ||
pr := github.PullRequest{ | ||
ClosedAt: &prDate, | ||
MergedAt: &prDate, | ||
} | ||
|
||
previous := now.Add(time.Hour * -24) | ||
current := now.Add(time.Hour * 24) | ||
|
||
got := includePR(pr, previous, current) | ||
want := true | ||
|
||
if got != want { | ||
t.Errorf("Included value for PR %s incorrect for range: [%s-%s] got: %v, want %v", | ||
pr.ClosedAt.String(), previous.String(), current.String(), got, want) | ||
t.Fail() | ||
} | ||
} | ||
|
||
func Test_includePR_WithinCurrentRange_ButNotMerged(t *testing.T) { | ||
now := time.Now() | ||
|
||
prDate := now.Add(time.Hour) | ||
pr := github.PullRequest{ | ||
ClosedAt: &prDate, | ||
} | ||
|
||
previous := now.Add(time.Hour * -24) | ||
current := now.Add(time.Hour * 24) | ||
|
||
got := includePR(pr, previous, current) | ||
want := false | ||
|
||
if got != want { | ||
t.Errorf("Included value for PR %s incorrect for range: [%s-%s] got: %v, want %v", | ||
pr.ClosedAt.String(), previous.String(), current.String(), got, want) | ||
t.Fail() | ||
} | ||
} |