From 369e43b0549065b32e9b341cf0bea70ff41f6767 Mon Sep 17 00:00:00 2001 From: MrMelon54 Date: Wed, 8 Jan 2025 23:01:58 +0000 Subject: [PATCH] Use empty hooks for testing --- hook/hook.go | 4 ++++ upload/upload_test.go | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hook/hook.go b/hook/hook.go index 9d4992c..2328fcb 100644 --- a/hook/hook.go +++ b/hook/hook.go @@ -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 diff --git a/upload/upload_test.go b/upload/upload_test.go index 7edd0de..16dc067 100644 --- a/upload/upload_test.go +++ b/upload/upload_test.go @@ -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)