-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_test.go
119 lines (109 loc) · 3.7 KB
/
convert_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"github.com/franela/goblin"
"go.woodpecker-ci.org/woodpecker/v3/server/model"
"radicle-woodpecker-addon/internal"
"testing"
)
func Test_convert(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Radicle converter", func() {
project := &internal.Repository{
ID: "the_radicle_id",
Name: "hello_world",
DefaultBranch: "default_branch",
Head: "head_commit",
}
user := &model.User{
ForgeRemoteID: "remote_user_id",
Login: "user_login",
AccessToken: "user_token",
Avatar: "user_avatar",
Admin: true,
}
rad := &radicle{
url: "http://some.url",
nodeID: "the_nid",
sessionToken: "the_token",
}
g.It("Should convert user with", func() {
nodeInfo := &radicle{
url: "http://some.url",
nodeID: "node_id",
sessionToken: "sess_id",
alias: "my_alias",
hookSecret: "supresectret",
}
to := convertUser(nodeInfo)
g.Assert(to.ForgeRemoteID).Equal(model.ForgeRemoteID("node_id"))
g.Assert(to.Login).Equal("my_alias")
})
g.It("Should convert repository with", func() {
to := convertProject(project, user, rad)
g.Assert(to.ForgeRemoteID).Equal(model.ForgeRemoteID("the_radicle_id"))
g.Assert(to.Name).Equal("hello_world (the_radicle_id)")
g.Assert(to.FullName).Equal("hello_world (the_radicle_id)")
g.Assert(to.ForgeURL).Equal("http://some.url/the_radicle_id")
g.Assert(to.Clone).Equal("http://some.url/the_radicle_id.git")
g.Assert(to.Hash).Equal("the_radicle_id")
g.Assert(to.CloneSSH).Equal("")
g.Assert(to.Branch).Equal("default_branch")
g.Assert(to.Owner).Equal("radicle")
g.Assert(to.PREnabled).IsTrue()
g.Assert(to.Perm.Push).IsTrue()
g.Assert(to.Perm.Admin).IsTrue()
g.Assert(to.Perm.Pull).IsTrue()
})
g.It("Should convert project file to content with", func() {
projectFile := &internal.ProjectFile{
Content: "some unicode content καλημέρα!",
}
to, err := convertProjectFileToContent(projectFile)
g.Assert(err).IsNil()
g.Assert(to).Equal([]byte("some unicode content καλημέρα!"))
})
g.It("Should convert file content with", func() {
fileTreeEntries := internal.FileTreeEntries{
Path: "/path/to/file",
Name: "file name",
}
fileContent := []byte("some unicode content καλημέρα!")
to := convertFileContent(fileTreeEntries, fileContent)
g.Assert(to.Name).Equal("/path/to/file")
g.Assert(to.Data).Equal([]byte("some unicode content καλημέρα!"))
})
g.It("Should convert project patch with", func() {
patch := &internal.Patch{
ID: "patch_id",
Title: "Patch title",
State: internal.State{
Status: "open",
},
}
to := convertProjectPatch(patch)
g.Assert(to.Title).Equal("Patch title")
g.Assert(to.Index).Equal(model.ForgeRemoteID("patch_id"))
})
g.It("Should convert project patch with", func() {
hookRepo := &internal.HookRepository{
ID: "repo_id",
Name: "repo_name",
Description: "repo_descirpiotn",
Visibility: internal.RepoVisibility{},
DefaultBranch: "abranch",
Default_Branch: "abranch",
URL: "http://some.url",
CloneURL: "http://some.clone.url",
Delegates: []string{"delegate1", "delegate2"},
Head: "head_commit",
}
to := convertHookProject(hookRepo, nil, rad)
g.Assert(to.Clone).Equal("http://some.url/repo_id.git")
g.Assert(to.Branch).Equal("abranch")
g.Assert(to.Name).Equal("repo_name (repo_id)")
g.Assert(to.ForgeRemoteID).Equal(model.ForgeRemoteID("repo_id"))
g.Assert(to.ForgeURL).Equal("http://some.url/repo_id")
g.Assert(to.FullName).Equal("repo_name (repo_id)")
})
})
}