本文整理汇总了Golang中github.com/rackspace/rack/internal/github.com/rackspace/gophercloud/testhelper.AssertEquals函数的典型用法代码示例。如果您正苦于以下问题:Golang AssertEquals函数的具体用法?Golang AssertEquals怎么用?Golang AssertEquals使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AssertEquals函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestListHandleSingle
func TestListHandleSingle(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("stack-name", "", "")
flagset.String("stack-id", "", "")
flagset.Set("stack-name", "stack1")
flagset.Set("stack-id", "id1")
c := cli.NewContext(app, flagset, nil)
cmd := &commandList{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msList{
stackName: "stack1",
stackID: "id1",
},
}
actual := &handler.Resource{
Params: ¶msList{},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsList).stackName, actual.Params.(*paramsList).stackName)
th.AssertEquals(t, expected.Params.(*paramsList).stackID, actual.Params.(*paramsList).stackID)
}
示例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: TestUpdate
func TestUpdate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/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 := UpdateOpts{
Name: "my_new_subnet",
DNSNameservers: []string{"foo"},
HostRoutes: []HostRoute{
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")
}
示例4: 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)
}
示例5: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.MockGetResponse(t)
v, err := Get(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, v.Name, "snapshot-001")
th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
}
示例6: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/v2.0/ports/46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2", 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, `
{
"port": {
"status": "ACTIVE",
"name": "",
"admin_state_up": true,
"network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7",
"tenant_id": "7e02058126cc4950b75f9970368ba177",
"device_owner": "network:router_interface",
"mac_address": "fa:16:3e:23:fd:d7",
"fixed_ips": [
{
"subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2",
"ip_address": "10.0.0.1"
}
],
"id": "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2",
"security_groups": [],
"device_id": "5e3898d7-11be-483e-9732-b2f5eccd2b2e"
}
}
`)
})
n, err := Get(fake.ServiceClient(), "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.Status, "ACTIVE")
th.AssertEquals(t, n.Name, "")
th.AssertEquals(t, n.AdminStateUp, true)
th.AssertEquals(t, n.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7")
th.AssertEquals(t, n.TenantID, "7e02058126cc4950b75f9970368ba177")
th.AssertEquals(t, n.DeviceOwner, "network:router_interface")
th.AssertEquals(t, n.MACAddress, "fa:16:3e:23:fd:d7")
th.AssertDeepEquals(t, n.FixedIPs, []IP{
IP{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.1"},
})
th.AssertEquals(t, n.ID, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2")
th.AssertDeepEquals(t, n.SecurityGroups, []string{})
th.AssertEquals(t, n.Status, "ACTIVE")
th.AssertEquals(t, n.DeviceID, "5e3898d7-11be-483e-9732-b2f5eccd2b2e")
}
示例7: TestCreate
func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockCreateResponse(t)
options := &CreateOpts{Size: 75}
n, err := Create(client.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.Size, 4)
th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
}
示例8: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockGetResponse(t)
v, err := Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, v.Name, "vol-001")
th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertEquals(t, v.Attachments[0]["device"], "/dev/vde")
}
示例9: TestCreate
func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.MockCreateResponse(t)
options := &CreateOpts{VolumeID: "1234", Name: "snapshot-001"}
n, err := Create(fake.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.VolumeID, "1234")
th.AssertEquals(t, n.Name, "snapshot-001")
th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
}
示例10: TestPreviewHandleSingle
func TestPreviewHandleSingle(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("name", "", "")
flagset.Set("name", "stack1")
c := cli.NewContext(app, flagset, nil)
cmd := &commandPreview{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msPreview{
opts: &osStacks.PreviewOpts{Name: "stack1"},
},
}
actual := &handler.Resource{
Params: ¶msPreview{
opts: &osStacks.PreviewOpts{},
},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsPreview).opts.Name, actual.Params.(*paramsPreview).opts.Name)
}
示例11: TestUploadExecute
func TestUploadExecute(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/foo/bar", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
w.Header().Add("Content-Type", "text/plain")
hash := md5.New()
io.WriteString(hash, "hodor")
localChecksum := hash.Sum(nil)
w.Header().Set("ETag", fmt.Sprintf("%x", localChecksum))
w.WriteHeader(201)
fmt.Fprintf(w, `hodor`)
})
fs := flag.NewFlagSet("flags", 1)
cmd := newUpCmd(fs)
cmd.Ctx.ServiceClient = client.ServiceClient()
res := &handler.Resource{
Params: ¶msUpload{
container: "foo",
object: "bar",
stream: strings.NewReader("hodor"),
opts: osObjects.CreateOpts{},
},
}
cmd.Execute(res)
th.AssertNoErr(t, res.Err)
th.AssertEquals(t, "Successfully uploaded object [bar] to container [foo]\n", res.Result)
}
示例12: TestDeleteHandleSingle
func TestDeleteHandleSingle(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/foo/bar", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(204)
})
fs := flag.NewFlagSet("flags", 1)
fs.String("container", "", "")
fs.String("name", "", "")
fs.Set("container", "foo")
fs.Set("name", "bar")
cmd := newDelCmd(fs)
cmd.Ctx.ServiceClient = client.ServiceClient()
expected := &handler.Resource{
Params: ¶msDelete{
object: "bar",
},
}
actual := &handler.Resource{
Params: ¶msDelete{},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsDelete).object, actual.Params.(*paramsDelete).object)
}
示例13: TestGetExecute
func TestGetExecute(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/foo/bar", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/plain")
fmt.Fprintf(w, `hodor`)
})
fs := flag.NewFlagSet("flags", 1)
fs.String("container", "", "")
fs.String("name", "", "")
fs.Set("container", "foo")
fs.Set("name", "bar")
cmd := newGetCmd(fs)
cmd.Ctx.ServiceClient = client.ServiceClient()
res := &handler.Resource{
Params: ¶msGet{container: "foo", object: "bar"},
}
cmd.Execute(res)
th.AssertNoErr(t, res.Err)
th.AssertEquals(t, "text/plain", res.Result.(map[string]interface{})["ContentType"])
}
示例14: TestCreateHandleSingle
func TestCreateHandleSingle(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("name", "", "")
flagset.Set("name", "server1")
c := cli.NewContext(app, flagset, nil)
cmd := &commandCreate{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msCreate{
opts: &servers.CreateOpts{
Name: "server1",
},
},
}
actual := &handler.Resource{
Params: ¶msCreate{
opts: &servers.CreateOpts{},
},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsCreate).opts.Name, actual.Params.(*paramsCreate).opts.Name)
}
示例15: TestEnumerateMarker
func TestEnumerateMarker(t *testing.T) {
pager := createMarkerPaged(t)
defer testhelper.TeardownHTTP()
callCount := 0
err := pager.EachPage(func(page Page) (bool, error) {
actual, err := ExtractMarkerStrings(page)
if err != nil {
return false, err
}
t.Logf("Handler invoked with %v", actual)
var expected []string
switch callCount {
case 0:
expected = []string{"aaa", "bbb", "ccc"}
case 1:
expected = []string{"ddd", "eee", "fff"}
case 2:
expected = []string{"ggg", "hhh", "iii"}
default:
t.Fatalf("Unexpected call count: %d", callCount)
return false, nil
}
testhelper.CheckDeepEquals(t, expected, actual)
callCount++
return true, nil
})
testhelper.AssertNoErr(t, err)
testhelper.AssertEquals(t, callCount, 3)
}