You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_test.go 1.0KB

123456789101112131415161718192021222324252627282930313233343536
  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. package git
  5. import (
  6. "path/filepath"
  7. "testing"
  8. "time"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestGetLatestCommitTime(t *testing.T) {
  12. lct, err := GetLatestCommitTime(".")
  13. assert.NoError(t, err)
  14. // Time is in the past
  15. now := time.Now()
  16. assert.True(t, lct.Unix() < now.Unix(), "%d not smaller than %d", lct, now)
  17. // Time is after Mon Oct 23 03:52:09 2017 +0300
  18. // which is the time of commit
  19. // d47b98c44c9a6472e44ab80efe65235e11c6da2a
  20. refTime, err := time.Parse("Mon Jan 02 15:04:05 2006 -0700", "Mon Oct 23 03:52:09 2017 +0300")
  21. assert.NoError(t, err)
  22. assert.True(t, lct.Unix() > refTime.Unix(), "%d not greater than %d", lct, refTime)
  23. }
  24. func TestRepoIsEmpty(t *testing.T) {
  25. emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty")
  26. repo, err := OpenRepository(emptyRepo2Path)
  27. assert.NoError(t, err)
  28. isEmpty, err := repo.IsEmpty()
  29. assert.NoError(t, err)
  30. assert.True(t, isEmpty)
  31. }