Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit 3c11853

Browse files
committed
Add test for GetLatestCommitTime
The test checks that latest commit time is before now and more recent than the commit this PR is based at Test no error is raised by time parsing and GetLatestCommitTime Print actual time when tests fail
1 parent 20222c4 commit 3c11853

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

repo_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package git
6+
7+
import (
8+
"testing"
9+
"time"
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestGetLatestCommitTime(t *testing.T) {
14+
lct, err := GetLatestCommitTime(".")
15+
assert.NoError(t, err)
16+
// Time is in the past
17+
now := time.Now()
18+
assert.True(t, lct.Unix() < now.Unix(), "%d not smaller than %d", lct, now)
19+
// Time is after Mon Oct 23 03:52:09 2017 +0300
20+
// which is the time of commit
21+
// d47b98c44c9a6472e44ab80efe65235e11c6da2a
22+
refTime, err := time.Parse("Mon Jan 02 15:04:05 2006 -0700", "Mon Oct 23 03:52:09 2017 +0300")
23+
assert.NoError(t, err)
24+
assert.True(t, lct.Unix() > refTime.Unix(), "%d not greater than %d", lct, refTime)
25+
}

0 commit comments

Comments
 (0)