blob: 8c17aa2c261198f21a9e2e33c99a17c374aacf6b [file] [log] [blame]
Brad Ison366a7a02016-03-27 17:06:21 -04001package webhooks
2
3import (
4 "testing"
5
6 "github.com/rackspace/gophercloud/pagination"
7 th "github.com/rackspace/gophercloud/testhelper"
8 "github.com/rackspace/gophercloud/testhelper/client"
9)
10
Brad Isone6e0ec12016-03-27 21:26:46 -040011const (
12 groupID = "10eb3219-1b12-4b34-b1e4-e10ee4f24c65"
13 policyID = "2b48d247-0282-4b9d-8775-5c4b67e8e649"
14)
15
Brad Ison366a7a02016-03-27 17:06:21 -040016func TestList(t *testing.T) {
17 th.SetupHTTP()
18 defer th.TeardownHTTP()
19 HandleWebhookListSuccessfully(t)
20
Brad Ison366a7a02016-03-27 17:06:21 -040021 pages := 0
22 pager := List(client.ServiceClient(), groupID, policyID)
23
24 err := pager.EachPage(func(page pagination.Page) (bool, error) {
25 pages++
26
27 webhooks, err := ExtractWebhooks(page)
28
29 if err != nil {
30 return false, err
31 }
32
33 if len(webhooks) != 2 {
34 t.Fatalf("Expected 2 policies, got %d", len(webhooks))
35 }
36
37 th.CheckDeepEquals(t, FirstWebhook, webhooks[0])
38 th.CheckDeepEquals(t, SecondWebhook, webhooks[1])
39
40 return true, nil
41 })
42
43 th.AssertNoErr(t, err)
44
45 if pages != 1 {
46 t.Errorf("Expected 1 page, saw %d", pages)
47 }
48}
Brad Isone6e0ec12016-03-27 21:26:46 -040049
50func TestCreate(t *testing.T) {
51 th.SetupHTTP()
52 defer th.TeardownHTTP()
53 HandleWebhookCreateSuccessfully(t)
54
55 client := client.ServiceClient()
56 opts := CreateOpts{
57 {
58 Name: "first hook",
59 },
60 {
61 Name: "second hook",
62 Metadata: map[string]string{
63 "notes": "a note about this webhook",
64 },
65 },
66 }
67
68 webhooks, err := Create(client, groupID, policyID, opts).ExtractWebhooks()
69
70 th.AssertNoErr(t, err)
71 th.CheckDeepEquals(t, FirstWebhook, webhooks[0])
72 th.CheckDeepEquals(t, SecondWebhook, webhooks[1])
73}