mirror of
https://github.com/1f349/site-hosting.git
synced 2025-01-21 06:36:33 +00:00
Use empty hooks for testing
This commit is contained in:
parent
21a6b03da1
commit
369e43b054
@ -16,6 +16,10 @@ func New(hookDir string, sitesDir string) *Hook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hook) Run(site, branch string) error {
|
func (h *Hook) Run(site, branch string) error {
|
||||||
|
if h.sitesDir == "" || h.hookDir == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
sitePath, err := securejoin.SecureJoin(h.sitesDir, site+"/work@"+branch)
|
sitePath, err := securejoin.SecureJoin(h.sitesDir, site+"/work@"+branch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/1f349/bluebell"
|
"github.com/1f349/bluebell"
|
||||||
"github.com/1f349/bluebell/database"
|
"github.com/1f349/bluebell/database"
|
||||||
|
"github.com/1f349/bluebell/hook"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
@ -79,7 +80,7 @@ func (f *fakeUploadDB) GetSiteByDomain(_ context.Context, domain string) (databa
|
|||||||
return database.Site{}, sql.ErrNoRows
|
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()
|
f.branchesMu.Lock()
|
||||||
defer f.branchesMu.Unlock()
|
defer f.branchesMu.Unlock()
|
||||||
if f.branchesMap == nil {
|
if f.branchesMap == nil {
|
||||||
@ -117,7 +118,7 @@ func (f *fakeUploadDB) UpdateBranch(ctx context.Context, arg database.UpdateBran
|
|||||||
|
|
||||||
func TestHandler_Handle(t *testing.T) {
|
func TestHandler_Handle(t *testing.T) {
|
||||||
fs := afero.NewMemMapFs()
|
fs := afero.NewMemMapFs()
|
||||||
h := New(fs, new(fakeUploadDB), nil)
|
h := New(fs, new(fakeUploadDB), hook.New("", ""))
|
||||||
|
|
||||||
r := httprouter.New()
|
r := httprouter.New()
|
||||||
r.POST("/u/:site/:branch", h.Handle)
|
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"} {
|
for _, branch := range []string{"main", "test", "dev"} {
|
||||||
t.Run(branch+" branch", func(t *testing.T) {
|
t.Run(branch+" branch", func(t *testing.T) {
|
||||||
fs := afero.NewMemMapFs()
|
fs := afero.NewMemMapFs()
|
||||||
h := New(fs, db, nil)
|
h := New(fs, db, hook.New("", ""))
|
||||||
buffer := bytes.NewBuffer(testArchiveTarGz)
|
buffer := bytes.NewBuffer(testArchiveTarGz)
|
||||||
assert.NoError(t, h.extractTarGzUpload(buffer, "example.com", branch))
|
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) {
|
func extractTarGzUploadMultipleTest(t *testing.T, db uploadQueries) {
|
||||||
fs := afero.NewMemMapFs()
|
fs := afero.NewMemMapFs()
|
||||||
h := New(fs, db, nil)
|
h := New(fs, db, hook.New("", ""))
|
||||||
sig := new(atomic.Bool)
|
sig := new(atomic.Bool)
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user