Skip to content

Commit

Permalink
Add tests for includePR
Browse files Browse the repository at this point in the history
Documents logic and adds tests for the basic scenarios.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Nov 1, 2019
1 parent d3105fe commit d3d9c1b
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions handler/release_handler_test.go
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()
}
}

0 comments on commit d3d9c1b

Please sign in to comment.