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.

38 lines
1.0 KiB

  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. "github.com/stretchr/testify/assert"
  9. )
  10. func TestCommitsCount(t *testing.T) {
  11. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  12. commitsCount, err := CommitsCount(bareRepo1Path, "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0")
  13. assert.NoError(t, err)
  14. assert.Equal(t, int64(3), commitsCount)
  15. }
  16. func TestGetFullCommitID(t *testing.T) {
  17. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  18. id, err := GetFullCommitID(bareRepo1Path, "8006ff9a")
  19. assert.NoError(t, err)
  20. assert.Equal(t, "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0", id)
  21. }
  22. func TestGetFullCommitIDError(t *testing.T) {
  23. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  24. id, err := GetFullCommitID(bareRepo1Path, "unknown")
  25. assert.Empty(t, id)
  26. if assert.Error(t, err) {
  27. assert.EqualError(t, err, "object does not exist [id: unknown, rel_path: ]")
  28. }
  29. }