Skip to content

Commit 8414339

Browse files
committed
feat: add GetProtocols()
1 parent adf8d22 commit 8414339

File tree

5 files changed

+198
-153
lines changed

5 files changed

+198
-153
lines changed

internal/repositories/github/parser_public_test.go

Lines changed: 64 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ func (suite *ParserPublicTestSuite) SetupTest() {
5050

5151
func (suite *ParserPublicTestSuite) TestParse() {
5252
type repository struct {
53-
branch string
54-
href string
55-
owner string
56-
path string
57-
protocol string
58-
provider string
59-
repo string
60-
resource string
53+
branch string
54+
href string
55+
owner string
56+
path string
57+
protocol string
58+
protocols []string
59+
provider string
60+
repo string
61+
resource string
6162
}
6263

6364
type test struct {
@@ -70,84 +71,90 @@ func (suite *ParserPublicTestSuite) TestParse() {
7071
{
7172
input: "https://github.com/owner/repository",
7273
want: &repository{
73-
protocol: "https",
74-
resource: "github.com",
75-
owner: "owner",
76-
repo: "repository",
77-
path: "",
78-
branch: "",
79-
provider: "github",
80-
href: "https://github.com/owner/repository",
74+
protocol: "https",
75+
protocols: []string{"https"},
76+
resource: "github.com",
77+
owner: "owner",
78+
repo: "repository",
79+
path: "",
80+
branch: "",
81+
provider: "github",
82+
href: "https://github.com/owner/repository",
8183
},
8284
wantErr: false,
8385
},
8486
{
8587
input: "https://github.com/owner/repository/blob/main/files/file0.json",
8688
want: &repository{
87-
protocol: "https",
88-
resource: "github.com",
89-
owner: "owner",
90-
repo: "repository",
91-
path: "/files/file0.json",
92-
branch: "main",
93-
provider: "github",
94-
href: "https://github.com/owner/repository/blob/main/files/file0.json",
89+
protocol: "https",
90+
protocols: []string{"https"},
91+
resource: "github.com",
92+
owner: "owner",
93+
repo: "repository",
94+
path: "/files/file0.json",
95+
branch: "main",
96+
provider: "github",
97+
href: "https://github.com/owner/repository/blob/main/files/file0.json",
9598
},
9699
wantErr: false,
97100
},
98101
{
99102
input: "https://github.com/owner/repository/tree/main/files",
100103
want: &repository{
101-
protocol: "https",
102-
resource: "github.com",
103-
owner: "owner",
104-
repo: "repository",
105-
path: "/files",
106-
branch: "main",
107-
provider: "github",
108-
href: "https://github.com/owner/repository/tree/main/files",
104+
protocol: "https",
105+
protocols: []string{"https"},
106+
resource: "github.com",
107+
owner: "owner",
108+
repo: "repository",
109+
path: "/files",
110+
branch: "main",
111+
provider: "github",
112+
href: "https://github.com/owner/repository/tree/main/files",
109113
},
110114
wantErr: false,
111115
},
112116
{
113117
input: "https://raw.githubusercontent.com/owner/repository/main/files/file0.json",
114118
want: &repository{
115-
protocol: "https",
116-
resource: "raw.githubusercontent.com",
117-
owner: "owner",
118-
repo: "repository",
119-
path: "/files/file0.json",
120-
branch: "main",
121-
provider: "github",
122-
href: "https://raw.githubusercontent.com/owner/repository/main/files/file0.json",
119+
protocol: "https",
120+
protocols: []string{"https"},
121+
resource: "raw.githubusercontent.com",
122+
owner: "owner",
123+
repo: "repository",
124+
path: "/files/file0.json",
125+
branch: "main",
126+
provider: "github",
127+
href: "https://raw.githubusercontent.com/owner/repository/main/files/file0.json",
123128
},
124129
wantErr: false,
125130
},
126131
{
127132
input: "https://www.github.com/owner/repository",
128133
want: &repository{
129-
protocol: "https",
130-
resource: "www.github.com",
131-
owner: "owner",
132-
repo: "repository",
133-
path: "",
134-
branch: "",
135-
provider: "github",
136-
href: "https://www.github.com/owner/repository",
134+
protocol: "https",
135+
protocols: []string{"https"},
136+
resource: "www.github.com",
137+
owner: "owner",
138+
repo: "repository",
139+
path: "",
140+
branch: "",
141+
provider: "github",
142+
href: "https://www.github.com/owner/repository",
137143
},
138144
wantErr: false,
139145
},
140146
{
141147
input: "[email protected]:owner/repository.git",
142148
want: &repository{
143-
protocol: "git",
144-
resource: "github.com",
145-
owner: "owner",
146-
repo: "repository",
147-
path: "",
148-
branch: "",
149-
provider: "github",
150-
href: "[email protected]:owner/repository.git",
149+
protocol: "git",
150+
protocols: []string{"git"},
151+
resource: "github.com",
152+
owner: "owner",
153+
repo: "repository",
154+
path: "",
155+
branch: "",
156+
provider: "github",
157+
href: "[email protected]:owner/repository.git",
151158
},
152159
wantErr: false,
153160
},
@@ -178,6 +185,7 @@ func (suite *ParserPublicTestSuite) TestParse() {
178185
} else {
179186
require.NoError(suite.T(), err)
180187
assert.Equal(suite.T(), tc.want.protocol, got.GetProtocol())
188+
assert.Equal(suite.T(), tc.want.protocols, got.GetProtocols())
181189
assert.Equal(suite.T(), tc.want.resource, got.GetResourceName())
182190
assert.Equal(suite.T(), tc.want.href, got.GetHREF())
183191
assert.Equal(suite.T(), tc.want.owner, got.GetOwnerName())

0 commit comments

Comments
 (0)