本文整理汇总了Golang中github.com/rackspace/gophercloud/testhelper/client.ServiceClient函数的典型用法代码示例。如果您正苦于以下问题:Golang ServiceClient函数的具体用法?Golang ServiceClient怎么用?Golang ServiceClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestWaitForStatus
func TestWaitForStatus(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/volumes/1234", func(w http.ResponseWriter, r *http.Request) {
time.Sleep(3 * time.Second)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"volume": {
"display_name": "vol-001",
"id": "1234",
"status":"available"
}
}`)
})
err := WaitForStatus(client.ServiceClient(), "1234", "available", 0)
if err == nil {
t.Errorf("Expected error: 'Time Out in WaitFor'")
}
err = WaitForStatus(client.ServiceClient(), "1234", "available", 6)
th.CheckNoErr(t, err)
}
示例2: TestWaitForStatus
func TestWaitForStatus(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/servers/4321", func(w http.ResponseWriter, r *http.Request) {
time.Sleep(2 * time.Second)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"server": {
"name": "the-server",
"id": "4321",
"status": "ACTIVE"
}
}`)
})
err := WaitForStatus(client.ServiceClient(), "4321", "ACTIVE", 0)
if err == nil {
t.Errorf("Expected error: 'Time Out in WaitFor'")
}
err = WaitForStatus(client.ServiceClient(), "4321", "ACTIVE", 3)
th.CheckNoErr(t, err)
}
示例3: TestSizeRange
func TestSizeRange(t *testing.T) {
_, err := Create(fake.ServiceClient(), CreateOpts{volumes.CreateOpts{Size: 1}}).Extract()
if err == nil {
t.Fatalf("Expected error, got none")
}
_, err = Create(fake.ServiceClient(), CreateOpts{volumes.CreateOpts{Size: 2000}}).Extract()
if err == nil {
t.Fatalf("Expected error, got none")
}
}
示例4: TestSendEvent
func TestSendEvent(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/events", 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, "Accept", "application/json")
th.TestJSONRequest(t, r, `{
"what": "Test Event",
"when": 1441831996000,
"tags": "Restart",
"data": "Test Data"
}`)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, ``)
})
event := Event{
What: "Test Event",
When: 1441831996000,
Tags: "Restart",
Data: "Test Data",
}
SendEvent(fake.ServiceClient(), event)
}
示例5: 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"))
}
示例6: TestList
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.MockListResponse(t)
count := 0
err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractVolumes(page)
if err != nil {
t.Errorf("Failed to extract volumes: %v", err)
return false, err
}
expected := []Volume{
Volume{
ID: "289da7f8-6440-407c-9fb4-7db01ec49164",
Name: "vol-001",
},
Volume{
ID: "96c3bda7-c82a-4f50-be73-ca7621794835",
Name: "vol-002",
},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertEquals(t, 1, count)
th.AssertNoErr(t, err)
}
示例7: 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)
}
示例8: TestCreate
func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleCreate(t)
opts := CreateOpts{
Name: "json_rack_instance",
FlavorRef: "1",
Databases: db.BatchCreateOpts{
db.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
db.CreateOpts{Name: "nextround"},
},
Users: users.BatchCreateOpts{
users.CreateOpts{
Name: "demouser",
Password: "demopassword",
Databases: db.BatchCreateOpts{
db.CreateOpts{Name: "sampledb"},
},
},
},
Size: 2,
}
instance, err := Create(fake.ServiceClient(), opts).Extract()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, &expectedInstance, instance)
}
示例9: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/extensions/agent", 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")
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(client.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.")
}
示例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: TestGetHomeDocument
func TestGetHomeDocument(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.HandleGetSuccessfully(t)
actual, err := Get(fake.ServiceClient()).Extract()
th.CheckNoErr(t, err)
expected := os.HomeDocument{
"rel/cdn": map[string]interface{}{
"href-template": "services{?marker,limit}",
"href-vars": map[string]interface{}{
"marker": "param/marker",
"limit": "param/limit",
},
"hints": map[string]interface{}{
"allow": []string{"GET"},
"formats": map[string]interface{}{
"application/json": map[string]interface{}{},
},
},
},
}
th.CheckDeepEquals(t, expected, *actual)
}
示例12: 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)
}
示例13: tokenPost
func tokenPost(t *testing.T, options gophercloud.AuthOptions, requestJSON string) CreateResult {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleTokenPost(t, requestJSON)
return Create(client.ServiceClient(), AuthOptions{options})
}
示例14: TestCreateErr
func TestCreateErr(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockCreateErrResponse(t, lbID)
opts := CreateOpts{
CreateOpt{
Address: "10.2.2.3",
Port: 80,
Condition: ENABLED,
Type: PRIMARY,
},
CreateOpt{
Address: "10.2.2.4",
Port: 81,
Condition: ENABLED,
Type: SECONDARY,
},
}
page := Create(client.ServiceClient(), lbID, opts)
actual, err := page.ExtractNodes()
if err == nil {
t.Fatal("Did not receive expected error from ExtractNodes")
}
if actual != nil {
t.Fatalf("Received non-nil result from failed ExtractNodes: %#v", actual)
}
}
示例15: TestCreate
func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockCreateRuleResponse(t)
opts := CreateOpts{
IPProtocol: "TCP",
FromPort: 80,
ToPort: 80,
CIDR: "10.10.12.0/24",
}
group, err := Create(client.ServiceClient(), opts).Extract()
th.AssertNoErr(t, err)
expected := &DefaultRule{
ID: ruleID,
FromPort: 80,
ToPort: 80,
IPProtocol: "TCP",
IPRange: secgroups.IPRange{CIDR: "10.10.12.0/24"},
}
th.AssertDeepEquals(t, expected, group)
}