本文整理匯總了Golang中github.com/gophercloud/gophercloud/testhelper.CheckEquals函數的典型用法代碼示例。如果您正苦於以下問題:Golang CheckEquals函數的具體用法?Golang CheckEquals怎麽用?Golang CheckEquals使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CheckEquals函數的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: TestV2EndpointNone
func TestV2EndpointNone(t *testing.T) {
_, actual := openstack.V2EndpointURL(&catalog2, gophercloud.EndpointOpts{
Type: "nope",
Availability: gophercloud.AvailabilityPublic,
})
expected := &gophercloud.ErrEndpointNotFound{}
th.CheckEquals(t, expected.Error(), actual.Error())
}
示例3: TestUserAgent
func TestUserAgent(t *testing.T) {
p := &gophercloud.ProviderClient{}
p.UserAgent.Prepend("custom-user-agent/2.4.0")
expected := "custom-user-agent/2.4.0 gophercloud/2.0.0"
actual := p.UserAgent.Join()
th.CheckEquals(t, expected, actual)
p.UserAgent.Prepend("another-custom-user-agent/0.3.0", "a-third-ua/5.9.0")
expected = "another-custom-user-agent/0.3.0 a-third-ua/5.9.0 custom-user-agent/2.4.0 gophercloud/2.0.0"
actual = p.UserAgent.Join()
th.CheckEquals(t, expected, actual)
p.UserAgent = gophercloud.UserAgent{}
expected = "gophercloud/2.0.0"
actual = p.UserAgent.Join()
th.CheckEquals(t, expected, actual)
}
示例4: TestV3EndpointBadAvailability
func TestV3EndpointBadAvailability(t *testing.T) {
_, err := openstack.V3EndpointURL(&catalog3, gophercloud.EndpointOpts{
Type: "same",
Name: "same",
Region: "same",
Availability: "wat",
})
th.CheckEquals(t, "Unexpected availability in endpoint query: wat", err.Error())
}
示例5: TestNormalizePathURL
func TestNormalizePathURL(t *testing.T) {
baseDir, _ := os.Getwd()
rawPath := "template.yaml"
basePath, _ := filepath.Abs(".")
result, _ := gophercloud.NormalizePathURL(basePath, rawPath)
expected := strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "template.yaml"}, "/")
th.CheckEquals(t, expected, result)
rawPath = "http://www.google.com"
basePath, _ = filepath.Abs(".")
result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
expected = "http://www.google.com"
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml"
basePath, _ = filepath.Abs(".")
result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "very/nested/file.yaml"}, "/")
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml"
basePath = "http://www.google.com"
result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
expected = "http://www.google.com/very/nested/file.yaml"
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml/"
basePath = "http://www.google.com/"
result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
expected = "http://www.google.com/very/nested/file.yaml"
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml"
basePath = "http://www.google.com/even/more"
result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
expected = "http://www.google.com/even/more/very/nested/file.yaml"
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml"
basePath = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more"}, "/")
result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more/very/nested/file.yaml"}, "/")
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml/"
basePath = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more"}, "/")
result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more/very/nested/file.yaml"}, "/")
th.CheckEquals(t, expected, result)
}
示例6: TestUpdate
func TestUpdate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockUpdateResponse(t)
options := volumes.UpdateOpts{Name: "vol-002"}
v, err := volumes.Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract()
th.AssertNoErr(t, err)
th.CheckEquals(t, "vol-002", v.Name)
}
示例7: TestDownloadReader
func TestDownloadReader(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleDownloadObjectSuccessfully(t)
response := objects.Download(fake.ServiceClient(), "testContainer", "testObject", nil)
defer response.Body.Close()
// Check reader
buf := bytes.NewBuffer(make([]byte, 0))
io.CopyN(buf, response.Body, 10)
th.CheckEquals(t, "Successful", string(buf.Bytes()))
}
示例8: TestNormalizeURL
func TestNormalizeURL(t *testing.T) {
urls := []string{
"NoSlashAtEnd",
"SlashAtEnd/",
}
expected := []string{
"NoSlashAtEnd/",
"SlashAtEnd/",
}
for i := 0; i < len(expected); i++ {
th.CheckEquals(t, expected[i], gophercloud.NormalizeURL(urls[i]))
}
}
示例9: TestNextPageURL
func TestNextPageURL(t *testing.T) {
var page images.ImagePage
var body map[string]interface{}
bodyString := []byte(`{"images":{"links":[{"href":"http://192.154.23.87/12345/images/image3","rel":"bookmark"}]}, "images_links":[{"href":"http://192.154.23.87/12345/images/image4","rel":"next"}]}`)
err := json.Unmarshal(bodyString, &body)
if err != nil {
t.Fatalf("Error unmarshaling data into page body: %v", err)
}
page.Body = body
expected := "http://192.154.23.87/12345/images/image4"
actual, err := page.NextPageURL()
th.AssertNoErr(t, err)
th.CheckEquals(t, expected, actual)
}
示例10: TestAuthenticatedClientV3
func TestAuthenticatedClientV3(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `
{
"versions": {
"values": [
{
"status": "stable",
"id": "v3.0",
"links": [
{ "href": "%s", "rel": "self" }
]
},
{
"status": "stable",
"id": "v2.0",
"links": [
{ "href": "%s", "rel": "self" }
]
}
]
}
}
`, th.Endpoint()+"v3/", th.Endpoint()+"v2.0/")
})
th.Mux.HandleFunc("/v3/auth/tokens", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Subject-Token", ID)
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `{ "token": { "expires_at": "2013-02-02T18:30:59.000000Z" } }`)
})
options := gophercloud.AuthOptions{
Username: "me",
Password: "secret",
DomainName: "default",
TenantName: "project",
IdentityEndpoint: th.Endpoint(),
}
client, err := openstack.AuthenticatedClient(options)
th.AssertNoErr(t, err)
th.CheckEquals(t, ID, client.TokenID)
}
示例11: TestList
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleListCDNFlavorsSuccessfully(t)
count := 0
err := flavors.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := flavors.ExtractFlavors(page)
if err != nil {
t.Errorf("Failed to extract flavors: %v", err)
return false, err
}
expected := []flavors.Flavor{
{
ID: "europe",
Providers: []flavors.Provider{
{
Provider: "Fastly",
Links: []gophercloud.Link{
gophercloud.Link{
Href: "http://www.fastly.com",
Rel: "provider_url",
},
},
},
},
Links: []gophercloud.Link{
gophercloud.Link{
Href: "https://www.poppycdn.io/v1.0/flavors/europe",
Rel: "self",
},
},
},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.CheckEquals(t, 1, count)
}
示例12: TestEnumerateSinglePaged
func TestEnumerateSinglePaged(t *testing.T) {
callCount := 0
pager := setupSinglePaged()
defer testhelper.TeardownHTTP()
err := pager.EachPage(func(page pagination.Page) (bool, error) {
callCount++
expected := []int{1, 2, 3}
actual, err := ExtractSingleInts(page)
testhelper.AssertNoErr(t, err)
testhelper.CheckDeepEquals(t, expected, actual)
return true, nil
})
testhelper.CheckNoErr(t, err)
testhelper.CheckEquals(t, 1, callCount)
}
示例13: TestList
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleListSuccessfully(t)
count := 0
err := tenantnetworks.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := tenantnetworks.ExtractNetworks(page)
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, ExpectedNetworkSlice, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.CheckEquals(t, 1, count)
}
示例14: TestListContainerInfo
func TestListContainerInfo(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleListContainerInfoSuccessfully(t)
count := 0
err := containers.List(fake.ServiceClient(), &containers.ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := containers.ExtractInfo(page)
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, ExpectedListInfo, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.CheckEquals(t, count, 1)
}
示例15: TestV2EndpointExact
func TestV2EndpointExact(t *testing.T) {
expectedURLs := map[gophercloud.Availability]string{
gophercloud.AvailabilityPublic: "https://public.correct.com/",
gophercloud.AvailabilityAdmin: "https://admin.correct.com/",
gophercloud.AvailabilityInternal: "https://internal.correct.com/",
}
for availability, expected := range expectedURLs {
actual, err := openstack.V2EndpointURL(&catalog2, gophercloud.EndpointOpts{
Type: "same",
Name: "same",
Region: "same",
Availability: availability,
})
th.AssertNoErr(t, err)
th.CheckEquals(t, expected, actual)
}
}