1
1
// Copyright 2023 The Gitea Authors. All rights reserved.
2
+ // Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
2
3
// SPDX-License-Identifier: MIT
3
4
4
5
package integration
@@ -18,14 +19,18 @@ import (
18
19
"gopkg.in/yaml.v3"
19
20
)
20
21
21
- func createIssueConfig (t * testing.T , user * user_model.User , repo * repo_model.Repository , issueConfig map [string ]any ) {
22
+ func createIssueConfigInDirectory (t * testing.T , user * user_model.User , repo * repo_model.Repository , dir string , issueConfig map [string ]any ) {
22
23
config , err := yaml .Marshal (issueConfig )
23
24
assert .NoError (t , err )
24
25
25
- err = createOrReplaceFileInBranch (user , repo , ".gitea /ISSUE_TEMPLATE/config.yaml" , repo .DefaultBranch , string (config ))
26
+ err = createOrReplaceFileInBranch (user , repo , fmt . Sprintf ( "%s /ISSUE_TEMPLATE/config.yaml", dir ) , repo .DefaultBranch , string (config ))
26
27
assert .NoError (t , err )
27
28
}
28
29
30
+ func createIssueConfig (t * testing.T , user * user_model.User , repo * repo_model.Repository , issueConfig map [string ]any ) {
31
+ createIssueConfigInDirectory (t , user , repo , ".gitea" , issueConfig )
32
+ }
33
+
29
34
func getIssueConfig (t * testing.T , owner , repo string ) api.IssueConfig {
30
35
urlStr := fmt .Sprintf ("/api/v1/repos/%s/%s/issue_config" , owner , repo )
31
36
req := NewRequest (t , "GET" , urlStr )
@@ -44,13 +49,17 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
44
49
owner := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : repo .OwnerID })
45
50
46
51
t .Run ("Default" , func (t * testing.T ) {
52
+ defer tests .PrintCurrentTest (t )()
53
+
47
54
issueConfig := getIssueConfig (t , owner .Name , repo .Name )
48
55
49
56
assert .True (t , issueConfig .BlankIssuesEnabled )
50
57
assert .Len (t , issueConfig .ContactLinks , 0 )
51
58
})
52
59
53
60
t .Run ("DisableBlankIssues" , func (t * testing.T ) {
61
+ defer tests .PrintCurrentTest (t )()
62
+
54
63
config := make (map [string ]any )
55
64
config ["blank_issues_enabled" ] = false
56
65
@@ -63,6 +72,8 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
63
72
})
64
73
65
74
t .Run ("ContactLinks" , func (t * testing.T ) {
75
+ defer tests .PrintCurrentTest (t )()
76
+
66
77
contactLink := make (map [string ]string )
67
78
contactLink ["name" ] = "TestName"
68
79
contactLink ["url" ] = "https://example.com"
@@ -84,6 +95,8 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
84
95
})
85
96
86
97
t .Run ("Full" , func (t * testing.T ) {
98
+ defer tests .PrintCurrentTest (t )()
99
+
87
100
contactLink := make (map [string ]string )
88
101
contactLink ["name" ] = "TestName"
89
102
contactLink ["url" ] = "https://example.com"
@@ -113,6 +126,8 @@ func TestAPIRepoIssueConfigPaths(t *testing.T) {
113
126
owner := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : repo .OwnerID })
114
127
115
128
templateConfigCandidates := []string {
129
+ ".forgejo/ISSUE_TEMPLATE/config" ,
130
+ ".forgejo/issue_template/config" ,
116
131
".gitea/ISSUE_TEMPLATE/config" ,
117
132
".gitea/issue_template/config" ,
118
133
".github/ISSUE_TEMPLATE/config" ,
@@ -123,6 +138,8 @@ func TestAPIRepoIssueConfigPaths(t *testing.T) {
123
138
for _ , extension := range []string {".yaml" , ".yml" } {
124
139
fullPath := canidate + extension
125
140
t .Run (fullPath , func (t * testing.T ) {
141
+ defer tests .PrintCurrentTest (t )()
142
+
126
143
configMap := make (map [string ]any )
127
144
configMap ["blank_issues_enabled" ] = false
128
145
@@ -153,6 +170,8 @@ func TestAPIRepoValidateIssueConfig(t *testing.T) {
153
170
urlStr := fmt .Sprintf ("/api/v1/repos/%s/%s/issue_config/validate" , owner .Name , repo .Name )
154
171
155
172
t .Run ("Valid" , func (t * testing.T ) {
173
+ defer tests .PrintCurrentTest (t )()
174
+
156
175
req := NewRequest (t , "GET" , urlStr )
157
176
resp := MakeRequest (t , req , http .StatusOK )
158
177
@@ -164,18 +183,28 @@ func TestAPIRepoValidateIssueConfig(t *testing.T) {
164
183
})
165
184
166
185
t .Run ("Invalid" , func (t * testing.T ) {
167
- config := make (map [string ]any )
168
- config ["blank_issues_enabled" ] = "Test"
186
+ dirs := []string {".gitea" , ".forgejo" }
187
+ for _ , dir := range dirs {
188
+ t .Run (dir , func (t * testing.T ) {
189
+ defer tests .PrintCurrentTest (t )()
190
+ defer func () {
191
+ deleteFileInBranch (owner , repo , fmt .Sprintf ("%s/ISSUE_TEMPLATE/config.yaml" , dir ), repo .DefaultBranch )
192
+ }()
169
193
170
- createIssueConfig (t , owner , repo , config )
194
+ config := make (map [string ]any )
195
+ config ["blank_issues_enabled" ] = "Test"
171
196
172
- req := NewRequest (t , "GET" , urlStr )
173
- resp := MakeRequest (t , req , http .StatusOK )
197
+ createIssueConfigInDirectory (t , owner , repo , dir , config )
174
198
175
- var issueConfigValidation api.IssueConfigValidation
176
- DecodeJSON (t , resp , & issueConfigValidation )
199
+ req := NewRequest (t , "GET" , urlStr )
200
+ resp := MakeRequest (t , req , http .StatusOK )
201
+
202
+ var issueConfigValidation api.IssueConfigValidation
203
+ DecodeJSON (t , resp , & issueConfigValidation )
177
204
178
- assert .False (t , issueConfigValidation .Valid )
179
- assert .NotEmpty (t , issueConfigValidation .Message )
205
+ assert .False (t , issueConfigValidation .Valid )
206
+ assert .NotEmpty (t , issueConfigValidation .Message )
207
+ })
208
+ }
180
209
})
181
210
}
0 commit comments