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


Golang testhelper.TestMethod函数代码示例

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


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

示例1: TestUpdateSuccessful

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

	th.Mux.HandleFunc("/services/12345", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "PATCH")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
		th.TestJSONRequest(t, r, `{ "type": "lasermagic" }`)

		w.Header().Add("Content-Type", "application/json")
		fmt.Fprintf(w, `
			{
				"service": {
						"id": "12345",
						"type": "lasermagic"
				}
			}
		`)
	})

	expected := &services.Service{
		ID:   "12345",
		Type: "lasermagic",
	}

	actual, err := services.Update(client.ServiceClient(), "12345", "lasermagic").Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, expected, actual)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:requests_test.go

示例2: MockDeleteResponse

func MockDeleteResponse(t *testing.T) {
	th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", 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:jrperritt,项目名称:gophercloud-1,代码行数:7,代码来源:fixtures.go

示例3: mockCreateRuleResponseICMPZero

func mockCreateRuleResponseICMPZero(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": "ICMP",
    "from_port": 0,
    "to_port": 0,
    "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": 0,
    "id": "{ruleID}",
    "ip_protocol": "ICMP",
    "ip_range": {
      "cidr": "10.10.12.0/24"
    },
    "to_port": 0
  }
}
`)
	})
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:34,代码来源:fixtures.go

示例4: mockDeleteUserResponse

func mockDeleteUserResponse(t *testing.T) {
	th.Mux.HandleFunc("/users/c39e3de9be2d4c779f1dfd6abacc176d", 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:jrperritt,项目名称:gophercloud-1,代码行数:7,代码来源:fixtures.go

示例5: MockGetDefaultResponse

func MockGetDefaultResponse(t *testing.T) {
	th.Mux.HandleFunc("/types/default", 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_type": {
                "required_extra_specs": null,
                "extra_specs": {
                    "snapshot_support": "True",
                    "driver_handles_share_servers": "True"
                },
                "name": "default",
                "id": "be27425c-f807-4500-a056-d00721db45cf"
            },
            "share_type": {
                "required_extra_specs": null,
                "extra_specs": {
                    "snapshot_support": "True",
                    "driver_handles_share_servers": "True"
                },
                "name": "default",
                "id": "be27425c-f807-4500-a056-d00721db45cf"
            }
        }`)
	})
}
开发者ID:gophercloud,项目名称:gophercloud,代码行数:30,代码来源:fixtures.go

示例6: MockGetResponse

func MockGetResponse(t *testing.T) {
	th.Mux.HandleFunc("/share-networks/7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd", 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, `
        {
            "share_network": {
                "name": "net_my1",
                "segmentation_id": null,
                "created_at": "2015-09-04T14:56:45.000000",
                "neutron_subnet_id": "53482b62-2c84-4a53-b6ab-30d9d9800d06",
                "updated_at": null,
                "id": "7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd",
                "neutron_net_id": "998b42ee-2cee-4d36-8b95-67b5ca1f2109",
                "ip_version": null,
                "nova_net_id": null,
                "cidr": null,
                "project_id": "16e1ab15c35a457e9c2b2aa189f544e1",
                "network_type": null,
                "description": "descr"
            }
        }`)
	})
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:27,代码来源:fixtures.go

示例7: TestFetch

// test the fetch function
func TestFetch(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	baseurl, err := getBasePath()
	th.AssertNoErr(t, err)
	fakeURL := strings.Join([]string{baseurl, "file.yaml"}, "/")
	urlparsed, err := url.Parse(fakeURL)
	th.AssertNoErr(t, err)

	th.Mux.HandleFunc(urlparsed.Path, func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		w.Header().Set("Content-Type", "application/jason")
		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, "Fee-fi-fo-fum")
	})

	client := fakeClient{BaseClient: getHTTPClient()}
	te := TE{
		URL:    "file.yaml",
		client: client,
	}
	err = te.Fetch()
	th.AssertNoErr(t, err)
	th.AssertEquals(t, fakeURL, te.URL)
	th.AssertEquals(t, "Fee-fi-fo-fum", string(te.Bin))
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:27,代码来源:utils_test.go

示例8: TestGet

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

	th.Mux.HandleFunc("/networks/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, `
{
    "network": {
        "admin_state_up": true,
        "id": "8d05a1b1-297a-46ca-8974-17debf51ca3c",
        "name": "ext_net",
        "router:external": true,
        "shared": false,
        "status": "ACTIVE",
        "subnets": [
            "2f1fb918-9b0e-4bf9-9a50-6cebbb4db2c5"
        ],
        "tenant_id": "5eb8995cf717462c9df8d1edfa498010"
    }
}
			`)
	})

	res := networks.Get(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
	n, err := external.ExtractGet(res)

	th.AssertNoErr(t, err)
	th.AssertEquals(t, true, n.External)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:35,代码来源:results_test.go

示例9: 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.Header().Add("Content-Type", "application/json")
		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:jrperritt,项目名称:gophercloud-1,代码行数:30,代码来源:fixtures.go

示例10: TestGet

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

	th.Mux.HandleFunc("/v2.0/extensions/agent", 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, `
{
    "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 := extensions.Get(fake.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:jrperritt,项目名称:gophercloud-1,代码行数:34,代码来源:delegate_test.go

示例11: 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:jrperritt,项目名称:gophercloud-1,代码行数:28,代码来源:fixtures.go

示例12: MockCreateResponse

func MockCreateResponse(t *testing.T) {
	th.Mux.HandleFunc("/volumes", 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, `
{
    "volume": {
        "size": 75
    }
}
      `)

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

		fmt.Fprintf(w, `
{
    "volume": {
        "size": 4,
        "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
    }
}
    `)
	})
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:27,代码来源:fixtures.go

示例13: MockTerminateConnectionResponse

func MockTerminateConnectionResponse(t *testing.T) {
	th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
		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, `
{
    "os-terminate_connection":
    {
        "connector":
        {
        "ip":"127.0.0.1",
        "host":"stack",
        "initiator":"iqn.1994-05.com.redhat:17cf566367d2",
        "multipath": true,
        "platform": "x86_64",
        "os_type": "linux2"
        }
    }
}
          `)

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

			fmt.Fprintf(w, `{}`)
		})
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:30,代码来源:fixtures.go

示例14: HandleGetSuccessfully

// HandleGetSuccessfully creates an HTTP handler at `/` on the test handler mux
// that responds with a `Get` response.
func HandleGetSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/", 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.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, `
    {
        "resources": {
            "rel/cdn": {
                "href-template": "services{?marker,limit}",
                "href-vars": {
                    "marker": "param/marker",
                    "limit": "param/limit"
                },
                "hints": {
                    "allow": [
                        "GET"
                    ],
                    "formats": {
                        "application/json": {}
                    }
                }
            }
        }
    }
    `)

	})
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:32,代码来源:fixtures.go

示例15: 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": "2016-08-17T22:11:58.602650",
        "bytes": 14,
        "name": "goodbye",
        "content_type": "application/octet-stream"
      },
      {
        "hash": "451e372e48e0f6b1114fa0724aa79fa1",
        "last_modified": "2016-08-17T22:11:58.602650",
        "bytes": 14,
        "name": "hello",
        "content_type": "application/octet-stream"
      }
    ]`)
		case "hello":
			fmt.Fprintf(w, `[]`)
		default:
			t.Fatalf("Unexpected marker: [%s]", marker)
		}
	})
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:36,代码来源:fixtures.go


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