本文整理汇总了Golang中github.com/jrperritt/rack/internal/github.com/rackspace/gophercloud/testhelper.SetupHTTP函数的典型用法代码示例。如果您正苦于以下问题:Golang SetupHTTP函数的具体用法?Golang SetupHTTP怎么用?Golang SetupHTTP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetupHTTP函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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)
}
开发者ID:harshalhshah,项目名称:rack,代码行数:33,代码来源:upload_test.go
示例2: TestListURL
func TestListURL(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
c := client.ServiceClient()
th.CheckEquals(t, c.Endpoint+"os-keypairs", listURL(c))
}
开发者ID:hdansou,项目名称:rack,代码行数:7,代码来源:urls_test.go
示例3: TestRebuildExecute
func TestRebuildExecute(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/servers/server1/action", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusAccepted)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `{"server":{}}`)
})
cmd := &commandRebuild{
Ctx: &handler.Context{
ServiceClient: client.ServiceClient(),
},
}
actual := &handler.Resource{
Params: ¶msRebuild{
serverID: "server1",
opts: &servers.RebuildOpts{
Name: "server1Rename",
ImageID: "123456789",
AdminPass: "secret",
DiskConfig: diskconfig.Auto,
},
},
}
cmd.Execute(actual)
th.AssertNoErr(t, actual.Err)
}
开发者ID:hdansou,项目名称:rack,代码行数:27,代码来源:rebuild_test.go
示例4: 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:hdansou,项目名称:rack,代码行数:7,代码来源:urls_test.go
示例5: TestCreateURL
func TestCreateURL(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
c := client.ServiceClient()
th.CheckEquals(t, c.Endpoint+"os-volumes_boot", createURL(c))
}
开发者ID:hdansou,项目名称:rack,代码行数:7,代码来源:urls_test.go
示例6: TestDeleteExecute
func TestDeleteExecute(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()
res := &handler.Resource{
Params: ¶msDelete{container: "foo", object: "bar"},
}
cmd.Execute(res)
th.AssertNoErr(t, res.Err)
}
开发者ID:harshalhshah,项目名称:rack,代码行数:25,代码来源:delete_test.go
示例7: TestUploadExecute
func TestUploadExecute(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/foo/bar", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(201)
th.TestMethod(t, r, "PUT")
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 := newUpCmd(fs)
cmd.Ctx.ServiceClient = client.ServiceClient()
res := &handler.Resource{
Params: ¶msUpload{container: "foo", object: "bar"},
}
cmd.Execute(res)
th.AssertNoErr(t, res.Err)
th.AssertEquals(t, "Successfully uploaded object [bar] to container [foo]\n", res.Result)
}
开发者ID:stephamon,项目名称:rack,代码行数:29,代码来源:upload_test.go
示例8: TestListHandleSingle
func TestListHandleSingle(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
setupList(t)
fs := flag.NewFlagSet("flags", 1)
fs.String("container", "", "")
fs.Set("container", "testContainer")
cmd := newListCmd(fs)
cmd.Ctx.ServiceClient = client.ServiceClient()
expected := &handler.Resource{
Params: ¶msList{
container: "testContainer",
},
}
actual := &handler.Resource{
Params: ¶msList{},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsList).container, actual.Params.(*paramsList).container)
}
开发者ID:harshalhshah,项目名称:rack,代码行数:28,代码来源:list_test.go
示例9: TestGetRequest
func TestGetRequest(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
client := gophercloud.ServiceClient{
ProviderClient: &gophercloud.ProviderClient{
TokenID: "12345abcdef",
},
Endpoint: testhelper.Endpoint(),
}
testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "GET")
testhelper.TestHeader(t, r, "Content-Type", "")
testhelper.TestHeader(t, r, "Accept", "application/json")
testhelper.TestHeader(t, r, "X-Auth-Token", "12345abcdef")
testhelper.TestHeader(t, r, "X-Subject-Token", "abcdef12345")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{ "token": { "expires_at": "2014-08-29T13:10:01.000000Z" } }
`)
})
token, err := Get(&client, "abcdef12345").Extract()
if err != nil {
t.Errorf("Info returned an error: %v", err)
}
expected, _ := time.Parse(time.UnixDate, "Fri Aug 29 13:10:01 UTC 2014")
if token.ExpiresAt != expected {
t.Errorf("Expected expiration time %s, but was %s", expected.Format(time.UnixDate), token.ExpiresAt.Format(time.UnixDate))
}
}
开发者ID:hdansou,项目名称:rack,代码行数:34,代码来源:requests_test.go
示例10: 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)
}
开发者ID:hdansou,项目名称:rack,代码行数:27,代码来源:client_test.go
示例11: authTokenPost
// authTokenPost verifies that providing certain AuthOptions and Scope results in an expected JSON structure.
func authTokenPost(t *testing.T, options gophercloud.AuthOptions, scope *Scope, requestJSON string) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
client := gophercloud.ServiceClient{
ProviderClient: &gophercloud.ProviderClient{
TokenID: "12345abcdef",
},
Endpoint: testhelper.Endpoint(),
}
testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "POST")
testhelper.TestHeader(t, r, "Content-Type", "application/json")
testhelper.TestHeader(t, r, "Accept", "application/json")
testhelper.TestJSONRequest(t, r, requestJSON)
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `{
"token": {
"expires_at": "2014-10-02T13:45:00.000000Z"
}
}`)
})
_, err := Create(&client, options, scope).Extract()
if err != nil {
t.Errorf("Create returned an error: %v", err)
}
}
开发者ID:hdansou,项目名称:rack,代码行数:31,代码来源:requests_test.go
示例12: TestCreateExtractsTokenFromResponse
func TestCreateExtractsTokenFromResponse(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
client := gophercloud.ServiceClient{
ProviderClient: &gophercloud.ProviderClient{},
Endpoint: testhelper.Endpoint(),
}
testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Subject-Token", "aaa111")
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `{
"token": {
"expires_at": "2014-10-02T13:45:00.000000Z"
}
}`)
})
options := gophercloud.AuthOptions{UserID: "me", Password: "shhh"}
token, err := Create(&client, options, nil).Extract()
if err != nil {
t.Fatalf("Create returned an error: %v", err)
}
if token.ID != "aaa111" {
t.Errorf("Expected token to be aaa111, but was %s", token.ID)
}
}
开发者ID:hdansou,项目名称:rack,代码行数:30,代码来源:requests_test.go
示例13: TestCreateExecute
func TestCreateExecute(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/container1", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Container-Meta-Foo", "bar")
w.Header().Add("X-Container-Meta-Key", "val")
w.Header().Add("X-Trans-Id", "1234567")
w.WriteHeader(http.StatusNoContent)
})
cmd := &commandCreate{
Ctx: &handler.Context{
ServiceClient: client.ServiceClient(),
},
}
actual := &handler.Resource{
Params: ¶msCreate{
opts: containers.CreateOpts{
Metadata: map[string]string{
"key": "val",
"foo": "bar",
},
},
container: "container1",
},
}
cmd.Execute(actual)
th.AssertNoErr(t, actual.Err)
}
开发者ID:hdansou,项目名称:rack,代码行数:28,代码来源:create_test.go
示例14: TestListAll
func TestListAll(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockListResponse(t)
allPages, err := List(client.ServiceClient(), &ListOpts{}).AllPages()
th.AssertNoErr(t, err)
actual, err := ExtractVolumes(allPages)
th.AssertNoErr(t, 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)
}
开发者ID:hdansou,项目名称:rack,代码行数:25,代码来源:requests_test.go
示例15: TestGetHandleSingle
func TestGetHandleSingle(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/servers/detail", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `{"servers":[{"ID":"server1","Name":"server1Name"}]}`)
})
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("name", "", "")
flagset.Set("name", "server1Name")
c := cli.NewContext(app, flagset, nil)
cmd := &commandGet{
Ctx: &handler.Context{
CLIContext: c,
ServiceClient: client.ServiceClient(),
},
}
expected := &handler.Resource{
Params: ¶msGet{
server: "server1",
},
}
actual := &handler.Resource{
Params: ¶msGet{},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsGet).server, actual.Params.(*paramsGet).server)
}
开发者ID:hdansou,项目名称:rack,代码行数:30,代码来源:get_test.go
示例16: TestChooseVersionFromSuffix
func TestChooseVersionFromSuffix(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
v2 := &Version{ID: "v2.0", Priority: 2, Suffix: "/v2.0/"}
v3 := &Version{ID: "v3.0", Priority: 3, Suffix: "/v3.0/"}
c := &gophercloud.ProviderClient{
IdentityBase: testhelper.Endpoint(),
IdentityEndpoint: testhelper.Endpoint() + "v2.0/",
}
v, endpoint, err := ChooseVersion(c, []*Version{v2, v3})
if err != nil {
t.Fatalf("Unexpected error from ChooseVersion: %v", err)
}
if v != v2 {
t.Errorf("Expected %#v to win, but %#v did instead", v2, v)
}
expected := testhelper.Endpoint() + "v2.0/"
if endpoint != expected {
t.Errorf("Expected endpoint [%s], but was [%s] instead", expected, endpoint)
}
}
开发者ID:hdansou,项目名称:rack,代码行数:25,代码来源:choose_version_test.go
示例17: 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"))
}
开发者ID:hdansou,项目名称:rack,代码行数:7,代码来源:requests_test.go
示例18: 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)
}
开发者ID:harshalhshah,项目名称:rack,代码行数:32,代码来源:delete_test.go
示例19: createLinked
func createLinked(t *testing.T) Pager {
testhelper.SetupHTTP()
testhelper.Mux.HandleFunc("/page1", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `{ "ints": [1, 2, 3], "links": { "next": "%s/page2" } }`, testhelper.Server.URL)
})
testhelper.Mux.HandleFunc("/page2", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `{ "ints": [4, 5, 6], "links": { "next": "%s/page3" } }`, testhelper.Server.URL)
})
testhelper.Mux.HandleFunc("/page3", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `{ "ints": [7, 8, 9], "links": { "next": null } }`)
})
client := createClient()
createPage := func(r PageResult) Page {
return LinkedPageResult{LinkedPageBase{PageResult: r}}
}
return NewPager(client, testhelper.Server.URL+"/page1", createPage)
}
开发者ID:hdansou,项目名称:rack,代码行数:26,代码来源:linked_test.go
示例20: 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:hdansou,项目名称:rack,代码行数:33,代码来源:delegate_test.go
注:本文中的github.com/jrperritt/rack/internal/github.com/rackspace/gophercloud/testhelper.SetupHTTP函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论