本文整理汇总了Golang中github.com/rackspace/rack/internal/github.com/rackspace/gophercloud/testhelper.TeardownHTTP函数的典型用法代码示例。如果您正苦于以下问题:Golang TeardownHTTP函数的具体用法?Golang TeardownHTTP怎么用?Golang TeardownHTTP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TeardownHTTP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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"])
}
示例2: 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)
}
示例3: TestCreateExecute
func TestCreateExecute(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/stacks", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusAccepted)
fmt.Fprintf(w, `{"stack": {"id": "3095aefc-09fb-4bc7-b1f0-f21a304e864c"}}`)
})
cmd := &commandCreate{
Ctx: &handler.Context{
ServiceClient: client.ServiceClient(),
},
}
templateOpts := new(osStacks.Template)
templateOpts.Bin = []byte(`"heat_template_version": "2014-10-16"`)
actual := &handler.Resource{
Params: ¶msCreate{
opts: &osStacks.CreateOpts{
Name: "stack1",
TemplateOpts: templateOpts,
Parameters: map[string]string{
"img": "foo",
"flavor": "bar",
},
},
},
}
cmd.Execute(actual)
th.AssertNoErr(t, actual.Err)
}
示例4: TestDeleteExecute
func TestDeleteExecute(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/container1", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("name", "", "")
flagset.Set("name", "container1")
c := cli.NewContext(app, flagset, nil)
cmd := &commandDelete{
Ctx: &handler.Context{
ServiceClient: client.ServiceClient(),
CLIContext: c,
},
}
actual := &handler.Resource{
Params: ¶msDelete{
container: "container1",
},
}
cmd.Execute(actual)
th.AssertNoErr(t, actual.Err)
}
示例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: 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)
}
示例7: TestListEventsExecute
func TestListEventsExecute(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/stacks/stack1/id1/resources/resource1/events", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, `{"events": [{"event_time": "2014-06-03T20:59:46", "resource_name":"resource1"}]}`)
})
cmd := &commandListEvents{
Ctx: &handler.Context{
ServiceClient: client.ServiceClient(),
},
}
actual := &handler.Resource{
Params: ¶msListEvents{
stackName: "stack1",
stackID: "id1",
resourceName: "resource1",
opts: &osStackEvents.ListResourceEventsOpts{},
},
}
cmd.Execute(actual)
th.AssertNoErr(t, actual.Err)
}
示例8: 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)
}
}
示例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))
}
}
示例10: 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)
}
示例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)
}
}
示例12: tokenPost
func tokenPost(t *testing.T, options gophercloud.AuthOptions, requestJSON string) os.CreateResult {
th.SetupHTTP()
defer th.TeardownHTTP()
os.HandleTokenPost(t, requestJSON)
return Create(client.ServiceClient(), WrapOptions(options))
}
示例13: 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)
}
示例14: TestGetHandleSingle
func TestGetHandleSingle(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()
expected := &handler.Resource{
Params: ¶msGet{
object: "bar",
},
}
actual := &handler.Resource{
Params: ¶msGet{},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsGet).object, actual.Params.(*paramsGet).object)
}
示例15: 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.String("output", "json", "")
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)
}