|
| 1 | +// Copyright 2023 The Gitea Authors. All rights reserved. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | +package mirror |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | +) |
| 11 | + |
| 12 | +func TestParseRemoteUpdateOutput(t *testing.T) { |
| 13 | + tests := []struct { |
| 14 | + input string |
| 15 | + results []*mirrorSyncResult |
| 16 | + }{ |
| 17 | + { |
| 18 | + // create tag |
| 19 | + input: "From https://xxx.com/xxx/xxx\n * [new tag] v1.4 -> v1.4\n", |
| 20 | + results: []*mirrorSyncResult{ |
| 21 | + { |
| 22 | + refName: "refs/tags/v1.4", |
| 23 | + oldCommitID: gitShortEmptySha, |
| 24 | + newCommitID: "", |
| 25 | + }, |
| 26 | + }, |
| 27 | + }, |
| 28 | + { |
| 29 | + // delete tag and create branch |
| 30 | + input: "From https://xxx.com/xxx/xxx\n - [deleted] (none) -> v1.0.1\n * [new branch] test/t3 -> test/t3\n * [new branch] test/t4 -> test/t4\n", |
| 31 | + results: []*mirrorSyncResult{ |
| 32 | + { |
| 33 | + refName: "v1.0.1", |
| 34 | + oldCommitID: "", |
| 35 | + newCommitID: gitShortEmptySha, |
| 36 | + }, |
| 37 | + { |
| 38 | + refName: "refs/heads/test/t3", |
| 39 | + oldCommitID: gitShortEmptySha, |
| 40 | + newCommitID: "", |
| 41 | + }, |
| 42 | + { |
| 43 | + refName: "refs/heads/test/t4", |
| 44 | + oldCommitID: gitShortEmptySha, |
| 45 | + newCommitID: "", |
| 46 | + }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + { |
| 50 | + // delete branch |
| 51 | + input: "From https://xxx.com/xxx/xxx\n - [deleted] (none) -> test/t2\n", |
| 52 | + results: []*mirrorSyncResult{ |
| 53 | + { |
| 54 | + refName: "test/t2", |
| 55 | + oldCommitID: "", |
| 56 | + newCommitID: gitShortEmptySha, |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | + { |
| 61 | + // new commits |
| 62 | + input: "From https://xxx.com/xxx/xxx\n aeb77a8..425ec44 test/t3 -> test/t3\n 93b2801..3e1d4c2 test/t4 -> test/t4\n", |
| 63 | + results: []*mirrorSyncResult{ |
| 64 | + { |
| 65 | + refName: "refs/heads/test/t3", |
| 66 | + oldCommitID: "aeb77a8", |
| 67 | + newCommitID: "425ec44", |
| 68 | + }, |
| 69 | + { |
| 70 | + refName: "refs/heads/test/t4", |
| 71 | + oldCommitID: "93b2801", |
| 72 | + newCommitID: "3e1d4c2", |
| 73 | + }, |
| 74 | + }, |
| 75 | + }, |
| 76 | + } |
| 77 | + |
| 78 | + for _, test := range tests { |
| 79 | + t.Run(test.input, func(t *testing.T) { |
| 80 | + results := parseRemoteUpdateOutput(test.input) |
| 81 | + assert.EqualValues(t, test.results, results, fmt.Sprintf("%#v", results)) |
| 82 | + }) |
| 83 | + } |
| 84 | +} |
0 commit comments