Skip to content

Commit 6ee6b64

Browse files
committed
test: fixed webhook tests
1 parent 02e1c17 commit 6ee6b64

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

pkg/webhook_creator/mocks.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ package webhook_creator
33
import (
44
context2 "context"
55
"errors"
6+
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
67
"github.com/quickube/piper/pkg/git_provider"
78
"golang.org/x/net/context"
89
"net/http"
910
)
1011

1112
type MockGitProviderClient struct {
12-
ListFilesFunc func(ctx context.Context, repo string, branch string, path string) ([]string, error)
13-
GetFileFunc func(ctx context.Context, repo string, branch string, path string) (*git_provider.CommitFile, error)
14-
GetFilesFunc func(ctx context.Context, repo string, branch string, paths []string) ([]*git_provider.CommitFile, error)
15-
SetWebhookFunc func(ctx context.Context, repo *string) (*git_provider.HookWithStatus, error)
16-
UnsetWebhookFunc func(ctx context.Context, hook *git_provider.HookWithStatus) error
17-
HandlePayloadFunc func(request *http.Request, secret []byte) (*git_provider.WebhookPayload, error)
18-
SetStatusFunc func(ctx context.Context, repo *string, commit *string, linkURL *string, status *string, message *string) error
19-
PingHookFunc func(ctx context.Context, hook *git_provider.HookWithStatus) error
13+
ListFilesFunc func(ctx context.Context, repo string, branch string, path string) ([]string, error)
14+
GetFileFunc func(ctx context.Context, repo string, branch string, path string) (*git_provider.CommitFile, error)
15+
GetFilesFunc func(ctx context.Context, repo string, branch string, paths []string) ([]*git_provider.CommitFile, error)
16+
SetWebhookFunc func(ctx context.Context, repo *string) (*git_provider.HookWithStatus, error)
17+
UnsetWebhookFunc func(ctx context.Context, hook *git_provider.HookWithStatus) error
18+
HandlePayloadFunc func(request *http.Request, secret []byte) (*git_provider.WebhookPayload, error)
19+
SetStatusFunc func(ctx context.Context, repo *string, commit *string, linkURL *string, status *string, message *string) error
20+
PingHookFunc func(ctx context.Context, hook *git_provider.HookWithStatus) error
21+
GetCorrelatingEventFunc func(ctx context.Context, workflowEvent *v1alpha1.WorkflowPhase) (string, error)
2022
}
2123

2224
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
6769
}
6870
return errors.New("unimplemented")
6971
}
72+
func (m *MockGitProviderClient) GetCorrelatingEvent(ctx context.Context, workflowEvent *v1alpha1.WorkflowPhase) (string, error) {
73+
if m.GetCorrelatingEventFunc != nil {
74+
return m.GetCorrelatingEventFunc(ctx, workflowEvent)
75+
}
76+
return "", errors.New("unimplemented")
77+
}
7078

7179
func (m *MockGitProviderClient) PingHook(ctx context2.Context, hook *git_provider.HookWithStatus) error {
7280
if m.PingHookFunc != nil {

pkg/webhook_handler/webhook_handler_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package webhook_handler
33
import (
44
"context"
55
"fmt"
6+
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
67
"github.com/quickube/piper/pkg/clients"
78
"github.com/quickube/piper/pkg/common"
89
"github.com/quickube/piper/pkg/git_provider"
@@ -95,7 +96,9 @@ func (m *mockGitProvider) HandlePayload(ctx context.Context, request *http.Reque
9596
func (m *mockGitProvider) SetStatus(ctx context.Context, repo *string, commit *string, linkURL *string, status *string, message *string) error {
9697
return nil
9798
}
98-
99+
func (m *mockGitProvider) GetCorrelatingEvent(ctx context.Context, workflowEvent *v1alpha1.WorkflowPhase) (string, error) {
100+
return "", nil
101+
}
99102
func (m *mockGitProvider) PingHook(ctx context.Context, hook *git_provider.HookWithStatus) error {
100103
return nil
101104
}

0 commit comments

Comments
 (0)