本文整理汇总了Golang中github.com/rackspace/gophercloud/testhelper.AssertNoErr函数的典型用法代码示例。如果您正苦于以下问题:Golang AssertNoErr函数的具体用法?Golang AssertNoErr怎么用?Golang AssertNoErr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AssertNoErr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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")
}
示例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)
}
示例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.")
}
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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.")
}
}
示例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
}
示例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)
}
示例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)
}
示例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
}
示例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)
}