Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
duck8823 committed Jun 2, 2019
1 parent 3e96623 commit 5e045e0
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
79 changes: 79 additions & 0 deletions application/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/uuid"
"testing"
"time"
)

func TestContextWithJob(t *testing.T) {
Expand Down Expand Up @@ -74,3 +75,81 @@ func TestBuildJobFromContext(t *testing.T) {
})

}

func TestBuildJob_BeginAt(t *testing.T) {
// given
want := time.Unix(10, 10)

// and
sut := &application.BuildJob{}

// when
sut.BeginAt(want)
got := sut.GetBeginTime()

// then
if !cmp.Equal(got, want) {
t.Errorf("must be equal, but %+v", cmp.Diff(got, want))
}
}

func TestBuildJob_EndAt(t *testing.T) {
// given
want := time.Unix(10, 10)

// and
sut := &application.BuildJob{}

// when
sut.EndAt(want)
got := sut.GetEndTime()

// then
if !cmp.Equal(got, want) {
t.Errorf("must be equal, but %+v", cmp.Diff(got, want))
}
}

func TestBuildJob_Duration(t *testing.T) {
tests := []struct {
name string
beginTime time.Time
endTime time.Time
want string
}{
{
"when duration is less than 60 seconds",
time.Unix(10, 10),
time.Unix(70, 0),
"59sec",
},
{
"when duration is greater than 60 seconds",
time.Unix(10, 10),
time.Unix(70, 11),
"1min",
},
{
"when duration is equal to 60 seconds",
time.Unix(10, 10),
time.Unix(70, 10),
"1min",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
// given
sut := &application.BuildJob{}
sut.BeginAt(test.beginTime)
sut.EndAt(test.endTime)

// when
got := sut.Duration()

// then
if got != test.want {
t.Errorf("want %s, but got %s", test.want, got)
}
})
}
}
9 changes: 9 additions & 0 deletions application/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/tcnksm/go-latest"
"os"
"testing"
"time"
)

type MaskString = maskString
Expand Down Expand Up @@ -65,3 +66,11 @@ func GenerateSSHKey(t *testing.T, path string) {
t.Fatalf("error occur: %+v", err)
}
}

func (j *BuildJob) GetBeginTime() time.Time {
return j.beginTime
}

func (j *BuildJob) GetEndTime() time.Time {
return j.endTime
}

0 comments on commit 5e045e0

Please sign in to comment.