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.

git_commit_test.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2020 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 convert
  5. import (
  6. "testing"
  7. "time"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/models/db"
  10. "code.gitea.io/gitea/models/unittest"
  11. "code.gitea.io/gitea/modules/git"
  12. api "code.gitea.io/gitea/modules/structs"
  13. "code.gitea.io/gitea/modules/util"
  14. "github.com/stretchr/testify/assert"
  15. )
  16. func TestToCommitMeta(t *testing.T) {
  17. assert.NoError(t, unittest.PrepareTestDatabase())
  18. headRepo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
  19. sha1, _ := git.NewIDFromString("0000000000000000000000000000000000000000")
  20. signature := &git.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)}
  21. tag := &git.Tag{
  22. Name: "Test Tag",
  23. ID: sha1,
  24. Object: sha1,
  25. Type: "Test Type",
  26. Tagger: signature,
  27. Message: "Test Message",
  28. }
  29. commitMeta := ToCommitMeta(headRepo, tag)
  30. assert.NotNil(t, commitMeta)
  31. assert.EqualValues(t, &api.CommitMeta{
  32. SHA: "0000000000000000000000000000000000000000",
  33. URL: util.URLJoin(headRepo.APIURL(), "git/commits", "0000000000000000000000000000000000000000"),
  34. Created: time.Unix(0, 0),
  35. }, commitMeta)
  36. }