-
Notifications
You must be signed in to change notification settings - Fork 0
/
branch_test.go
64 lines (51 loc) · 2.59 KB
/
branch_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package goscm
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
func TestBranch_ListRepoBranches_Client(t *testing.T) {
server := setupSingleTestServer(
"testdata/branch/scm-listrepobranches-example.json",
"/api/v2/repositories/scm-manager/scm-manager/branches/", t)
defer server.Close()
client, err := NewClient(server.URL, "")
require.NoError(t, err, "Error during client initialization")
branches, err := client.ListRepoBranches("scm-manager", "scm-manager")
require.NoError(t, err, "The ListRepoBranches method of the client threw an error.")
assert.Len(t, branches.Embedded.Branches, 4)
assert.Equal(t, "branchInCamelCase", branches.Embedded.Branches[0].Name)
assert.Equal(t, "2024-11-14T10:50:45Z", branches.Embedded.Branches[1].LastCommitDate)
assert.Equal(t, "889023f4d4c8f2672ff752cf8d3a1d8d2f0fb4af", branches.Embedded.Branches[2].Revision)
assert.Equal(t, "[email protected]", branches.Embedded.Branches[3].LastCommitter.Mail)
}
func TestBranch_GetRepoBranch_Client(t *testing.T) {
server := setupSingleTestServer(
"testdata/branch/scm-getrepobranch-example.json",
"/api/v2/repositories/scm-manager/scm-manager/branches/feature%2Fbranch-with-a-slash", t)
defer server.Close()
client, err := NewClient(server.URL, "")
require.NoError(t, err, "Error during client initialization")
branch, err := client.GetRepoBranch("scm-manager", "scm-manager", "feature/branch-with-a-slash")
require.NoError(t, err, "The GetRepoBranch method of the client threw an error.")
assert.Equal(t, "feature/branch-with-a-slash", branch.Name)
assert.Equal(t, "889023f4d4c8f2672ff752cf8d3a1d8d2f0fb4af", branch.Revision)
assert.Equal(t, false, branch.DefaultBranch)
assert.Equal(t, "2024-11-14T14:51:42Z", branch.LastCommitDate)
assert.Equal(t, "SCM Administrator", branch.LastCommitter.Name)
}
func TestBranch_GetDefaultBranch_Client(t *testing.T) {
server := setupSingleTestServer(
"testdata/branch/scm-listrepobranches-example.json",
"/api/v2/repositories/scm-manager/scm-manager/branches/", t)
defer server.Close()
client, err := NewClient(server.URL, "")
require.NoError(t, err, "Error during client initialization")
branch, err := client.GetDefaultBranch("scm-manager", "scm-manager")
require.NoError(t, err, "The GetDefaultBranch method of the client threw an error.")
assert.Equal(t, "main", branch.Name)
assert.Equal(t, "22442f21ce44c78517f5100c252b1681089dd70c", branch.Revision)
assert.Equal(t, true, branch.DefaultBranch)
assert.Equal(t, "2024-11-14T14:24:40Z", branch.LastCommitDate)
assert.Equal(t, "SCM Administrator", branch.LastCommitter.Name)
}