code.gitea.io/gitea@v1.21.7/services/mirror/mirror_test.go (about)

     1  // Copyright 2023 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package mirror
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func Test_parseRemoteUpdateOutput(t *testing.T) {
    13  	output := `
    14   * [new tag]         v0.1.8     -> v0.1.8
    15   * [new branch]      master     -> origin/master
    16   - [deleted]         (none)     -> origin/test1
    17   - [deleted]         (none)     -> tag1
    18   + f895a1e...957a993 test2      -> origin/test2  (forced update)
    19     957a993..a87ba5f  test3      -> origin/test3
    20  `
    21  	results := parseRemoteUpdateOutput(output, "origin")
    22  	assert.Len(t, results, 6)
    23  	assert.EqualValues(t, "refs/tags/v0.1.8", results[0].refName.String())
    24  	assert.EqualValues(t, gitShortEmptySha, results[0].oldCommitID)
    25  	assert.EqualValues(t, "", results[0].newCommitID)
    26  
    27  	assert.EqualValues(t, "refs/heads/master", results[1].refName.String())
    28  	assert.EqualValues(t, gitShortEmptySha, results[1].oldCommitID)
    29  	assert.EqualValues(t, "", results[1].newCommitID)
    30  
    31  	assert.EqualValues(t, "refs/heads/test1", results[2].refName.String())
    32  	assert.EqualValues(t, "", results[2].oldCommitID)
    33  	assert.EqualValues(t, gitShortEmptySha, results[2].newCommitID)
    34  
    35  	assert.EqualValues(t, "refs/tags/tag1", results[3].refName.String())
    36  	assert.EqualValues(t, "", results[3].oldCommitID)
    37  	assert.EqualValues(t, gitShortEmptySha, results[3].newCommitID)
    38  
    39  	assert.EqualValues(t, "refs/heads/test2", results[4].refName.String())
    40  	assert.EqualValues(t, "f895a1e", results[4].oldCommitID)
    41  	assert.EqualValues(t, "957a993", results[4].newCommitID)
    42  
    43  	assert.EqualValues(t, "refs/heads/test3", results[5].refName.String())
    44  	assert.EqualValues(t, "957a993", results[5].oldCommitID)
    45  	assert.EqualValues(t, "a87ba5f", results[5].newCommitID)
    46  }