Пример #1
0
func testServiceList(t *testing.T, client *gophercloud.ServiceClient) {
	err := services.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
		serviceList, err := os.ExtractServices(page)
		th.AssertNoErr(t, err)

		for _, service := range serviceList {
			t.Logf("Listing service: %+v", service)
		}

		return true, nil
	})

	th.AssertNoErr(t, err)
}
Пример #2
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	os.HandleListCDNServiceSuccessfully(t)

	count := 0

	err := List(fake.ServiceClient(), &os.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := os.ExtractServices(page)
		if err != nil {
			t.Errorf("Failed to extract services: %v", err)
			return false, err
		}

		expected := []os.Service{
			os.Service{
				ID:   "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0",
				Name: "mywebsite.com",
				Domains: []os.Domain{
					os.Domain{
						Domain: "www.mywebsite.com",
					},
				},
				Origins: []os.Origin{
					os.Origin{
						Origin: "mywebsite.com",
						Port:   80,
						SSL:    false,
					},
				},
				Caching: []os.CacheRule{
					os.CacheRule{
						Name: "default",
						TTL:  3600,
					},
					os.CacheRule{
						Name: "home",
						TTL:  17200,
						Rules: []os.TTLRule{
							os.TTLRule{
								Name:       "index",
								RequestURL: "/index.htm",
							},
						},
					},
					os.CacheRule{
						Name: "images",
						TTL:  12800,
						Rules: []os.TTLRule{
							os.TTLRule{
								Name:       "images",
								RequestURL: "*.png",
							},
						},
					},
				},
				Restrictions: []os.Restriction{
					os.Restriction{
						Name: "website only",
						Rules: []os.RestrictionRule{
							os.RestrictionRule{
								Name:     "mywebsite.com",
								Referrer: "www.mywebsite.com",
							},
						},
					},
				},
				FlavorID: "asia",
				Status:   "deployed",
				Errors:   []os.Error{},
				Links: []gophercloud.Link{
					gophercloud.Link{
						Href: "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0",
						Rel:  "self",
					},
					gophercloud.Link{
						Href: "mywebsite.com.cdn123.poppycdn.net",
						Rel:  "access_url",
					},
					gophercloud.Link{
						Href: "https://www.poppycdn.io/v1.0/flavors/asia",
						Rel:  "flavor",
					},
				},
			},
			os.Service{
				ID:   "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1",
				Name: "myothersite.com",
				Domains: []os.Domain{
					os.Domain{
						Domain: "www.myothersite.com",
					},
				},
				Origins: []os.Origin{
					os.Origin{
						Origin: "44.33.22.11",
						Port:   80,
						SSL:    false,
					},
					os.Origin{
						Origin: "77.66.55.44",
						Port:   80,
						SSL:    false,
						Rules: []os.OriginRule{
							os.OriginRule{
								Name:       "videos",
								RequestURL: "^/videos/*.m3u",
							},
						},
					},
				},
				Caching: []os.CacheRule{
					os.CacheRule{
						Name: "default",
						TTL:  3600,
					},
				},
				Restrictions: []os.Restriction{},
				FlavorID:     "europe",
				Status:       "deployed",
				Links: []gophercloud.Link{
					gophercloud.Link{
						Href: "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1",
						Rel:  "self",
					},
					gophercloud.Link{
						Href: "myothersite.com.poppycdn.net",
						Rel:  "access_url",
					},
					gophercloud.Link{
						Href: "https://www.poppycdn.io/v1.0/flavors/europe",
						Rel:  "flavor",
					},
				},
			},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})
	th.AssertNoErr(t, err)

	if count != 1 {
		t.Errorf("Expected 1 page, got %d", count)
	}
}