summaryrefslogtreecommitdiffstats
path: root/modules/convert/git_commit_test.go
diff options
context:
space:
mode:
authorLucas Queiroz <me@lucasqueiroz.dev>2020-10-05 01:07:54 -0300
committerGitHub <noreply@github.com>2020-10-05 12:07:54 +0800
commit67a5573310cf23726e3c2ef4651221c6dc150075 (patch)
treeadd7af9497a8d421fedaec36f1638fb70ab3b5ad /modules/convert/git_commit_test.go
parent48703c3c68ff3d948b406c422bc4f663da783d87 (diff)
downloadgitea-67a5573310cf23726e3c2ef4651221c6dc150075.tar.gz
gitea-67a5573310cf23726e3c2ef4651221c6dc150075.zip
[#13004] Add Timestamp to Tag list API (#13026)
* Add Timestamp to Tag list API * Add unit test for ToCommitMeta * Rename timestamp to created * Reformat files
Diffstat (limited to 'modules/convert/git_commit_test.go')
-rw-r--r--modules/convert/git_commit_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/convert/git_commit_test.go b/modules/convert/git_commit_test.go
new file mode 100644
index 0000000000..2158d0d777
--- /dev/null
+++ b/modules/convert/git_commit_test.go
@@ -0,0 +1,42 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package convert
+
+import (
+ "testing"
+ "time"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/git"
+ api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/util"
+
+ "github.com/go-git/go-git/v5/plumbing/object"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestToCommitMeta(t *testing.T) {
+ assert.NoError(t, models.PrepareTestDatabase())
+ headRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ sha1, _ := git.NewIDFromString("0000000000000000000000000000000000000000")
+ signature := &object.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)}
+ tag := &git.Tag{
+ Name: "Test Tag",
+ ID: sha1,
+ Object: sha1,
+ Type: "Test Type",
+ Tagger: signature,
+ Message: "Test Message",
+ }
+
+ commitMeta := ToCommitMeta(headRepo, tag)
+
+ assert.NotNil(t, commitMeta)
+ assert.EqualValues(t, &api.CommitMeta{
+ SHA: "0000000000000000000000000000000000000000",
+ URL: util.URLJoin(headRepo.APIURL(), "git/commits", "0000000000000000000000000000000000000000"),
+ Created: time.Unix(0, 0),
+ }, commitMeta)
+}