code.gitea.io/gitea@v1.21.7/services/convert/git_commit_test.go (about)

     1  // Copyright 2020 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package convert
     5  
     6  import (
     7  	"testing"
     8  	"time"
     9  
    10  	repo_model "code.gitea.io/gitea/models/repo"
    11  	"code.gitea.io/gitea/models/unittest"
    12  	"code.gitea.io/gitea/modules/git"
    13  	api "code.gitea.io/gitea/modules/structs"
    14  	"code.gitea.io/gitea/modules/util"
    15  
    16  	"github.com/stretchr/testify/assert"
    17  )
    18  
    19  func TestToCommitMeta(t *testing.T) {
    20  	assert.NoError(t, unittest.PrepareTestDatabase())
    21  	headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
    22  	sha1, _ := git.NewIDFromString("0000000000000000000000000000000000000000")
    23  	signature := &git.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)}
    24  	tag := &git.Tag{
    25  		Name:    "Test Tag",
    26  		ID:      sha1,
    27  		Object:  sha1,
    28  		Type:    "Test Type",
    29  		Tagger:  signature,
    30  		Message: "Test Message",
    31  	}
    32  
    33  	commitMeta := ToCommitMeta(headRepo, tag)
    34  
    35  	assert.NotNil(t, commitMeta)
    36  	assert.EqualValues(t, &api.CommitMeta{
    37  		SHA:     "0000000000000000000000000000000000000000",
    38  		URL:     util.URLJoin(headRepo.APIURL(), "git/commits", "0000000000000000000000000000000000000000"),
    39  		Created: time.Unix(0, 0),
    40  	}, commitMeta)
    41  }