本文整理汇总了Golang中github.com/rackspace/gophercloud/testhelper.AssertNoErr函数的典型用法代码示例。如果您正苦于以下问题:Golang AssertNoErr函数的具体用法?Golang AssertNoErr怎么用?Golang AssertNoErr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AssertNoErr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestList
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockListResponse(t, lbID)
count := 0
err := List(client.ServiceClient(), lbID).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractAccessList(page)
th.AssertNoErr(t, err)
expected := AccessList{
NetworkItem{Address: "206.160.163.21", ID: 21, Type: DENY},
NetworkItem{Address: "206.160.163.22", ID: 22, Type: DENY},
NetworkItem{Address: "206.160.163.23", ID: 23, Type: DENY},
NetworkItem{Address: "206.160.163.24", ID: 24, Type: DENY},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, count)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:28,代码来源:requests_test.go
示例2: TestAccounts
func TestAccounts(t *testing.T) {
c, err := createClient(t, false)
th.AssertNoErr(t, err)
updateHeaders, err := raxAccounts.Update(c, raxAccounts.UpdateOpts{Metadata: map[string]string{"white": "mountains"}}).Extract()
th.AssertNoErr(t, err)
t.Logf("Update Account Response Headers: %+v\n", updateHeaders)
defer func() {
updateres := raxAccounts.Update(c, raxAccounts.UpdateOpts{Metadata: map[string]string{"white": ""}})
th.AssertNoErr(t, updateres.Err)
metadata, err := raxAccounts.Get(c).ExtractMetadata()
th.AssertNoErr(t, err)
t.Logf("Metadata from Get Account request (after update reverted): %+v\n", metadata)
th.CheckEquals(t, metadata["White"], "")
}()
getResp := raxAccounts.Get(c)
th.AssertNoErr(t, getResp.Err)
getHeaders, _ := getResp.Extract()
t.Logf("Get Account Response Headers: %+v\n", getHeaders)
metadata, _ := getResp.ExtractMetadata()
t.Logf("Metadata from Get Account request (after update): %+v\n", metadata)
th.CheckEquals(t, metadata["White"], "mountains")
}
开发者ID:RomainVabre,项目名称:origin,代码行数:27,代码来源:accounts_test.go
示例3: TestMemberUpdateSuccessfully
func TestMemberUpdateSuccessfully(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
counter := HandleImageMemberUpdate(t)
im, err := Update(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
"8989447062e04a818baf9e073fd04fa7",
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, ImageMember{
CreatedAt: createdAt,
ImageID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
MemberID: "8989447062e04a818baf9e073fd04fa7",
Schema: "/v2/schemas/member",
Status: "accepted",
UpdatedAt: updatedAt,
}, *im)
}
开发者ID:rackspace,项目名称:gophercloud,代码行数:29,代码来源:requests_test.go
示例4: TestTenants
func TestTenants(t *testing.T) {
service := authenticatedClient(t)
t.Logf("Tenants available to the currently issued token:")
count := 0
err := rstenants.List(service, nil).EachPage(func(page pagination.Page) (bool, error) {
t.Logf("--- Page %02d ---", count)
tenants, err := rstenants.ExtractTenants(page)
th.AssertNoErr(t, err)
for i, tenant := range tenants {
t.Logf("[%02d] id=[%s]", i, tenant.ID)
t.Logf(" name=[%s] enabled=[%v]", i, tenant.Name, tenant.Enabled)
t.Logf(" description=[%s]", tenant.Description)
}
count++
return true, nil
})
th.AssertNoErr(t, err)
if count == 0 {
t.Errorf("No tenants listed for your current token.")
}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:25,代码来源:tenant_test.go
示例5: TestCreateMemberSuccessfully
func TestCreateMemberSuccessfully(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleCreateImageMemberSuccessfully(t)
im, err := 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, ImageMember{
CreatedAt: createdAt,
ImageID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
MemberID: "8989447062e04a818baf9e073fd04fa7",
Schema: "/v2/schemas/member",
Status: "pending",
UpdatedAt: updatedAt,
}, *im)
}
开发者ID:rackspace,项目名称:gophercloud,代码行数:25,代码来源:requests_test.go
示例6: TestListAlgorithms
func TestListAlgorithms(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockListAlgorithmsResponse(t)
count := 0
err := ListAlgorithms(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractAlgorithms(page)
th.AssertNoErr(t, err)
expected := []Algorithm{
Algorithm{Name: "LEAST_CONNECTIONS"},
Algorithm{Name: "RANDOM"},
Algorithm{Name: "ROUND_ROBIN"},
Algorithm{Name: "WEIGHTED_LEAST_CONNECTIONS"},
Algorithm{Name: "WEIGHTED_ROUND_ROBIN"},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, count)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:29,代码来源:requests_test.go
示例7: TestListImageDetails
func TestListImageDetails(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/images/detail", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
r.ParseForm()
marker := r.Form.Get("marker")
switch marker {
case "":
fmt.Fprintf(w, ListOutput)
case "e19a734c-c7e6-443a-830c-242209c4d65d":
fmt.Fprintf(w, `{ "images": [] }`)
default:
t.Fatalf("Unexpected marker: [%s]", marker)
}
})
count := 0
err := ListDetail(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractImages(page)
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, ExpectedImageSlice, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.CheckEquals(t, 1, count)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:33,代码来源:delegate_test.go
示例8: TestListCerts
func TestListCerts(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockListCertsResponse(t, lbID)
count := 0
err := ListCerts(client.ServiceClient(), lbID).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractCerts(page)
th.AssertNoErr(t, err)
expected := []Certificate{
Certificate{ID: 123, HostName: "rackspace.com"},
Certificate{ID: 124, HostName: "*.rackspace.com"},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, count)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:26,代码来源:requests_test.go
示例9: TestList
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockListRulesResponse(t)
count := 0
err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractDefaultRules(page)
th.AssertNoErr(t, err)
expected := []DefaultRule{
DefaultRule{
FromPort: 80,
ID: ruleID,
IPProtocol: "TCP",
IPRange: secgroups.IPRange{CIDR: "10.10.10.0/24"},
ToPort: 80,
},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, count)
}
开发者ID:nerfmiester,项目名称:gophercloud,代码行数:31,代码来源:requests_test.go
示例10: TestListImages
func TestListImages(t *testing.T) {
client, err := newClient()
th.AssertNoErr(t, err)
count := 0
err = images.ListDetail(client, nil).EachPage(func(page pagination.Page) (bool, error) {
count++
t.Logf("-- Page %02d --", count)
is, err := images.ExtractImages(page)
th.AssertNoErr(t, err)
for i, image := range is {
t.Logf("[%02d] id=[%s]", i, image.ID)
t.Logf(" name=[%s]", image.Name)
t.Logf(" created=[%s]", image.Created)
t.Logf(" updated=[%s]", image.Updated)
t.Logf(" min disk=[%d]", image.MinDisk)
t.Logf(" min RAM=[%d]", image.MinRAM)
t.Logf(" progress=[%d]", image.Progress)
t.Logf(" status=[%s]", image.Status)
}
return true, nil
})
th.AssertNoErr(t, err)
if count < 1 {
t.Errorf("Expected at least one page of images.")
}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:30,代码来源:images_test.go
示例11: createTestImage
func createTestImage(t *testing.T, client *gophercloud.ServiceClient) images.Image {
//creating image
imageName := tools.RandomString("ACCPT", 16)
containerFormat := "ami"
createResult := images.Create(client, images.CreateOpts{Name: imageName,
ContainerFormat: containerFormat,
DiskFormat: containerFormat})
th.AssertNoErr(t, createResult.Err)
image, err := createResult.Extract()
th.AssertNoErr(t, err)
t.Logf("Image %v", image)
//checking status
image, err = images.Get(client, image.ID).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, image.Status, images.ImageStatusQueued)
//uploading image data
data := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}
uploadResult := images.Upload(client, image.ID, bytes.NewReader(data))
th.AssertNoErr(t, uploadResult.Err)
//checking status
image, err = images.Get(client, image.ID).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, image.Status, images.ImageStatusActive)
th.AssertEquals(t, image.SizeBytes, 9)
return *image
}
开发者ID:rackspace,项目名称:gophercloud,代码行数:29,代码来源:common.go
示例12: TestListBackups
func TestListBackups(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
fixture.SetupHandler(t, resURL+"/backups", "GET", "", listBackupsResp, 200)
pages := 0
err := ListBackups(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
pages++
actual, err := backups.ExtractBackups(page)
th.AssertNoErr(t, err)
expected := []backups.Backup{
backups.Backup{
Created: timeVal,
Description: "Backup from Restored Instance",
ID: "87972694-4be2-40f5-83f8-501656e0032a",
InstanceID: "29af2cd9-0674-48ab-b87a-b160f00208e6",
LocationRef: "http://localhost/path/to/backup",
Name: "restored_backup",
ParentID: "",
Size: 0.141026,
Status: "COMPLETED",
Updated: timeVal,
Datastore: datastores.DatastorePartial{Version: "5.1", Type: "MySQL", VersionID: "20000000-0000-0000-0000-000000000002"},
},
}
th.AssertDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, pages)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:35,代码来源:requests_test.go
示例13: TestMultiEphemeral
func TestMultiEphemeral(t *testing.T) {
client, err := newClient()
th.AssertNoErr(t, err)
if testing.Short() {
t.Skip("Skipping test that requires server creation in short mode.")
}
choices, err := ComputeChoicesFromEnv()
if err != nil {
t.Fatal(err)
}
name := tools.RandomString("Gophercloud-", 8)
t.Logf("Creating server [%s].", name)
bd := []bootfromvolume.BlockDevice{
bootfromvolume.BlockDevice{
BootIndex: 0,
UUID: choices.ImageID,
SourceType: bootfromvolume.Image,
DestinationType: "local",
DeleteOnTermination: true,
},
bootfromvolume.BlockDevice{
BootIndex: -1,
SourceType: bootfromvolume.Blank,
DestinationType: "local",
DeleteOnTermination: true,
GuestFormat: "ext4",
VolumeSize: 1,
},
bootfromvolume.BlockDevice{
BootIndex: -1,
SourceType: bootfromvolume.Blank,
DestinationType: "local",
DeleteOnTermination: true,
GuestFormat: "ext4",
VolumeSize: 1,
},
}
serverCreateOpts := servers.CreateOpts{
Name: name,
FlavorRef: choices.FlavorID,
ImageRef: choices.ImageID,
}
server, err := bootfromvolume.Create(client, bootfromvolume.CreateOptsExt{
serverCreateOpts,
bd,
}).Extract()
th.AssertNoErr(t, err)
if err = waitForStatus(client, server, "ACTIVE"); err != nil {
t.Fatal(err)
}
t.Logf("Created server: %+v\n", server)
defer servers.Delete(client, server.ID)
t.Logf("Deleting server [%s]...", name)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:60,代码来源:bootfromvolume_test.go
示例14: newClient
func newClient(t *testing.T) *gophercloud.ServiceClient {
authURL := os.Getenv("OS_AUTH_URL")
username := os.Getenv("OS_USERNAME")
password := os.Getenv("OS_PASSWORD")
tenantName := os.Getenv("OS_TENANT_NAME")
tenantID := os.Getenv("OS_TENANT_ID")
domainName := os.Getenv("OS_DOMAIN_NAME")
regionName := os.Getenv("OS_REGION_NAME")
t.Logf("Credentials used: OS_AUTH_URL='%s' OS_USERNAME='%s' OS_PASSWORD='*****' OS_TENANT_NAME='%s' OS_TENANT_NAME='%s' OS_REGION_NAME='%s' OS_TENANT_ID='%s' \n",
authURL, username, tenantName, domainName, regionName, tenantID)
client, err := openstack.NewClient(authURL)
th.AssertNoErr(t, err)
ao := gophercloud.AuthOptions{
Username: username,
Password: password,
TenantName: tenantName,
TenantID: tenantID,
DomainName: domainName,
}
err = openstack.AuthenticateV3(client, ao)
th.AssertNoErr(t, err)
t.Logf("Token is %v", client.TokenID)
c, err := openstack.NewImageServiceV2(client, gophercloud.EndpointOpts{
Region: regionName,
})
th.AssertNoErr(t, err)
return c
}
开发者ID:rackspace,项目名称:gophercloud,代码行数:34,代码来源:common.go
示例15: TestList
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockListResponse(t, lbID)
count := 0
err := List(client.ServiceClient(), lbID).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractVIPs(page)
th.AssertNoErr(t, err)
expected := []VIP{
VIP{ID: 1000, Address: "206.10.10.210", Type: "PUBLIC"},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, count)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:25,代码来源:requests_test.go
示例16: TestListAll
func TestListAll(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockListResponse(t)
allPages, err := List(client.ServiceClient(), &ListOpts{}).AllPages()
th.AssertNoErr(t, err)
actual, err := ExtractVolumes(allPages)
th.AssertNoErr(t, err)
expected := []Volume{
Volume{
ID: "289da7f8-6440-407c-9fb4-7db01ec49164",
Name: "vol-001",
},
Volume{
ID: "96c3bda7-c82a-4f50-be73-ca7621794835",
Name: "vol-002",
},
}
th.CheckDeepEquals(t, expected, actual)
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:25,代码来源:requests_test.go
示例17: TestListProtocols
func TestListProtocols(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockListProtocolsResponse(t)
count := 0
err := ListProtocols(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractProtocols(page)
th.AssertNoErr(t, err)
expected := []Protocol{
Protocol{Name: "DNS_TCP", Port: 53},
Protocol{Name: "DNS_UDP", Port: 53},
Protocol{Name: "FTP", Port: 21},
Protocol{Name: "HTTP", Port: 80},
Protocol{Name: "HTTPS", Port: 443},
Protocol{Name: "IMAPS", Port: 993},
Protocol{Name: "IMAPv4", Port: 143},
}
th.CheckDeepEquals(t, expected[0:7], actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, count)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:31,代码来源:requests_test.go
示例18: TestAccounts
func TestAccounts(t *testing.T) {
// Create a provider client for making the HTTP requests.
// See common.go in this directory for more information.
client := newClient(t)
// Update an account's metadata.
updateres := accounts.Update(client, accounts.UpdateOpts{Metadata: metadata})
th.AssertNoErr(t, updateres.Err)
// Defer the deletion of the metadata set above.
defer func() {
tempMap := make(map[string]string)
for k := range metadata {
tempMap[k] = ""
}
updateres = accounts.Update(client, accounts.UpdateOpts{Metadata: tempMap})
th.AssertNoErr(t, updateres.Err)
}()
// Retrieve account metadata.
getres := accounts.Get(client, nil)
th.AssertNoErr(t, getres.Err)
// Extract the custom metadata from the 'Get' response.
am, err := getres.ExtractMetadata()
th.AssertNoErr(t, err)
for k := range metadata {
if am[k] != metadata[strings.Title(k)] {
t.Errorf("Expected custom metadata with key: %s", k)
return
}
}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:32,代码来源:accounts_test.go
示例19: TestListingUserRoles
func TestListingUserRoles(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockListRolesResponse(t)
tenantID := "1d8b6120dcc640fda4fc9194ffc80273"
userID := "c39e3de9be2d4c779f1dfd6abacc176d"
err := ListRoles(client.ServiceClient(), tenantID, userID).EachPage(func(page pagination.Page) (bool, error) {
actual, err := ExtractRoles(page)
th.AssertNoErr(t, err)
expected := []Role{
Role{ID: "9fe2ff9ee4384b1894a90878d3e92bab", Name: "foo_role"},
Role{ID: "1ea3d56793574b668e85960fbf651e13", Name: "admin"},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:25,代码来源:requests_test.go
示例20: TestAuthenticate
func TestAuthenticate(t *testing.T) {
ao := v2AuthOptions(t)
service := unauthenticatedClient(t)
// Authenticated!
result := tokens2.Create(service, tokens2.WrapOptions(ao))
// Extract and print the token.
token, err := result.ExtractToken()
th.AssertNoErr(t, err)
t.Logf("Acquired token: [%s]", token.ID)
t.Logf("The token will expire at: [%s]", token.ExpiresAt.String())
t.Logf("The token is valid for tenant: [%#v]", token.Tenant)
// Extract and print the service catalog.
catalog, err := result.ExtractServiceCatalog()
th.AssertNoErr(t, err)
t.Logf("Acquired service catalog listing [%d] services", len(catalog.Entries))
for i, entry := range catalog.Entries {
t.Logf("[%02d]: name=[%s], type=[%s]", i, entry.Name, entry.Type)
for _, endpoint := range entry.Endpoints {
t.Logf(" - region=[%s] publicURL=[%s]", endpoint.Region, endpoint.PublicURL)
}
}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:27,代码来源:token_test.go
注:本文中的github.com/rackspace/gophercloud/testhelper.AssertNoErr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论