From e434217891e0e3773c7d5523c05276b95d916fec Mon Sep 17 00:00:00 2001 From: Omri Assa Date: Sat, 11 Jan 2025 21:33:52 +0200 Subject: [PATCH] fix: fixed webhook tests --- pkg/webhook_creator/mocks.go | 24 ++++++++++++++------- pkg/webhook_handler/webhook_handler_test.go | 5 ++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pkg/webhook_creator/mocks.go b/pkg/webhook_creator/mocks.go index 529f4dd..d5d6718 100644 --- a/pkg/webhook_creator/mocks.go +++ b/pkg/webhook_creator/mocks.go @@ -3,20 +3,22 @@ package webhook_creator import ( context2 "context" "errors" + "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" "github.com/quickube/piper/pkg/git_provider" "golang.org/x/net/context" "net/http" ) type MockGitProviderClient struct { - ListFilesFunc func(ctx context.Context, repo string, branch string, path string) ([]string, error) - GetFileFunc func(ctx context.Context, repo string, branch string, path string) (*git_provider.CommitFile, error) - GetFilesFunc func(ctx context.Context, repo string, branch string, paths []string) ([]*git_provider.CommitFile, error) - SetWebhookFunc func(ctx context.Context, repo *string) (*git_provider.HookWithStatus, error) - UnsetWebhookFunc func(ctx context.Context, hook *git_provider.HookWithStatus) error - HandlePayloadFunc func(request *http.Request, secret []byte) (*git_provider.WebhookPayload, error) - SetStatusFunc func(ctx context.Context, repo *string, commit *string, linkURL *string, status *string, message *string) error - PingHookFunc func(ctx context.Context, hook *git_provider.HookWithStatus) error + ListFilesFunc func(ctx context.Context, repo string, branch string, path string) ([]string, error) + GetFileFunc func(ctx context.Context, repo string, branch string, path string) (*git_provider.CommitFile, error) + GetFilesFunc func(ctx context.Context, repo string, branch string, paths []string) ([]*git_provider.CommitFile, error) + SetWebhookFunc func(ctx context.Context, repo *string) (*git_provider.HookWithStatus, error) + UnsetWebhookFunc func(ctx context.Context, hook *git_provider.HookWithStatus) error + HandlePayloadFunc func(request *http.Request, secret []byte) (*git_provider.WebhookPayload, error) + SetStatusFunc func(ctx context.Context, repo *string, commit *string, linkURL *string, status *string, message *string) error + PingHookFunc func(ctx context.Context, hook *git_provider.HookWithStatus) error + GetCorrelatingEventFunc func(ctx context.Context, workflowEvent *v1alpha1.WorkflowPhase) (string, error) } func (m *MockGitProviderClient) ListFiles(ctx context2.Context, repo string, branch string, path string) ([]string, error) { @@ -67,6 +69,12 @@ func (m *MockGitProviderClient) SetStatus(ctx context2.Context, repo *string, co } return errors.New("unimplemented") } +func (m *MockGitProviderClient) GetCorrelatingEvent(ctx context.Context, workflowEvent *v1alpha1.WorkflowPhase) (string, error) { + if m.GetCorrelatingEventFunc != nil { + return m.GetCorrelatingEventFunc(ctx, workflowEvent) + } + return "", errors.New("unimplemented") +} func (m *MockGitProviderClient) PingHook(ctx context2.Context, hook *git_provider.HookWithStatus) error { if m.PingHookFunc != nil { diff --git a/pkg/webhook_handler/webhook_handler_test.go b/pkg/webhook_handler/webhook_handler_test.go index 1fea48d..785faaf 100644 --- a/pkg/webhook_handler/webhook_handler_test.go +++ b/pkg/webhook_handler/webhook_handler_test.go @@ -3,6 +3,7 @@ package webhook_handler import ( "context" "fmt" + "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" "github.com/quickube/piper/pkg/clients" "github.com/quickube/piper/pkg/common" "github.com/quickube/piper/pkg/git_provider" @@ -95,7 +96,9 @@ func (m *mockGitProvider) HandlePayload(ctx context.Context, request *http.Reque func (m *mockGitProvider) SetStatus(ctx context.Context, repo *string, commit *string, linkURL *string, status *string, message *string) error { return nil } - +func (m *mockGitProvider) GetCorrelatingEvent(ctx context.Context, workflowEvent *v1alpha1.WorkflowPhase) (string, error) { + return "", nil +} func (m *mockGitProvider) PingHook(ctx context.Context, hook *git_provider.HookWithStatus) error { return nil }