Skip to content

Commit

Permalink
webhook unit test
Browse files Browse the repository at this point in the history
Signed-off-by: DrowYue <[email protected]>
  • Loading branch information
DrowYue committed Aug 26, 2024
1 parent cf4b8af commit 0f6afed
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/webhook/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@ var (
)

func Test(t *testing.T) {
clustersCreated := "clustersCreated"
webhook := &webhookmodels.Webhook{
Enabled: true,
URL: "https://horizon.org",
SSLVerifyEnabled: false,
Triggers: clustersCreated,
ResourceType: "clusters",
ResourceID: 0,
}

webhook, err := mgr.CreateWebhook(ctx, webhook)
assert.Nil(t, err)

retrieveWebhook, err := mgr.GetWebhook(ctx, webhook.ID)
assert.Nil(t, err)
assert.NotNil(t, retrieveWebhook)
assert.Equal(t, retrieveWebhook.ID, webhook.ID)

resources := map[string][]uint{}
resources[common.ResourceCluster] = []uint{0}
_, count, err := mgr.ListWebhookOfResources(ctx, resources, q.New(q.KeyWords{

Check failure on line 58 in pkg/webhook/manager/manager_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ineffectual assignment to err (ineffassign)

Check failure on line 58 in pkg/webhook/manager/manager_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ineffectual assignment to err (ineffassign)
common.Enabled: true,
}))
assert.Equal(t, int64(1), count)

retrieveWebhooks, err := mgr.ListWebhooks(ctx)

Check failure on line 63 in pkg/webhook/manager/manager_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ineffectual assignment to err (ineffassign)

Check failure on line 63 in pkg/webhook/manager/manager_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ineffectual assignment to err (ineffassign)
assert.Equal(t, 1, len(retrieveWebhooks))

webhook.URL = "https://horizon.com"
retrieveWebhook, err = mgr.UpdateWebhook(ctx, webhook.ID, webhook)

Check failure on line 67 in pkg/webhook/manager/manager_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ineffectual assignment to err (ineffassign)

Check failure on line 67 in pkg/webhook/manager/manager_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ineffectual assignment to err (ineffassign)
assert.Equal(t, retrieveWebhook.ID, webhook.ID)
assert.Equal(t, retrieveWebhook.URL, "https://horizon.com")

events := []*eventmodels.Event{
{
EventSummary: eventmodels.EventSummary{
Expand Down Expand Up @@ -119,6 +152,16 @@ func Test(t *testing.T) {
assert.Contains(t, []uint{1, 2}, log.ID)
}

_, err = mgr.ResendWebhook(ctx, 1)
assert.Nil(t, err)

_, err = mgr.GetMaxEventIDOfLog(ctx)
assert.Nil(t, err)

retrievedLogs, err := mgr.GetWebhookLogByEventID(ctx, 1, 1)
assert.Nil(t, err)
assert.Equal(t, uint(1), retrievedLogs.ID)

for _, log := range webhookLogs {
_, err = mgr.DeleteWebhookLogs(ctx, log.ID)
assert.Nil(t, err)
Expand Down

0 comments on commit 0f6afed

Please sign in to comment.