mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-30 19:22:09 +00:00
chore: refactor act/artifactcache Handler to an interface (#934)
- the Handler struct becomes handler (lowercase) - the Handler interface is defined to be the existing methods - isClosed() is added and used only in tests - setgcAt() is added and used only in tests --- This is to allow mocking the Handler interface for testing. <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - other - [PR](https://code.forgejo.org/forgejo/runner/pulls/934): <!--number 934 --><!--line 0 --><!--description Y2hvcmU6IHJlZmFjdG9yIGFjdC9hcnRpZmFjdGNhY2hlIEhhbmRsZXIgdG8gYW4gaW50ZXJmYWNl-->chore: refactor act/artifactcache Handler to an interface<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/934 Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
bfc5516467
commit
69c6c70845
5 changed files with 52 additions and 29 deletions
|
@ -76,8 +76,7 @@ func TestHandler(t *testing.T) {
|
|||
})
|
||||
t.Run("close", func(t *testing.T) {
|
||||
require.NoError(t, handler.Close())
|
||||
assert.Nil(t, handler.server)
|
||||
assert.Nil(t, handler.listener)
|
||||
assert.True(t, handler.isClosed())
|
||||
_, err := httpClient.Post(fmt.Sprintf("%s/caches/%d", base, 1), "", nil)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
@ -983,7 +982,7 @@ func TestHandler_gcCache(t *testing.T) {
|
|||
}
|
||||
require.NoError(t, db.Close())
|
||||
|
||||
handler.gcAt = time.Time{} // ensure gcCache will not skip
|
||||
handler.setgcAt(time.Time{}) // ensure gcCache will not skip
|
||||
handler.gcCache()
|
||||
|
||||
db, err = handler.openDB()
|
||||
|
@ -1010,8 +1009,7 @@ func TestHandler_ExternalURL(t *testing.T) {
|
|||
|
||||
assert.Equal(t, handler.ExternalURL(), "http://127.0.0.1:34567")
|
||||
require.NoError(t, handler.Close())
|
||||
assert.Nil(t, handler.server)
|
||||
assert.Nil(t, handler.listener)
|
||||
assert.True(t, handler.isClosed())
|
||||
})
|
||||
|
||||
t.Run("reports correct URL on IPv6 zero host", func(t *testing.T) {
|
||||
|
@ -1021,8 +1019,7 @@ func TestHandler_ExternalURL(t *testing.T) {
|
|||
|
||||
assert.Equal(t, handler.ExternalURL(), "http://[2001:db8::]:34567")
|
||||
require.NoError(t, handler.Close())
|
||||
assert.Nil(t, handler.server)
|
||||
assert.Nil(t, handler.listener)
|
||||
assert.True(t, handler.isClosed())
|
||||
})
|
||||
|
||||
t.Run("reports correct URL on IPv6", func(t *testing.T) {
|
||||
|
@ -1032,7 +1029,6 @@ func TestHandler_ExternalURL(t *testing.T) {
|
|||
|
||||
assert.Equal(t, handler.ExternalURL(), "http://[2001:db8::1:2:3:4]:34567")
|
||||
require.NoError(t, handler.Close())
|
||||
assert.Nil(t, handler.server)
|
||||
assert.Nil(t, handler.listener)
|
||||
assert.True(t, handler.isClosed())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue