本文整理汇总了Golang中github.com/rackspace/gophercloud/testhelper.CheckEquals函数的典型用法代码示例。如果您正苦于以下问题:Golang CheckEquals函数的具体用法?Golang CheckEquals怎么用?Golang CheckEquals使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CheckEquals函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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")
}
示例2: TestGetExtension
func TestGetExtension(t *testing.T) {
service := authenticatedClient(t)
ext, err := extensions2.Get(service, "OS-KSCRUD").Extract()
th.AssertNoErr(t, err)
th.CheckEquals(t, "OpenStack Keystone User CRUD", ext.Name)
th.CheckEquals(t, "http://docs.openstack.org/identity/api/ext/OS-KSCRUD/v1.0", ext.Namespace)
th.CheckEquals(t, "OS-KSCRUD", ext.Alias)
th.CheckEquals(t, "OpenStack extensions to Keystone v2.0 API enabling User Operations.", ext.Description)
}
示例3: TestCreateContainer
func TestCreateContainer(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleCreateContainerSuccessfully(t)
options := CreateOpts{ContentType: "application/json", Metadata: map[string]string{"foo": "bar"}}
res := Create(fake.ServiceClient(), "testContainer", options)
c, err := res.Extract()
th.CheckNoErr(t, err)
th.CheckEquals(t, "bar", res.Header["X-Container-Meta-Foo"][0])
th.CheckEquals(t, "1234567", c.TransID)
}
示例4: TestListURL
func TestListURL(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
c := client.ServiceClient()
th.CheckEquals(t, c.Endpoint+"os-keypairs", listURL(c))
}
示例5: TestList
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/os-networksv2", 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, `
{
"networks": [
{
"label": "test-network-1",
"cidr": "192.168.100.0/24",
"id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
},
{
"label": "test-network-2",
"cidr": "192.30.250.00/18",
"id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324"
}
]
}
`)
})
client := fake.ServiceClient()
count := 0
err := List(client).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractNetworks(page)
if err != nil {
t.Errorf("Failed to extract networks: %v", err)
return false, err
}
expected := []Network{
Network{
Label: "test-network-1",
CIDR: "192.168.100.0/24",
ID: "d32019d3-bc6e-4319-9c1d-6722fc136a22",
},
Network{
Label: "test-network-2",
CIDR: "192.30.250.00/18",
ID: "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.CheckEquals(t, 1, count)
}
示例6: TestAuthenticatedClientV2
func TestAuthenticatedClientV2(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/tokens", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `
{
"access": {
"token": {
"id": "01234567890",
"expires": "2014-10-01T10:00:00.000000Z"
},
"serviceCatalog": []
}
}
`)
})
options := gophercloud.AuthOptions{
Username: "me",
APIKey: "09876543210",
IdentityEndpoint: th.Endpoint() + "v2.0/",
}
client, err := AuthenticatedClient(options)
th.AssertNoErr(t, err)
th.CheckEquals(t, "01234567890", client.TokenID)
}
示例7: TestGetVolumes
func (s *CinderV2Suite) TestGetVolumes() {
Convey("Given Cinder volumes are requested", s.T(), func() {
Convey("When authentication is required", func() {
provider, err := openstackintel.Authenticate(th.Endpoint(), "me", "secret", "tenant")
th.AssertNoErr(s.T(), err)
th.CheckEquals(s.T(), s.Token, provider.TokenID)
Convey("and GetVolumes called", func() {
dispatch := ServiceV2{}
volumes, err := dispatch.GetVolumes(provider)
Convey("Then proper limits values are returned", func() {
So(len(volumes), ShouldEqual, 2)
So(volumes[s.Tenant1ID].Bytes, ShouldEqual, s.Vol1Size*1024*1024*1024)
So(volumes[s.Tenant2ID].Bytes, ShouldEqual, s.Vol2Size*1024*1024*1024)
So(volumes[s.Tenant1ID].Count, ShouldEqual, 1)
So(volumes[s.Tenant2ID].Count, ShouldEqual, 1)
})
Convey("and no error reported", func() {
So(err, ShouldBeNil)
})
})
})
})
}
示例8: TestV3EndpointNoService
func TestV3EndpointNoService(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/services", 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")
fmt.Fprintf(w, `
{
"links": {
"next": null,
"previous": null
},
"services": []
}
`)
})
_, err := V3EndpointURL(fake.ServiceClient(), gophercloud.EndpointOpts{
Type: "nope",
Name: "same",
Region: "same",
Availability: gophercloud.AvailabilityPublic,
})
th.CheckEquals(t, gophercloud.ErrServiceNotFound, err)
}
示例9: TestV2EndpointNone
func TestV2EndpointNone(t *testing.T) {
_, err := V2EndpointURL(&catalog2, gophercloud.EndpointOpts{
Type: "nope",
Availability: gophercloud.AvailabilityPublic,
})
th.CheckEquals(t, gophercloud.ErrEndpointNotFound, err)
}
示例10: 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)
}
示例11: TestCreateURL
func TestCreateURL(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
c := client.ServiceClient()
th.CheckEquals(t, c.Endpoint+"os-floating-ips", createURL(c))
}
示例12: TestGetURL
func TestGetURL(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
c := client.ServiceClient()
th.CheckEquals(t, c.Endpoint+"os-quota-sets/wat", getURL(c, "wat"))
}
示例13: TestDeleteURL
func TestDeleteURL(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
c := client.ServiceClient()
th.CheckEquals(t, c.Endpoint+"os-keypairs/wat", deleteURL(c, "wat"))
}
示例14: TestKeystoneLogin
func TestKeystoneLogin(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
const ID = "0123456789"
th.Mux.HandleFunc("/v3/auth/tokens", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Subject-Token", ID)
type AuthRequest struct {
Auth struct {
Identity struct {
Password struct {
User struct {
Domain struct{ Name string }
Name string
Password string
}
}
}
}
}
var x AuthRequest
body, _ := ioutil.ReadAll(r.Body)
json.Unmarshal(body, &x)
domainName := x.Auth.Identity.Password.User.Domain.Name
userName := x.Auth.Identity.Password.User.Name
password := x.Auth.Identity.Password.User.Password
if domainName == "default" && userName == "testuser" && password == "testpw" {
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `{ "token": { "expires_at": "2020-02-02T18:30:59.000000Z" } }`)
} else {
w.WriteHeader(http.StatusUnauthorized)
}
})
keystoneAuth := New("keystone_auth", th.Endpoint(), http.DefaultTransport, "default", &TestUserIdentityMapper{})
_, ok, err := keystoneAuth.AuthenticatePassword("testuser", "testpw")
th.AssertNoErr(t, err)
th.CheckEquals(t, ok, true)
_, ok, err = keystoneAuth.AuthenticatePassword("testuser", "badpw")
th.AssertNoErr(t, err)
th.CheckEquals(t, ok, false)
_, ok, err = keystoneAuth.AuthenticatePassword("testuser", "")
th.AssertNoErr(t, err)
th.CheckEquals(t, ok, false)
}
示例15: TestGetURL
func TestGetURL(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
c := client.ServiceClient()
id := "1"
th.CheckEquals(t, c.Endpoint+"os-tenant-networks/"+id, getURL(c, id))
}