本文整理匯總了Golang中github.com/gophercloud/gophercloud/testhelper.TeardownHTTP函數的典型用法代碼示例。如果您正苦於以下問題:Golang TeardownHTTP函數的具體用法?Golang TeardownHTTP怎麽用?Golang TeardownHTTP使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了TeardownHTTP函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestList
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleListExtensionsSuccessfully(t)
count := 0
extensions.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := extensions.ExtractExtensions(page)
th.AssertNoErr(t, err)
expected := []common.Extension{
common.Extension{
Updated: "2013-01-20T00:00:00-00:00",
Name: "Neutron Service Type Management",
Links: []interface{}{},
Namespace: "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
Alias: "service-type",
Description: "API for retrieving service providers for Neutron advanced services",
},
}
th.AssertDeepEquals(t, expected, actual)
return true, nil
})
th.CheckEquals(t, 1, count)
}
示例2: TestListMembers
func TestListMembers(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleMemberListSuccessfully(t)
pages := 0
err := pools.ListMembers(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.ListMembersOpts{}).EachPage(func(page pagination.Page) (bool, error) {
pages++
actual, err := pools.ExtractMembers(page)
if err != nil {
return false, err
}
if len(actual) != 2 {
t.Fatalf("Expected 2 members, got %d", len(actual))
}
th.CheckDeepEquals(t, MemberWeb, actual[0])
th.CheckDeepEquals(t, MemberDb, actual[1])
return true, nil
})
th.AssertNoErr(t, err)
if pages != 1 {
t.Errorf("Expected 1 page, saw %d", pages)
}
}
示例3: tokenPost
func tokenPost(t *testing.T, options gophercloud.AuthOptions, requestJSON string) tokens.CreateResult {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleTokenPost(t, requestJSON)
return tokens.Create(client.ServiceClient(), options)
}
示例4: TestGet
// Verifies that it is possible to get a share network
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockGetResponse(t)
var nilTime time.Time
expected := sharenetworks.ShareNetwork{
ID: "7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd",
Name: "net_my1",
CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 56, 45, 0, time.UTC)),
Description: "descr",
NetworkType: "",
CIDR: "",
NovaNetID: "",
NeutronNetID: "998b42ee-2cee-4d36-8b95-67b5ca1f2109",
NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06",
IPVersion: 0,
SegmentationID: 0,
UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime),
ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
}
n, err := sharenetworks.Get(client.ServiceClient(), "7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd").Extract()
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, &expected, n)
}
示例5: TestListImage
func TestListImage(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleImageListSuccessfully(t)
t.Logf("Test setup %+v\n", th.Server)
t.Logf("Id\tName\tOwner\tChecksum\tSizeBytes")
pager := images.List(fakeclient.ServiceClient(), images.ListOpts{Limit: 1})
t.Logf("Pager state %v", pager)
count, pages := 0, 0
err := pager.EachPage(func(page pagination.Page) (bool, error) {
pages++
t.Logf("Page %v", page)
images, err := images.ExtractImages(page)
if err != nil {
return false, err
}
for _, i := range images {
t.Logf("%s\t%s\t%s\t%s\t%v\t\n", i.ID, i.Name, i.Owner, i.Checksum, i.SizeBytes)
count++
}
return true, nil
})
th.AssertNoErr(t, err)
t.Logf("--------\n%d images listed on %d pages.\n", count, pages)
th.AssertEquals(t, 3, pages)
th.AssertEquals(t, 3, count)
}
示例6: TestGetHomeDocument
func TestGetHomeDocument(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleGetSuccessfully(t)
actual, err := base.Get(fake.ServiceClient()).Extract()
th.CheckNoErr(t, err)
expected := base.HomeDocument{
"rel/cdn": map[string]interface{}{
"href-template": "services{?marker,limit}",
"href-vars": map[string]interface{}{
"marker": "param/marker",
"limit": "param/limit",
},
"hints": map[string]interface{}{
"allow": []string{"GET"},
"formats": map[string]interface{}{
"application/json": map[string]interface{}{},
},
},
},
}
th.CheckDeepEquals(t, expected, *actual)
}
示例7: TestList
// Verifies that share types can be listed correctly
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockListResponse(t)
allPages, err := sharetypes.List(client.ServiceClient(), &sharetypes.ListOpts{}).AllPages()
th.AssertNoErr(t, err)
actual, err := sharetypes.ExtractShareTypes(allPages)
th.AssertNoErr(t, err)
expected := []sharetypes.ShareType{
{
ID: "be27425c-f807-4500-a056-d00721db45cf",
Name: "default",
IsPublic: true,
ExtraSpecs: map[string]interface{}{"snapshot_support": "True", "driver_handles_share_servers": "True"},
RequiredExtraSpecs: map[string]interface{}{"driver_handles_share_servers": "True"},
},
{
ID: "f015bebe-c38b-4c49-8832-00143b10253b",
Name: "d",
IsPublic: true,
ExtraSpecs: map[string]interface{}{"driver_handles_share_servers": "false", "snapshot_support": "True"},
RequiredExtraSpecs: map[string]interface{}{"driver_handles_share_servers": "True"},
},
}
th.CheckDeepEquals(t, expected, actual)
}
示例8: TestMemberUpdateSuccessfully
func TestMemberUpdateSuccessfully(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
counter := HandleImageMemberUpdate(t)
im, err := members.Update(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
"8989447062e04a818baf9e073fd04fa7",
members.UpdateOpts{
Status: "accepted",
}).Extract()
th.AssertEquals(t, 1, counter.Counter)
th.AssertNoErr(t, err)
createdAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z")
th.AssertNoErr(t, err)
updatedAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z")
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, members.Member{
CreatedAt: createdAt,
ImageID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
MemberID: "8989447062e04a818baf9e073fd04fa7",
Schema: "/v2/schemas/member",
Status: "accepted",
UpdatedAt: updatedAt,
}, *im)
}
示例9: TestCreateMemberSuccessfully
func TestCreateMemberSuccessfully(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleCreateImageMemberSuccessfully(t)
im, err := members.Create(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
"8989447062e04a818baf9e073fd04fa7").Extract()
th.AssertNoErr(t, err)
createdAt, err := time.Parse(time.RFC3339, createdAtString)
th.AssertNoErr(t, err)
updatedAt, err := time.Parse(time.RFC3339, updatedAtString)
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, members.Member{
CreatedAt: createdAt,
ImageID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
MemberID: "8989447062e04a818baf9e073fd04fa7",
Schema: "/v2/schemas/member",
Status: "pending",
UpdatedAt: updatedAt,
}, *im)
}
示例10: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/networks/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"network": {
"admin_state_up": true,
"id": "8d05a1b1-297a-46ca-8974-17debf51ca3c",
"name": "ext_net",
"router:external": true,
"shared": false,
"status": "ACTIVE",
"subnets": [
"2f1fb918-9b0e-4bf9-9a50-6cebbb4db2c5"
],
"tenant_id": "5eb8995cf717462c9df8d1edfa498010"
}
}
`)
})
res := networks.Get(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
n, err := external.ExtractGet(res)
th.AssertNoErr(t, err)
th.AssertEquals(t, true, n.External)
}
示例11: TestShowMemberDetails
func TestShowMemberDetails(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleImageMemberDetails(t)
md, err := members.Get(fakeclient.ServiceClient(),
"da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
"8989447062e04a818baf9e073fd04fa7").Extract()
th.AssertNoErr(t, err)
if md == nil {
t.Errorf("Expected non-nil value for md")
}
createdAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z")
th.AssertNoErr(t, err)
updatedAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z")
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, members.Member{
CreatedAt: createdAt,
ImageID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
MemberID: "8989447062e04a818baf9e073fd04fa7",
Schema: "/v2/schemas/member",
Status: "pending",
UpdatedAt: updatedAt,
}, *md)
}
示例12: TestListServers
func TestListServers(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleServerListSuccessfully(t)
pages := 0
err := servers.List(client.ServiceClient(), servers.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
pages++
actual, err := servers.ExtractServers(page)
if err != nil {
return false, err
}
if len(actual) != 3 {
t.Fatalf("Expected 3 servers, got %d", len(actual))
}
th.CheckDeepEquals(t, ServerHerp, actual[0])
th.CheckDeepEquals(t, ServerDerp, actual[1])
th.CheckDeepEquals(t, ServerMerp, actual[2])
return true, nil
})
th.AssertNoErr(t, err)
if pages != 1 {
t.Errorf("Expected 1 page, saw %d", pages)
}
}
示例13: TestFetch
// test the fetch function
func TestFetch(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
baseurl, err := getBasePath()
th.AssertNoErr(t, err)
fakeURL := strings.Join([]string{baseurl, "file.yaml"}, "/")
urlparsed, err := url.Parse(fakeURL)
th.AssertNoErr(t, err)
th.Mux.HandleFunc(urlparsed.Path, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
w.Header().Set("Content-Type", "application/jason")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Fee-fi-fo-fum")
})
client := fakeClient{BaseClient: getHTTPClient()}
te := TE{
URL: "file.yaml",
client: client,
}
err = te.Fetch()
th.AssertNoErr(t, err)
th.AssertEquals(t, fakeURL, te.URL)
th.AssertEquals(t, "Fee-fi-fo-fum", string(te.Bin))
}
示例14: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/extensions/agent", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"extension": {
"updated": "2013-02-03T10:00:00-00:00",
"name": "agent",
"links": [],
"namespace": "http://docs.openstack.org/ext/agent/api/v2.0",
"alias": "agent",
"description": "The agent management extension."
}
}
`)
})
ext, err := extensions.Get(fake.ServiceClient(), "agent").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, ext.Updated, "2013-02-03T10:00:00-00:00")
th.AssertEquals(t, ext.Name, "agent")
th.AssertEquals(t, ext.Namespace, "http://docs.openstack.org/ext/agent/api/v2.0")
th.AssertEquals(t, ext.Alias, "agent")
th.AssertEquals(t, ext.Description, "The agent management extension.")
}
示例15: TestListFlavors
func TestListFlavors(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleList(t)
pages := 0
err := flavors.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
pages++
actual, err := flavors.ExtractFlavors(page)
if err != nil {
return false, err
}
expected := []flavors.Flavor{
{
ID: 1,
Name: "m1.tiny",
RAM: 512,
Links: []gophercloud.Link{
{Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
{Href: "https://openstack.example.com/flavors/1", Rel: "bookmark"},
},
},
{
ID: 2,
Name: "m1.small",
RAM: 1024,
Links: []gophercloud.Link{
{Href: "https://openstack.example.com/v1.0/1234/flavors/2", Rel: "self"},
{Href: "https://openstack.example.com/flavors/2", Rel: "bookmark"},
},
},
{
ID: 3,
Name: "m1.medium",
RAM: 2048,
Links: []gophercloud.Link{
{Href: "https://openstack.example.com/v1.0/1234/flavors/3", Rel: "self"},
{Href: "https://openstack.example.com/flavors/3", Rel: "bookmark"},
},
},
{
ID: 4,
Name: "m1.large",
RAM: 4096,
Links: []gophercloud.Link{
{Href: "https://openstack.example.com/v1.0/1234/flavors/4", Rel: "self"},
{Href: "https://openstack.example.com/flavors/4", Rel: "bookmark"},
},
},
}
th.AssertDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, pages)
}