Skip to content

Commit

Permalink
add rest unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick0308 committed Mar 9, 2020
1 parent 1829072 commit 3a46e04
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
19 changes: 19 additions & 0 deletions protocol/rest/rest_config_initializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ func TestGetRestConsumerServiceConfig(t *testing.T) {
initConsumerRestConfig()
serviceConfig := GetRestConsumerServiceConfig("UserProvider")
assert.NotEmpty(t, serviceConfig)
assert.NotEmpty(t, serviceConfig.RestMethodConfigsMap)
assert.NotEmpty(t, serviceConfig.RestMethodConfigsMap["GetUser"])
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].QueryParamsMap[1], "userid")
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].HeadersMap[3], "age")
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].PathParamsMap[4], "time")
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].Body, 0)
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].Produces, "application/xml")
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].Consumes, "application/xml")
assert.Equal(t, serviceConfig.Client, "resty1")
}

func TestGetRestProviderServiceConfig(t *testing.T) {
Expand All @@ -44,4 +53,14 @@ func TestGetRestProviderServiceConfig(t *testing.T) {
initProviderRestConfig()
serviceConfig := GetRestProviderServiceConfig("UserProvider")
assert.NotEmpty(t, serviceConfig)
assert.NotEmpty(t, serviceConfig.RestMethodConfigsMap)
assert.NotEmpty(t, serviceConfig.RestMethodConfigsMap["GetUser"])
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].QueryParamsMap[1], "userid")
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].HeadersMap[3], "age")
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].PathParamsMap[4], "time")
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].Body, 0)
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].Produces, "application/xml")
assert.Equal(t, serviceConfig.RestMethodConfigsMap["GetUser"].Consumes, "application/xml")
assert.Equal(t, serviceConfig.Server, "go-restful1")

}
12 changes: 6 additions & 6 deletions protocol/rest/rest_config_reader/testdata/consumer_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ references:
url: "dubbo://127.0.0.1:20000/UserProvider"
cluster: "failover"
timeout: "3s"
rest_client: "resty"
rest_produces: "*/*"
rest_consumes: "*/*"
rest_client: "resty1"
rest_produces: "application/xml"
rest_consumes: "application/xml"
methods :
- name: "GetUser"
retries: "3"
timeout: "5s"
rest_query_params: "1:userid,2:username"
rest_headrs: "3:age"
rest_headers: "3:age"
rest_path_params: "4:time,2:name"
rest_body: 0
rest_produces: "*/*"
rest_consumes: "*/*"
rest_produces: "application/xml"
rest_consumes: "application/xml"

params:
"serviceid":
Expand Down
8 changes: 4 additions & 4 deletions protocol/rest/rest_config_reader/testdata/provider_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ services:
group: "as"
warmup: "100"
cluster: "failover"
rest_server: "go-restful"
rest_server: "go-restful1"
rest_produces: "*/*"
rest_consumes: "*/*"
methods:
Expand All @@ -67,11 +67,11 @@ services:
# the name of RejectedExecutionHandler
execute.limit.rejected.handler: "default"
rest_query_params: "1:userid,2:username"
rest_headrs: "3:age"
rest_headers: "3:age"
rest_path_params: "4:time,2:name"
rest_body: 0
rest_produces: "*/*"
rest_consumes: "*/*"
rest_produces: "application/xml"
rest_consumes: "application/xml"

protocols:
"rest":
Expand Down

0 comments on commit 3a46e04

Please sign in to comment.