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


Golang testhelper.TestMethod函数代码示例

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


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

示例1: mockCreateRuleResponse

func mockCreateRuleResponse(t *testing.T) {
	th.Mux.HandleFunc(rootPath, func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "POST")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		th.TestJSONRequest(t, r, `
{
  "security_group_default_rule": {
    "ip_protocol": "TCP",
    "from_port": 80,
    "to_port": 80,
    "cidr": "10.10.12.0/24"
  }
}
	`)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, `
{
  "security_group_default_rule": {
    "from_port": 80,
    "id": "{ruleID}",
    "ip_protocol": "TCP",
    "ip_range": {
      "cidr": "10.10.12.0/24"
    },
    "to_port": 80
  }
}
`)
	})
}
开发者ID:johndmulhausen,项目名称:kubernetes,代码行数:34,代码来源:fixtures.go

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

示例3: MockDeleteUserRoleResponse

func MockDeleteUserRoleResponse(t *testing.T) {
	th.Mux.HandleFunc("/users/{user_id}/roles/OS-KSADM/{role_id}", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "DELETE")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
		w.WriteHeader(http.StatusNoContent)
	})
}
开发者ID:sstrato,项目名称:gophercloud,代码行数:7,代码来源:fixtures.go

示例4: HandleDeleteCDNAssetSuccessfully

// HandleDeleteCDNAssetSuccessfully creates an HTTP handler at `/services/{id}/assets` on the test handler mux
// that responds with a `Delete` response.
func HandleDeleteCDNAssetSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0/assets", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "DELETE")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
		w.WriteHeader(http.StatusAccepted)
	})
}
开发者ID:DSpeichert,项目名称:gophercloud,代码行数:9,代码来源:fixtures.go

示例5: HandleImageMemberList

// HandleImageMemberList happy path setup
func HandleImageMemberList(t *testing.T) {
	th.Mux.HandleFunc("/images/da3b75d9-3f4a-40e7-8a2c-bfab23927dea/members", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID)

		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, `{
		    "members": [
		        {
		            "created_at": "2013-10-07T17:58:03Z",
		            "image_id": "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
		            "member_id": "123456789",
		            "schema": "/v2/schemas/member",
		            "status": "pending",
		            "updated_at": "2013-10-07T17:58:03Z"
		        },
		        {
		            "created_at": "2013-10-07T17:58:55Z",
		            "image_id": "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
		            "member_id": "987654321",
		            "schema": "/v2/schemas/member",
		            "status": "accepted",
		            "updated_at": "2013-10-08T12:08:55Z"
		        }
		    ],
		    "schema": "/v2/schemas/members"
		}`)
	})
}
开发者ID:rackspace,项目名称:gophercloud,代码行数:30,代码来源:fixtures.go

示例6: mockAddRuleResponseICMPZero

func mockAddRuleResponseICMPZero(t *testing.T) {
	th.Mux.HandleFunc("/os-security-group-rules", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "POST")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		th.TestJSONRequest(t, r, `
{
  "security_group_rule": {
    "from_port": 0,
    "ip_protocol": "ICMP",
    "to_port": 0,
    "parent_group_id": "{groupID}",
    "cidr": "0.0.0.0/0"
  }
}	`)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, `
{
  "security_group_rule": {
    "from_port": 0,
    "group": {},
    "ip_protocol": "ICMP",
    "to_port": 0,
    "parent_group_id": "{groupID}",
    "ip_range": {
      "cidr": "0.0.0.0/0"
    },
    "id": "{ruleID}"
  }
}`)
	})
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:35,代码来源:fixtures.go

示例7: mockCreateResponse

func mockCreateResponse(t *testing.T, lbID int) {
	th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "POST")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		th.TestJSONRequest(t, r, `
{
    "type":"PUBLIC",
    "ipVersion":"IPV6"
}
    `)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusAccepted)

		fmt.Fprintf(w, `
{
    "address":"fd24:f480:ce44:91bc:1af2:15ff:0000:0002",
    "id":9000134,
    "type":"PUBLIC",
    "ipVersion":"IPV6"
}
  `)
	})
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:25,代码来源:fixtures.go

示例8: HandleListObjectsInfoSuccessfully

// HandleListObjectsInfoSuccessfully creates an HTTP handler at `/testContainer` on the test handler mux that
// responds with a `List` response when full info is requested.
func HandleListObjectsInfoSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
		th.TestHeader(t, r, "Accept", "application/json")

		w.Header().Set("Content-Type", "application/json")
		r.ParseForm()
		marker := r.Form.Get("marker")
		switch marker {
		case "":
			fmt.Fprintf(w, `[
      {
        "hash": "451e372e48e0f6b1114fa0724aa79fa1",
        "last_modified": "2009-11-10 23:00:00 +0000 UTC",
        "bytes": 14,
        "name": "goodbye",
        "content_type": "application/octet-stream"
      },
      {
        "hash": "451e372e48e0f6b1114fa0724aa79fa1",
        "last_modified": "2009-11-10 23:00:00 +0000 UTC",
        "bytes": 14,
        "name": "hello",
        "content_type": "application/octet-stream"
      }
    ]`)
		case "hello":
			fmt.Fprintf(w, `[]`)
		default:
			t.Fatalf("Unexpected marker: [%s]", marker)
		}
	})
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:36,代码来源:fixtures.go

示例9: MockGetResponse

func MockGetResponse(t *testing.T) {
	th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, `
{
    "volume": {
        "display_name": "vol-001",
        "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
 	"attachments": [
	  {
            "device": "/dev/vde",
            "server_id": "a740d24b-dc5b-4d59-ac75-53971c2920ba",
            "id": "d6da11e5-2ed3-413e-88d8-b772ba62193d",
            "volume_id": "d6da11e5-2ed3-413e-88d8-b772ba62193d"
          }
        ]
   }
}
      `)
	})
}
开发者ID:sstrato,项目名称:gophercloud,代码行数:25,代码来源:fixtures.go

示例10: mockGetStatsResponse

func mockGetStatsResponse(t *testing.T, id int) {
	th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/stats", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, `
{
  "connectTimeOut": 10,
  "connectError": 20,
  "connectFailure": 30,
  "dataTimedOut": 40,
  "keepAliveTimedOut": 50,
  "maxConn": 60,
  "currentConn": 40,
  "connectTimeOutSsl": 10,
  "connectErrorSsl": 20,
  "connectFailureSsl": 30,
  "dataTimedOutSsl": 40,
  "keepAliveTimedOutSsl": 50,
  "maxConnSsl": 60,
  "currentConnSsl": 40
}
			`)
	})
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:28,代码来源:fixtures.go

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

示例12: mockDeleteErrorPageResponse

func mockDeleteErrorPageResponse(t *testing.T, id int) {
	th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/errorpage", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "DELETE")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
		w.WriteHeader(http.StatusOK)
	})
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:7,代码来源:fixtures.go

示例13: mockListAlgorithmsResponse

func mockListAlgorithmsResponse(t *testing.T) {
	th.Mux.HandleFunc("/loadbalancers/algorithms", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, `
{
  "algorithms": [
    {
      "name": "LEAST_CONNECTIONS"
    },
    {
      "name": "RANDOM"
    },
    {
      "name": "ROUND_ROBIN"
    },
    {
      "name": "WEIGHTED_LEAST_CONNECTIONS"
    },
    {
      "name": "WEIGHTED_ROUND_ROBIN"
    }
  ]
}
			`)
	})
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:31,代码来源:fixtures.go

示例14: HandleListExtensionsSuccessfully

// HandleListExtensionsSuccessfully creates an HTTP handler that returns ListOutput for a List
// call.
func HandleListExtensionsSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/extensions", 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")

		fmt.Fprintf(w, `
{
  "extensions": {
    "values": [
      {
        "updated": "2013-01-20T00:00:00-00:00",
        "name": "Neutron Service Type Management",
        "links": [],
        "namespace": "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
        "alias": "service-type",
        "description": "API for retrieving service providers for Neutron advanced services"
      }
    ]
  }
}
    `)
	})

}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:28,代码来源:fixtures.go

示例15: mockDisableResponse

func mockDisableResponse(t *testing.T, lbID int) {
	th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "DELETE")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
		w.WriteHeader(http.StatusAccepted)
	})
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:7,代码来源:fixtures.go


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