本文整理汇总了Golang中github.com/rackspace/gophercloud/testhelper/client.ServiceClient函数的典型用法代码示例。如果您正苦于以下问题:Golang ServiceClient函数的具体用法?Golang ServiceClient怎么用?Golang ServiceClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:26,代码来源:util_test.go
示例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)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:26,代码来源:util_test.go
示例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")
}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:delegate_test.go
示例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)
}
开发者ID:goru97,项目名称:Metrics_GO,代码行数:28,代码来源:requests_test.go
示例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"))
}
开发者ID:RomainVabre,项目名称:origin,代码行数:7,代码来源:urls_test.go
示例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)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:35,代码来源:delegate_test.go
示例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)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:26,代码来源:requests_test.go
示例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)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:29,代码来源:requests_test.go
示例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.")
}
开发者ID:RomainVabre,项目名称:origin,代码行数:34,代码来源:delegate_test.go
示例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)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:33,代码来源:delegate_test.go
示例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)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:25,代码来源:delegate_test.go
示例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)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:25,代码来源:requests_test.go
示例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})
}
开发者ID:RomainVabre,项目名称:origin,代码行数:7,代码来源:requests_test.go
示例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)
}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:31,代码来源:requests_test.go
示例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)
}
开发者ID:nerfmiester,项目名称:gophercloud,代码行数:25,代码来源:requests_test.go
示例16: TestList
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockListRulesResponse(t)
count := 0
err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractDefaultRules(page)
th.AssertNoErr(t, err)
expected := []DefaultRule{
DefaultRule{
FromPort: 80,
ID: ruleID,
IPProtocol: "TCP",
IPRange: secgroups.IPRange{CIDR: "10.10.10.0/24"},
ToPort: 80,
},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, count)
}
开发者ID:nerfmiester,项目名称:gophercloud,代码行数:31,代码来源:requests_test.go
示例17: TestListURL
func TestListURL(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
c := client.ServiceClient()
th.CheckEquals(t, c.Endpoint+"os-keypairs", listURL(c))
}
开发者ID:RomainVabre,项目名称:origin,代码行数:7,代码来源:urls_test.go
示例18: TestUpdateSuccessful
func TestUpdateSuccessful(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
testhelper.Mux.HandleFunc("/services/12345", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "PATCH")
testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID)
testhelper.TestJSONRequest(t, r, `{ "type": "lasermagic" }`)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `
{
"service": {
"id": "12345",
"type": "lasermagic"
}
}
`)
})
result, err := Update(client.ServiceClient(), "12345", "lasermagic").Extract()
if err != nil {
t.Fatalf("Unable to update service: %v", err)
}
if result.ID != "12345" {
t.Fatalf("Expected ID 12345, was %s", result.ID)
}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:29,代码来源:requests_test.go
示例19: TestGenerateExecute
func TestGenerateExecute(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/os-keypairs", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `{"keypair":{}}`)
})
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.Bool("json", false, "")
c := cli.NewContext(app, flagset, nil)
cmd := &commandGenerate{
Ctx: &handler.Context{
CLIContext: c,
ServiceClient: client.ServiceClient(),
},
}
actual := &handler.Resource{
Params: ¶msGenerate{
opts: &osKeypairs.CreateOpts{
Name: "keypair1Name",
},
},
}
cmd.Execute(actual)
th.AssertNoErr(t, actual.Err)
}
开发者ID:flazz,项目名称:rack,代码行数:27,代码来源:generate_test.go
示例20: TestGet
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockGetGroupsResponse(t, groupID)
group, err := Get(client.ServiceClient(), groupID).Extract()
th.AssertNoErr(t, err)
expected := &SecurityGroup{
ID: groupID,
Description: "default",
Name: "default",
TenantID: "openstack",
Rules: []Rule{
Rule{
FromPort: 80,
ToPort: 85,
IPProtocol: "TCP",
IPRange: IPRange{CIDR: "0.0.0.0"},
Group: Group{TenantID: "openstack", Name: "default"},
ParentGroupID: groupID,
ID: ruleID,
},
},
}
th.AssertDeepEquals(t, expected, group)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:29,代码来源:requests_test.go
注:本文中的github.com/rackspace/gophercloud/testhelper/client.ServiceClient函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论