当前位置: 首页>>代码示例>>Golang>>正文


Golang testhelper.TeardownHTTP函数代码示例

本文整理汇总了Golang中github.com/rackspace/gophercloud/testhelper.TeardownHTTP函数的典型用法代码示例。如果您正苦于以下问题:Golang TeardownHTTP函数的具体用法?Golang TeardownHTTP怎么用?Golang TeardownHTTP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了TeardownHTTP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: TestResizeHandleSingle

func TestResizeHandleSingle(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("id", "", "")
	flagset.Set("id", "server1")
	c := cli.NewContext(app, flagset, nil)
	cmd := &commandResize{
		Ctx: &handler.Context{
			CLIContext:    c,
			ServiceClient: client.ServiceClient(),
		},
	}
	expected := &handler.Resource{
		Params: &paramsResize{
			serverID: "server1",
		},
	}
	actual := &handler.Resource{
		Params: &paramsResize{},
	}
	err := cmd.HandleSingle(actual)
	th.AssertNoErr(t, err)
	th.AssertEquals(t, expected.Params.(*paramsResize).serverID, actual.Params.(*paramsResize).serverID)
}
开发者ID:flazz,项目名称:rack,代码行数:30,代码来源:resize_test.go

示例3: TestBulkDelete

func TestBulkDelete(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "DELETE")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
		th.AssertEquals(t, r.URL.RawQuery, "bulk-delete")

		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, `
      {
        "Number Not Found": 1,
        "Response Status": "200 OK",
        "Errors": [],
        "Number Deleted": 1,
        "Response Body": ""
      }
    `)
	})

	options := DeleteOpts{"gophercloud-testcontainer1", "gophercloud-testcontainer2"}
	actual, err := Delete(fake.ServiceClient(), options).ExtractBody()
	th.AssertNoErr(t, err)
	th.AssertEquals(t, actual.NumberDeleted, 1)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:25,代码来源:requests_test.go

示例4: 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 := ExtractAccessList(page)
		th.AssertNoErr(t, err)

		expected := AccessList{
			NetworkItem{Address: "206.160.163.21", ID: 21, Type: DENY},
			NetworkItem{Address: "206.160.163.22", ID: 22, Type: DENY},
			NetworkItem{Address: "206.160.163.23", ID: 23, Type: DENY},
			NetworkItem{Address: "206.160.163.24", ID: 24, Type: DENY},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, count)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:28,代码来源:requests_test.go

示例5: TestList

func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleList(t)

	expectedDBs := []Database{
		Database{Name: "anotherexampledb"},
		Database{Name: "exampledb"},
		Database{Name: "nextround"},
		Database{Name: "sampledb"},
		Database{Name: "testingdb"},
	}

	pages := 0
	err := List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractDBs(page)
		if err != nil {
			return false, err
		}

		th.CheckDeepEquals(t, expectedDBs, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)

	if pages != 1 {
		t.Errorf("Expected 1 page, saw %d", pages)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:33,代码来源:requests_test.go

示例6: 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: &paramsGenerate{
			opts: &osKeypairs.CreateOpts{
				Name: "keypair1Name",
			},
		},
	}
	cmd.Execute(actual)
	th.AssertNoErr(t, actual.Err)
}
开发者ID:flazz,项目名称:rack,代码行数:27,代码来源:generate_test.go

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: TestAssociateHealthMonitor

func TestAssociateHealthMonitor(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	th.Mux.HandleFunc("/v2.0/lb/pools/332abe93-f488-41ba-870b-2ac66be7f853/health_monitors", 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, "Content-Type", "application/json")
		th.TestHeader(t, r, "Accept", "application/json")
		th.TestJSONRequest(t, r, `
{
   "health_monitor":{
      "id":"b624decf-d5d3-4c66-9a3d-f047e7786181"
   }
}
			`)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusCreated)
		fmt.Fprintf(w, `{}`)
	})

	_, err := AssociateMonitor(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "b624decf-d5d3-4c66-9a3d-f047e7786181").Extract()
	th.AssertNoErr(t, err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:25,代码来源:requests_test.go

示例13: TestGet

func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	HandleGet(t)

	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, []ports.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.DeviceID, "5e3898d7-11be-483e-9732-b2f5eccd2b2e")

	th.AssertEquals(t, n.HostID, "devstack")
	th.AssertEquals(t, n.VNICType, "normal")
	th.AssertEquals(t, n.VIFType, "ovs")
	th.AssertDeepEquals(t, n.VIFDetails, map[string]interface{}{"port_filter": true, "ovs_hybrid_plug": true})
}
开发者ID:sstrato,项目名称:gophercloud,代码行数:28,代码来源:requests_test.go

示例14: TestUpdate

func TestUpdate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	HandleUpdate(t)

	options := UpdateOpts{
		UpdateOptsBuilder: ports.UpdateOpts{
			Name: "new_port_name",
			FixedIPs: []ports.IP{
				{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"},
			},
			SecurityGroups: []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"},
		},
		HostID:   "HOST1",
		VNICType: "normal",
	}

	s, err := Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", options).Extract()
	th.AssertNoErr(t, err)

	th.AssertEquals(t, s.Name, "new_port_name")
	th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{
		{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"},
	})
	th.AssertDeepEquals(t, s.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"})
	th.AssertEquals(t, s.HostID, "HOST1")
	th.AssertEquals(t, s.VNICType, "normal")
}
开发者ID:sstrato,项目名称:gophercloud,代码行数:29,代码来源:requests_test.go

示例15: 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


注:本文中的github.com/rackspace/gophercloud/testhelper.TeardownHTTP函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。