Skip to content

Commit 52f0b75

Browse files
committed
update tests
1 parent 1871276 commit 52f0b75

File tree

1 file changed

+23
-41
lines changed

1 file changed

+23
-41
lines changed

services/mirror/mirror_pull_test.go

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -66,45 +66,27 @@ func Test_parseRemoteUpdateOutput(t *testing.T) {
6666
}
6767

6868
func Test_checkRecoverableSyncError(t *testing.T) {
69-
recoverableDescription := " should be marked as recoverable."
70-
fatalDescription := " should be considered fatal and not recoverable."
71-
72-
// would exit status 128
73-
description := "A race condition in http git-fetch where certain refs were listed on the remote and are no longer there"
74-
stderr := "fatal: remote error: upload-pack: not our ref 988881adc9fc3655077dc2d4d757d480b5ea0e11"
75-
assert.True(t, checkRecoverableSyncError(stderr), description+recoverableDescription)
76-
77-
// would exit status 1
78-
description = "A race condition where a local gc/prune removes a named ref during a git-fetch"
79-
stderr = "cannot lock ref 'refs/pull/123456/merge': unable to resolve reference 'refs/pull/134153/merge'"
80-
assert.True(t, checkRecoverableSyncError(stderr), description+recoverableDescription)
81-
82-
description = "A race condition in http git-fetch where named refs were listed on the remote and are no longer there"
83-
stderr = "error: cannot lock ref 'refs/remotes/origin/foo': unable to resolve reference 'refs/remotes/origin/foo': reference broken"
84-
assert.True(t, checkRecoverableSyncError(stderr), description+recoverableDescription)
85-
86-
// would exit status 128
87-
description = "A race condition in http git-fetch where named refs were force-pushed during the update"
88-
stderr = "error: cannot lock ref 'refs/pull/123456/merge': is at 988881adc9fc3655077dc2d4d757d480b5ea0e11 but expected 7f894307ffc9553edbd0b671cab829786866f7b2"
89-
assert.True(t, checkRecoverableSyncError(stderr), description+recoverableDescription)
90-
91-
// would exit status 128
92-
description = "A race condition with other local git operations, such as git-maintenance,"
93-
stderr = "fatal: Unable to create '/data/gitea-repositories/foo-org/bar-repo.git/./objects/info/commit-graphs/commit-graph-chain.lock': File exists."
94-
assert.True(t, checkRecoverableSyncError(stderr), description+recoverableDescription)
95-
96-
// would exit status 128
97-
description = "Missing or unauthorized credentials"
98-
stderr = "fatal: Authentication failed for 'https://example.com/foo-does-not-exist/bar.git/'"
99-
assert.False(t, checkRecoverableSyncError(stderr), description+fatalDescription)
100-
101-
// would exit status 128
102-
description = "A non-existent remote repository"
103-
stderr = "fatal: Could not read from remote repository."
104-
assert.False(t, checkRecoverableSyncError(stderr), description+fatalDescription)
105-
106-
// would exit status 128
107-
description = "A non-functioning proxy"
108-
stderr = "fatal: unable to access 'https://example.com/foo-does-not-exist/bar.git/': Failed to connect to configured-https-proxy port 1080 after 0 ms: Couldn't connect to server"
109-
assert.False(t, checkRecoverableSyncError(stderr), description+fatalDescription)
69+
cases := []struct {
70+
recoverable bool
71+
message string
72+
}{
73+
// A race condition in http git-fetch where certain refs were listed on the remote and are no longer there, would exit status 128
74+
{true, "fatal: remote error: upload-pack: not our ref 988881adc9fc3655077dc2d4d757d480b5ea0e11"},
75+
// A race condition where a local gc/prune removes a named ref during a git-fetch would exit status 1
76+
{true, "cannot lock ref 'refs/pull/123456/merge': unable to resolve reference 'refs/pull/134153/merge'"},
77+
// A race condition in http git-fetch where named refs were listed on the remote and are no longer there
78+
{true, "error: cannot lock ref 'refs/remotes/origin/foo': unable to resolve reference 'refs/remotes/origin/foo': reference broken"},
79+
// A race condition in http git-fetch where named refs were force-pushed during the update, would exit status 128
80+
{true, "error: cannot lock ref 'refs/pull/123456/merge': is at 988881adc9fc3655077dc2d4d757d480b5ea0e11 but expected 7f894307ffc9553edbd0b671cab829786866f7b2"},
81+
// Missing or unauthorized credentials, would exit status 128
82+
{false, "fatal: Authentication failed for 'https://example.com/foo-does-not-exist/bar.git/'"},
83+
// A non-existent remote repository, would exit status 128
84+
{false, "fatal: Could not read from remote repository."},
85+
// A non-functioning proxy, would exit status 128
86+
{false, "fatal: unable to access 'https://example.com/foo-does-not-exist/bar.git/': Failed to connect to configured-https-proxy port 1080 after 0 ms: Couldn't connect to server"},
87+
}
88+
89+
for _, c := range cases {
90+
assert.Equal(t, c.recoverable, checkRecoverableSyncError(c.message), "test case: %s", c.message)
91+
}
11092
}

0 commit comments

Comments
 (0)