Use empty hooks for testing

This commit is contained in:
Melon 2025-01-08 23:01:58 +00:00
parent 21a6b03da1
commit 369e43b054
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
2 changed files with 9 additions and 4 deletions

View File

@ -16,6 +16,10 @@ func New(hookDir string, sitesDir string) *Hook {
}
func (h *Hook) Run(site, branch string) error {
if h.sitesDir == "" || h.hookDir == "" {
return nil
}
sitePath, err := securejoin.SecureJoin(h.sitesDir, site+"/work@"+branch)
if err != nil {
return err

View File

@ -8,6 +8,7 @@ import (
"fmt"
"github.com/1f349/bluebell"
"github.com/1f349/bluebell/database"
"github.com/1f349/bluebell/hook"
"github.com/google/uuid"
"github.com/julienschmidt/httprouter"
"github.com/spf13/afero"
@ -79,7 +80,7 @@ func (f *fakeUploadDB) GetSiteByDomain(_ context.Context, domain string) (databa
return database.Site{}, sql.ErrNoRows
}
func (f *fakeUploadDB) AddBranch(ctx context.Context, arg database.AddBranchParams) error {
func (f *fakeUploadDB) AddBranch(_ context.Context, arg database.AddBranchParams) error {
f.branchesMu.Lock()
defer f.branchesMu.Unlock()
if f.branchesMap == nil {
@ -117,7 +118,7 @@ func (f *fakeUploadDB) UpdateBranch(ctx context.Context, arg database.UpdateBran
func TestHandler_Handle(t *testing.T) {
fs := afero.NewMemMapFs()
h := New(fs, new(fakeUploadDB), nil)
h := New(fs, new(fakeUploadDB), hook.New("", ""))
r := httprouter.New()
r.POST("/u/:site/:branch", h.Handle)
@ -168,7 +169,7 @@ func extractTarGzUploadTest(t *testing.T, db uploadQueries) {
for _, branch := range []string{"main", "test", "dev"} {
t.Run(branch+" branch", func(t *testing.T) {
fs := afero.NewMemMapFs()
h := New(fs, db, nil)
h := New(fs, db, hook.New("", ""))
buffer := bytes.NewBuffer(testArchiveTarGz)
assert.NoError(t, h.extractTarGzUpload(buffer, "example.com", branch))
@ -188,7 +189,7 @@ func TestHandler_extractTarGzUpload_memoryDB_multiple(t *testing.T) {
func extractTarGzUploadMultipleTest(t *testing.T, db uploadQueries) {
fs := afero.NewMemMapFs()
h := New(fs, db, nil)
h := New(fs, db, hook.New("", ""))
sig := new(atomic.Bool)
wg := new(sync.WaitGroup)