Skip to content

Commit 9d9e6ac

Browse files
zeripathlunny
authored andcommitted
Yet another attempt to fix the intermittent failure of gpg git test (#9146)
* Yet another attempt to fix the race in gpg_git_test * add some fail nows * Need to set preparetestenv * Ensure that http messages go to the correct server
1 parent 055f6d2 commit 9d9e6ac

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

integrations/git_helper_for_declarative_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bo
9191
assert.NoError(t, err)
9292
listener, err := net.Listen("tcp", u.Host)
9393
assert.NoError(t, err)
94+
u.Host = listener.Addr().String()
9495

9596
defer func() {
9697
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)

integrations/gpg_git_test.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
)
2424

2525
func TestGPGGit(t *testing.T) {
26+
prepareTestEnv(t)
2627
username := "user2"
2728

2829
// OK Set a new GPG home
@@ -125,11 +126,19 @@ func TestGPGGit(t *testing.T) {
125126
t.Run("CreateCRUDFile-Always", crudActionCreateFile(
126127
t, testCtx, user, "master", "always", "signed-always.txt", func(t *testing.T, response api.FileResponse) {
127128
assert.True(t, response.Verification.Verified)
129+
if !response.Verification.Verified {
130+
t.FailNow()
131+
return
132+
}
128133
assert.Equal(t, "[email protected]", response.Verification.Signer.Email)
129134
}))
130135
t.Run("CreateCRUDFile-ParentSigned-always", crudActionCreateFile(
131136
t, testCtx, user, "parentsigned", "parentsigned-always", "signed-parent2.txt", func(t *testing.T, response api.FileResponse) {
132137
assert.True(t, response.Verification.Verified)
138+
if !response.Verification.Verified {
139+
t.FailNow()
140+
return
141+
}
133142
assert.Equal(t, "[email protected]", response.Verification.Signer.Email)
134143
}))
135144
})
@@ -144,6 +153,10 @@ func TestGPGGit(t *testing.T) {
144153
t.Run("CreateCRUDFile-Always-ParentSigned", crudActionCreateFile(
145154
t, testCtx, user, "always", "always-parentsigned", "signed-always-parentsigned.txt", func(t *testing.T, response api.FileResponse) {
146155
assert.True(t, response.Verification.Verified)
156+
if !response.Verification.Verified {
157+
t.FailNow()
158+
return
159+
}
147160
assert.Equal(t, "[email protected]", response.Verification.Signer.Email)
148161
}))
149162
})
@@ -160,6 +173,10 @@ func TestGPGGit(t *testing.T) {
160173
assert.NotNil(t, branch.Commit)
161174
assert.NotNil(t, branch.Commit.Verification)
162175
assert.True(t, branch.Commit.Verification.Verified)
176+
if !branch.Commit.Verification.Verified {
177+
t.FailNow()
178+
return
179+
}
163180
assert.Equal(t, "[email protected]", branch.Commit.Verification.Signer.Email)
164181
}))
165182
})
@@ -170,7 +187,8 @@ func TestGPGGit(t *testing.T) {
170187

171188
t.Run("AlwaysSign-Initial-CRUD-Never", func(t *testing.T) {
172189
defer PrintCurrentTest(t)()
173-
testCtx := NewAPITestContext(t, username, "initial-always")
190+
testCtx := NewAPITestContext(t, username, "initial-always-never")
191+
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
174192
t.Run("CreateCRUDFile-Never", crudActionCreateFile(
175193
t, testCtx, user, "master", "never", "unsigned-never.txt", func(t *testing.T, response api.FileResponse) {
176194
assert.False(t, response.Verification.Verified)
@@ -180,13 +198,17 @@ func TestGPGGit(t *testing.T) {
180198
setting.Repository.Signing.CRUDActions = []string{"parentsigned"}
181199
onGiteaRun(t, func(t *testing.T, u *url.URL) {
182200
u.Path = baseAPITestContext.GitPath()
183-
184201
t.Run("AlwaysSign-Initial-CRUD-ParentSigned-On-Always", func(t *testing.T) {
185202
defer PrintCurrentTest(t)()
186-
testCtx := NewAPITestContext(t, username, "initial-always")
203+
testCtx := NewAPITestContext(t, username, "initial-always-parent")
204+
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
187205
t.Run("CreateCRUDFile-ParentSigned", crudActionCreateFile(
188206
t, testCtx, user, "master", "parentsigned", "signed-parent.txt", func(t *testing.T, response api.FileResponse) {
189207
assert.True(t, response.Verification.Verified)
208+
if !response.Verification.Verified {
209+
t.FailNow()
210+
return
211+
}
190212
assert.Equal(t, "[email protected]", response.Verification.Signer.Email)
191213
}))
192214
})
@@ -197,10 +219,15 @@ func TestGPGGit(t *testing.T) {
197219

198220
t.Run("AlwaysSign-Initial-CRUD-Always", func(t *testing.T) {
199221
defer PrintCurrentTest(t)()
200-
testCtx := NewAPITestContext(t, username, "initial-always")
222+
testCtx := NewAPITestContext(t, username, "initial-always-always")
223+
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
201224
t.Run("CreateCRUDFile-Always", crudActionCreateFile(
202225
t, testCtx, user, "master", "always", "signed-always.txt", func(t *testing.T, response api.FileResponse) {
203226
assert.True(t, response.Verification.Verified)
227+
if !response.Verification.Verified {
228+
t.FailNow()
229+
return
230+
}
204231
assert.Equal(t, "[email protected]", response.Verification.Signer.Email)
205232
}))
206233

@@ -287,7 +314,7 @@ func crudActionCreateFile(t *testing.T, ctx APITestContext, user *models.User, f
287314
Email: user.Email,
288315
},
289316
},
290-
Content: base64.StdEncoding.EncodeToString([]byte("This is new text")),
317+
Content: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("This is new text for %s", path))),
291318
}, callback...)
292319
}
293320

0 commit comments

Comments
 (0)