本文整理汇总了Golang中github.com/gophercloud/gophercloud/testhelper.TeardownHTTP函数的典型用法代码示例。如果您正苦于以下问题:Golang TeardownHTTP函数的具体用法?Golang TeardownHTTP怎么用?Golang TeardownHTTP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TeardownHTTP函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:28,代码来源:delegate_test.go
示例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)
}
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:requests_test.go
示例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)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:7,代码来源:requests_test.go
示例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)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:requests_test.go
示例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)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:34,代码来源:requests_test.go
示例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)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:25,代码来源:requests_test.go
示例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)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:30,代码来源:requests_test.go
示例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)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:requests_test.go
示例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)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:25,代码来源:requests_test.go
示例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)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:35,代码来源:results_test.go
示例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)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:requests_test.go
示例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)
}
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:30,代码来源:requests_test.go
示例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))
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:27,代码来源:utils_test.go
示例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.")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:34,代码来源:delegate_test.go
示例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)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:60,代码来源:requests_test.go
示例16: TestMemberListEmpty
func TestMemberListEmpty(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleImageMemberEmptyList(t)
pager := members.List(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea")
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)
members, err := members.ExtractMembers(page)
if err != nil {
return false, err
}
for _, i := range members {
t.Logf("%s\t%s\t%s\t%s\t\n", i.ImageID, i.MemberID, i.Status, i.Schema)
count++
}
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 0, pages)
th.AssertEquals(t, 0, count)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:requests_test.go
示例17: TestList
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleList(t)
expectedDBs := []databases.Database{
{Name: "anotherexampledb"},
{Name: "exampledb"},
{Name: "nextround"},
{Name: "sampledb"},
{Name: "testingdb"},
}
pages := 0
err := databases.List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
pages++
actual, err := databases.ExtractDBs(page)
if err != nil {
return false, err
}
th.CheckDeepEquals(t, expectedDBs, actual)
return true, nil
})
th.AssertNoErr(t, err)
if pages != 1 {
t.Errorf("Expected 1 page, saw %d", pages)
}
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:33,代码来源:requests_test.go
示例18: TestAssociateHealthMonitor
func TestAssociateHealthMonitor(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/lb/pools/332abe93-f488-41ba-870b-2ac66be7f853/health_monitors", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestHeader(t, r, "Content-Type", "application/json")
th.TestHeader(t, r, "Accept", "application/json")
th.TestJSONRequest(t, r, `
{
"health_monitor":{
"id":"b624decf-d5d3-4c66-9a3d-f047e7786181"
}
}
`)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `{}`)
})
_, err := pools.AssociateMonitor(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "b624decf-d5d3-4c66-9a3d-f047e7786181").Extract()
th.AssertNoErr(t, err)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:25,代码来源:requests_test.go
示例19: TestListAll
func TestListAll(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockListResponse(t)
allPages, err := volumes.List(client.ServiceClient(), &volumes.ListOpts{}).AllPages()
th.AssertNoErr(t, err)
actual, err := volumes.ExtractVolumes(allPages)
th.AssertNoErr(t, err)
expected := []volumes.Volume{
{
ID: "289da7f8-6440-407c-9fb4-7db01ec49164",
Name: "vol-001",
},
{
ID: "96c3bda7-c82a-4f50-be73-ca7621794835",
Name: "vol-002",
},
}
th.CheckDeepEquals(t, expected, actual)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:25,代码来源:requests_test.go
示例20: TestCreate
// Verifies that a security service can be created correctly
func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockCreateResponse(t)
options := &securityservices.CreateOpts{
Name: "SecServ1",
Description: "Creating my first Security Service",
DNSIP: "10.0.0.0/24",
User: "demo",
Password: "***",
Type: "kerberos",
}
s, err := securityservices.Create(client.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.Name, "SecServ1")
th.AssertEquals(t, s.Description, "Creating my first Security Service")
th.AssertEquals(t, s.User, "demo")
th.AssertEquals(t, s.DNSIP, "10.0.0.0/24")
th.AssertEquals(t, s.Password, "supersecret")
th.AssertEquals(t, s.Type, "kerberos")
}
开发者ID:gophercloud,项目名称:gophercloud,代码行数:26,代码来源:requests_test.go
注:本文中的github.com/gophercloud/gophercloud/testhelper.TeardownHTTP函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论