本文整理匯總了Golang中github.com/rackspace/gophercloud/testhelper.AssertEquals函數的典型用法代碼示例。如果您正苦於以下問題:Golang AssertEquals函數的具體用法?Golang AssertEquals怎麽用?Golang AssertEquals使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AssertEquals函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: TestURLs
func TestURLs(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.AssertEquals(t, th.Endpoint()+"v2.0/security-groups", rootURL(fake.ServiceClient()))
th.AssertEquals(t, th.Endpoint()+"v2.0/security-groups/foo", resourceURL(fake.ServiceClient(), "foo"))
}
示例3: 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))
}
示例4: 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 := List(fakeclient.ServiceClient(), 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 := 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)
}
示例5: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/os-networksv2/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": {
"label": "test-network-1",
"cidr": "192.168.100.0/24",
"id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
}
}
`)
})
n, err := Get(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.CIDR, "192.168.100.0/24")
th.AssertEquals(t, n.Label, "test-network-1")
th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
}
示例6: TestMemberListSuccessfully
func TestMemberListSuccessfully(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleImageMemberList(t)
pager := 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 := 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, 1, pages)
th.AssertEquals(t, 2, count)
}
示例7: 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 := 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.")
}
示例8: TestImageMemberDetailsAndUpdate
func TestImageMemberDetailsAndUpdate(t *testing.T) {
// getting current tenant id
memberTenantID := os.Getenv("OS_TENANT_ID")
if memberTenantID == "" {
t.Fatalf("Please define OS_TENANT_ID for image member updating test was '%s'", memberTenantID)
}
client := newClient(t)
//creating image
image := createTestImage(t, client)
defer deleteImage(t, client, image)
//creating member
member, err := members.Create(client, image.ID, memberTenantID).Extract()
th.AssertNoErr(t, err)
th.AssertNotNil(t, member)
//checking image member details
member, err = members.Get(client, image.ID, memberTenantID).Extract()
th.AssertNoErr(t, err)
th.AssertNotNil(t, member)
th.AssertEquals(t, memberTenantID, member.MemberID)
th.AssertEquals(t, "pending", member.Status)
t.Logf("Updating image's %s member status for tenant %s to 'accepted' ", image.ID, memberTenantID)
//updating image
member, err = members.Update(client, image.ID, memberTenantID, "accepted").Extract()
th.AssertNoErr(t, err)
th.AssertNotNil(t, member)
th.AssertEquals(t, "accepted", member.Status)
}
示例9: TestUpdate
func TestUpdate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleUpdate(t)
options := UpdateOpts{
UpdateOptsBuilder: ports.UpdateOpts{
Name: "new_port_name",
FixedIPs: []ports.IP{
{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"},
},
SecurityGroups: []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"},
},
HostID: "HOST1",
VNICType: "normal",
}
s, err := Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", options).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.Name, "new_port_name")
th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{
{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"},
})
th.AssertDeepEquals(t, s.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"})
th.AssertEquals(t, s.HostID, "HOST1")
th.AssertEquals(t, s.VNICType, "normal")
}
示例10: TestBulkDelete
func TestBulkDelete(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.AssertEquals(t, r.URL.RawQuery, "bulk-delete")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"Number Not Found": 1,
"Response Status": "200 OK",
"Errors": [],
"Number Deleted": 1,
"Response Body": ""
}
`)
})
options := DeleteOpts{"gophercloud-testcontainer1", "gophercloud-testcontainer2"}
actual, err := Delete(fake.ServiceClient(), options).ExtractBody()
th.AssertNoErr(t, err)
th.AssertEquals(t, actual.NumberDeleted, 1)
}
示例11: TestUpdate
func TestUpdate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
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, `
{
"subnet": {
"name": "my_new_subnet",
"dns_nameservers": ["foo"],
"host_routes": [{"destination":"","nexthop": "bar"}]
}
}
`)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `
{
"subnet": {
"name": "my_new_subnet",
"enable_dhcp": true,
"network_id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
"tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
"dns_nameservers": [],
"allocation_pools": [
{
"start": "10.0.0.2",
"end": "10.0.0.254"
}
],
"host_routes": [],
"ip_version": 4,
"gateway_ip": "10.0.0.1",
"cidr": "10.0.0.0/24",
"id": "08eae331-0402-425a-923c-34f7cfe39c1b"
}
}
`)
})
opts := os.UpdateOpts{
Name: "my_new_subnet",
DNSNameservers: []string{"foo"},
HostRoutes: []os.HostRoute{
os.HostRoute{NextHop: "bar"},
},
}
s, err := Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.Name, "my_new_subnet")
th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b")
}
示例12: TestProjectCRUDOperations
func TestProjectCRUDOperations(t *testing.T) {
serviceClient := createAuthenticatedClient(t)
if serviceClient == nil {
return
}
// Create project
opts := projects.ProjectOpts{
Enabled: true,
Name: "Test project",
Description: "This is test project",
}
project, err := projects.Create(serviceClient, opts).Extract()
th.AssertNoErr(t, err)
defer projects.Delete(serviceClient, project.ID)
th.AssertEquals(t, project.Enabled, true)
th.AssertEquals(t, project.Name, "Test project")
th.AssertEquals(t, project.Description, "This is test project")
// List projects
pager := projects.List(serviceClient, projects.ListOpts{})
err = pager.EachPage(func(page pagination.Page) (bool, error) {
t.Logf("--- Page ---")
projectList, err := projects.ExtractProjects(page)
th.AssertNoErr(t, err)
for _, p := range projectList {
t.Logf("Project: ID [%s] Name [%s] Is enabled? [%s]",
p.ID, p.Name, p.Enabled)
}
return true, nil
})
th.CheckNoErr(t, err)
projectID := project.ID
// Get a project
if projectID == "" {
t.Fatalf("In order to retrieve a project, the ProjectID must be set")
}
project, err = projects.Get(serviceClient, projectID).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, project.ID, projectID)
th.AssertEquals(t, project.DomainID, "")
th.AssertEquals(t, project.ParentID, "")
th.AssertEquals(t, project.Enabled, true)
th.AssertEquals(t, project.Name, "Test project")
th.AssertEquals(t, project.Description, "This is test project")
// Update project
project, err = projects.Update(serviceClient, projectID, projects.ProjectOpts{Name: "New test project name"}).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, project.Name, "New test project name")
// Delete project
res := projects.Delete(serviceClient, projectID)
th.AssertNoErr(t, res.Err)
}
示例13: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/security-groups/85cc3048-abc3-43cc-89b3-377341426ac5", 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, `
{
"security_group": {
"description": "default",
"id": "85cc3048-abc3-43cc-89b3-377341426ac5",
"name": "default",
"security_group_rules": [
{
"direction": "egress",
"ethertype": "IPv6",
"id": "3c0e45ff-adaf-4124-b083-bf390e5482ff",
"port_range_max": null,
"port_range_min": null,
"protocol": null,
"remote_group_id": null,
"remote_ip_prefix": null,
"security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5",
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
},
{
"direction": "egress",
"ethertype": "IPv4",
"id": "93aa42e5-80db-4581-9391-3a608bd0e448",
"port_range_max": null,
"port_range_min": null,
"protocol": null,
"remote_group_id": null,
"remote_ip_prefix": null,
"security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5",
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
}
],
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
}
}
`)
})
sg, err := Get(fake.ServiceClient(), "85cc3048-abc3-43cc-89b3-377341426ac5").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, "default", sg.Description)
th.AssertEquals(t, "85cc3048-abc3-43cc-89b3-377341426ac5", sg.ID)
th.AssertEquals(t, "default", sg.Name)
th.AssertEquals(t, 2, len(sg.Rules))
th.AssertEquals(t, "e4f50856753b4dc6afee5fa6b9b6c550", sg.TenantID)
}
示例14: TestCreate
func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/routers", 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, `
{
"router":{
"name": "foo_router",
"admin_state_up": false,
"external_gateway_info":{
"network_id":"8ca37218-28ff-41cb-9b10-039601ea7e6b"
}
}
}
`)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `
{
"router": {
"status": "ACTIVE",
"external_gateway_info": {
"network_id": "8ca37218-28ff-41cb-9b10-039601ea7e6b"
},
"name": "foo_router",
"admin_state_up": false,
"tenant_id": "6b96ff0cb17a4b859e1e575d221683d3",
"distributed": false,
"id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e"
}
}
`)
})
asu := false
gwi := GatewayInfo{NetworkID: "8ca37218-28ff-41cb-9b10-039601ea7e6b"}
options := CreateOpts{
Name: "foo_router",
AdminStateUp: &asu,
GatewayInfo: &gwi,
}
r, err := Create(fake.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, "foo_router", r.Name)
th.AssertEquals(t, false, r.AdminStateUp)
th.AssertDeepEquals(t, GatewayInfo{NetworkID: "8ca37218-28ff-41cb-9b10-039601ea7e6b"}, r.GatewayInfo)
}
示例15: TestValidateType
func TestValidateType(t *testing.T) {
ok := validateType(Schedule)
th.AssertEquals(t, true, ok)
ok = validateType(Webhook)
th.AssertEquals(t, true, ok)
ok = validateType("BAD")
th.AssertEquals(t, false, ok)
}