Skip to content

Commit

Permalink
fix: add ListFiles mock
Browse files Browse the repository at this point in the history
Signed-off-by: Gosha <gosha@rookout.com>
  • Loading branch information
gosharo committed Jul 10, 2023
1 parent e0b0de4 commit 7645a71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pkg/webhook_handler/webhook_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ func (wh *WebhookHandlerImpl) PrepareBatchForMatchingTriggers(ctx *context.Conte
}
}

var parameters *git_provider.CommitFile
parameters := &git_provider.CommitFile{
Path: nil,
Content: nil,
}
if IsFileExists(ctx, wh, ".workflows", "parameters.yaml") {
parameters, err = wh.clients.GitProvider.GetFile(
ctx,
Expand Down
14 changes: 13 additions & 1 deletion pkg/webhook_handler/webhook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/rookout/piper/pkg/utils"
assertion "github.com/stretchr/testify/assert"
"net/http"
"strings"
"testing"
)

Expand Down Expand Up @@ -65,7 +66,18 @@ func (m *MockGitProvider) GetFiles(ctx *context.Context, repo string, branch str
}

func (m *MockGitProvider) ListFiles(ctx *context.Context, repo string, branch string, path string) ([]string, error) {
return nil, nil
var files []string

fullPath := fmt.Sprintf("%s/%s/%s/", repo, branch, path)

for key := range commitFileMap {
if strings.Contains(key, fullPath) {
trimmed := strings.Replace(key, fullPath, "", -1)
files = append(files, trimmed)
}
}

return files, nil
}

func (m *MockGitProvider) SetWebhook() error {
Expand Down

0 comments on commit 7645a71

Please sign in to comment.