Skip to content

Commit

Permalink
fix: fixed webhook tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omri2001 committed Jan 11, 2025
1 parent 02e1c17 commit e434217
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
24 changes: 16 additions & 8 deletions pkg/webhook_creator/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion pkg/webhook_handler/webhook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit e434217

Please sign in to comment.