Merge branch 'master' into strict-http-status-validate
This commit is contained in:
commit
9ee8c406d3
|
@ -5,13 +5,13 @@ services:
|
|||
|
||||
language: go
|
||||
go:
|
||||
- 1.7
|
||||
- 1.11
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- GO_VERSION=1.7
|
||||
- GO_VERSION=1.6
|
||||
- GO_VERSION=1.5
|
||||
- GO_VERSION=1.11
|
||||
- GO_VERSION=1.10
|
||||
- GO_VERSION=1.9
|
||||
|
||||
cache:
|
||||
directories:
|
||||
|
|
65
Makefile
65
Makefile
|
@ -11,6 +11,7 @@ FILES_TO_RELEASE=$(shell find . -name "*.go" | grep -vE "/vendor/|/test|.*_test.
|
|||
FILES_TO_RELEASE_WITH_VENDOR=$(shell find . -name "*.go" | grep -vE "/test|.*_test.go")
|
||||
LINT_IGNORE_DOC="service\/.*\.go:.+(comment on exported|should have comment or be unexported)"
|
||||
LINT_IGNORE_CONFLICT="service\/.*\.go:.+(type name will be used as)"
|
||||
LINT_IGNORE_METHOD="GetGlobalUniqueId"
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>\` where <target> is one of"
|
||||
|
@ -41,7 +42,7 @@ vet:
|
|||
lint:
|
||||
@echo "golint, skipping vendor packages"
|
||||
@lint=$$(for pkg in ${PKGS_TO_CHECK}; do golint $${pkg}; done); \
|
||||
lint=$$(echo "$${lint}" | grep -vE -e ${LINT_IGNORE_DOC} -e ${LINT_IGNORE_CONFLICT}); \
|
||||
lint=$$(echo "$${lint}" | grep -vE -e ${LINT_IGNORE_DOC} -e ${LINT_IGNORE_CONFLICT} -e ${LINT_IGNORE_METHOD}); \
|
||||
if [[ -n $${lint} ]]; then echo "$${lint}"; exit 1; fi
|
||||
@echo "ok"
|
||||
|
||||
|
@ -97,10 +98,10 @@ unit-race:
|
|||
go test -v -race -cpu=1,2,4 ${PKGS_TO_CHECK}
|
||||
@echo "ok"
|
||||
|
||||
unit-runtime: unit-runtime-go-1.5 unit-runtime-go-1.6 unit-runtime-go-1.7
|
||||
unit-runtime: unit-runtime-go-1.9 unit-runtime-go-1.10 unit-runtime-go-1.11
|
||||
|
||||
export define DOCKERFILE_GO_1_7
|
||||
FROM golang:1.7
|
||||
export define DOCKERFILE_GO_1_11
|
||||
FROM golang:1.11
|
||||
|
||||
ADD . /go/src/github.com/yunify/qingcloud-sdk-go
|
||||
WORKDIR /go/src/github.com/yunify/qingcloud-sdk-go
|
||||
|
@ -108,18 +109,18 @@ WORKDIR /go/src/github.com/yunify/qingcloud-sdk-go
|
|||
CMD ["make", "build", "unit"]
|
||||
endef
|
||||
|
||||
unit-runtime-go-1.7:
|
||||
@echo "run test in go 1.7"
|
||||
echo "$${DOCKERFILE_GO_1_7}" > "dockerfile_go_1.7"
|
||||
docker build -f "./dockerfile_go_1.7" -t "${PREFIX}:go-1.7" .
|
||||
rm -f "./dockerfile_go_1.7"
|
||||
docker run --name "${PREFIX}-go-1.7-unit" -t "${PREFIX}:go-1.7"
|
||||
docker rm "${PREFIX}-go-1.7-unit"
|
||||
docker rmi "${PREFIX}:go-1.7"
|
||||
unit-runtime-go-1.11:
|
||||
@echo "run test in go 1.11"
|
||||
echo "$${DOCKERFILE_GO_1_11}" > "dockerfile_go_1.11"
|
||||
docker build -f "./dockerfile_go_1.11" -t "${PREFIX}:go-1.11" .
|
||||
rm -f "./dockerfile_go_1.11"
|
||||
docker run --name "${PREFIX}-go-1.11-unit" -t "${PREFIX}:go-1.11"
|
||||
docker rm "${PREFIX}-go-1.11-unit"
|
||||
docker rmi "${PREFIX}:go-1.11"
|
||||
@echo "ok"
|
||||
|
||||
export define DOCKERFILE_GO_1_6
|
||||
FROM golang:1.6
|
||||
export define DOCKERFILE_GO_1_10
|
||||
FROM golang:1.10
|
||||
|
||||
ADD . /go/src/github.com/yunify/qingcloud-sdk-go
|
||||
WORKDIR /go/src/github.com/yunify/qingcloud-sdk-go
|
||||
|
@ -127,18 +128,18 @@ WORKDIR /go/src/github.com/yunify/qingcloud-sdk-go
|
|||
CMD ["make", "build", "unit"]
|
||||
endef
|
||||
|
||||
unit-runtime-go-1.6:
|
||||
@echo "run test in go 1.6"
|
||||
echo "$${DOCKERFILE_GO_1_6}" > "dockerfile_go_1.6"
|
||||
docker build -f "./dockerfile_go_1.6" -t "${PREFIX}:go-1.6" .
|
||||
rm -f "./dockerfile_go_1.6"
|
||||
docker run --name "${PREFIX}-go-1.6-unit" -t "${PREFIX}:go-1.6"
|
||||
docker rm "${PREFIX}-go-1.6-unit"
|
||||
docker rmi "${PREFIX}:go-1.6"
|
||||
unit-runtime-go-1.10:
|
||||
@echo "run test in go 1.10"
|
||||
echo "$${DOCKERFILE_GO_1_10}" > "dockerfile_go_1.10"
|
||||
docker build -f "./dockerfile_go_1.10" -t "${PREFIX}:go-1.10" .
|
||||
rm -f "./dockerfile_go_1.10"
|
||||
docker run --name "${PREFIX}-go-1.10-unit" -t "${PREFIX}:go-1.10"
|
||||
docker rm "${PREFIX}-go-1.10-unit"
|
||||
docker rmi "${PREFIX}:go-1.10"
|
||||
@echo "ok"
|
||||
|
||||
export define DOCKERFILE_GO_1_5
|
||||
FROM golang:1.5
|
||||
export define DOCKERFILE_GO_1_9
|
||||
FROM golang:1.9
|
||||
ENV GO15VENDOREXPERIMENT="1"
|
||||
|
||||
ADD . /go/src/github.com/yunify/qingcloud-sdk-go
|
||||
|
@ -147,14 +148,14 @@ WORKDIR /go/src/github.com/yunify/qingcloud-sdk-go
|
|||
CMD ["make", "build", "unit"]
|
||||
endef
|
||||
|
||||
unit-runtime-go-1.5:
|
||||
@echo "run test in go 1.5"
|
||||
echo "$${DOCKERFILE_GO_1_5}" > "dockerfile_go_1.5"
|
||||
docker build -f "./dockerfile_go_1.5" -t "${PREFIX}:go-1.5" .
|
||||
rm -f "./dockerfile_go_1.5"
|
||||
docker run --name "${PREFIX}-go-1.5-unit" -t "${PREFIX}:go-1.5"
|
||||
docker rm "${PREFIX}-go-1.5-unit"
|
||||
docker rmi "${PREFIX}:go-1.5"
|
||||
unit-runtime-go-1.9:
|
||||
@echo "run test in go 1.9"
|
||||
echo "$${DOCKERFILE_GO_1_9}" > "dockerfile_go_1.9"
|
||||
docker build -f "./dockerfile_go_1.9" -t "${PREFIX}:go-1.9" .
|
||||
rm -f "./dockerfile_go_1.9"
|
||||
docker run --name "${PREFIX}-go-1.9-unit" -t "${PREFIX}:go-1.9"
|
||||
docker rm "${PREFIX}-go-1.9-unit"
|
||||
docker rmi "${PREFIX}:go-1.9"
|
||||
@echo "ok"
|
||||
|
||||
test:
|
||||
|
|
|
@ -61,6 +61,9 @@ func (b *Builder) build() (*http.Request, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if b.operation.RequestMethod == "POST" {
|
||||
httpRequest.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
}
|
||||
|
||||
logger.Info(fmt.Sprintf(
|
||||
"Built QingCloud request: [%d] %s \n %s ",
|
||||
|
|
|
@ -135,10 +135,10 @@ func (is *Signer) BuildStringToSignByValues(requestDate string, requestMethod st
|
|||
value = strings.Replace(value, "+", "%20", -1)
|
||||
parts = append(parts, key+"="+value)
|
||||
} else {
|
||||
parts = append(parts, key)
|
||||
parts = append(parts, key+"=")
|
||||
}
|
||||
} else {
|
||||
parts = append(parts, key)
|
||||
parts = append(parts, key+"=")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -102,9 +102,14 @@ func (u *Unpacker) parseError() error {
|
|||
RetCode: int(retCodeValue.Elem().Int()),
|
||||
}
|
||||
if messageValue.IsValid() && messageValue.Type().String() == "*string" {
|
||||
err.Message = messageValue.Elem().String()
|
||||
if messageValue.Elem().IsValid() {
|
||||
err.Message = messageValue.Elem().String()
|
||||
} else {
|
||||
err.Message = "null"
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return fmt.Errorf("invalid retCodeValue %v returned", retCodeValue)
|
||||
}
|
||||
|
|
|
@ -149,3 +149,50 @@ func TestUnpacker_UnpackHTTPRequestWithError(t *testing.T) {
|
|||
assert.Equal(t, e.RetCode, 1400)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnpacker_UnpackHTTPRequestWithWrongType2(t *testing.T) {
|
||||
type DescribeInstanceTypesOutput struct {
|
||||
RetCode *int `json:"ret_code" name:"ret_code"`
|
||||
Message *string `json:"message" name:"message"`
|
||||
}
|
||||
|
||||
httpResponse := &http.Response{Header: http.Header{}}
|
||||
httpResponse.StatusCode = 200
|
||||
httpResponse.Header.Set("Content-Type", "application/json")
|
||||
responseString := `{
|
||||
"message": null,
|
||||
"ret_code":1400
|
||||
}`
|
||||
httpResponse.Body = ioutil.NopCloser(bytes.NewReader([]byte(responseString)))
|
||||
|
||||
output := &DescribeInstanceTypesOutput{}
|
||||
outputValue := reflect.ValueOf(output)
|
||||
unpacker := Unpacker{}
|
||||
err := unpacker.UnpackHTTPRequest(&data.Operation{}, httpResponse, &outputValue)
|
||||
if !assert.NotNil(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
println("err", err.Error())
|
||||
}
|
||||
|
||||
func TestUnpacker_UnpackHTTPRequestWithWrongHTTPStatus(t *testing.T) {
|
||||
type DescribeInstanceTypesOutput struct {
|
||||
RetCode *int `json:"ret_code" name:"ret_code"`
|
||||
Message *string `json:"message" name:"message"`
|
||||
}
|
||||
|
||||
httpResponse := &http.Response{Header: http.Header{}}
|
||||
httpResponse.StatusCode = 500
|
||||
httpResponse.Header.Set("Content-Type", "application/json")
|
||||
responseString := "{}"
|
||||
httpResponse.Body = ioutil.NopCloser(bytes.NewReader([]byte(responseString)))
|
||||
|
||||
output := &DescribeInstanceTypesOutput{}
|
||||
outputValue := reflect.ValueOf(output)
|
||||
unpacker := Unpacker{}
|
||||
err := unpacker.UnpackHTTPRequest(&data.Operation{}, httpResponse, &outputValue)
|
||||
if !assert.NotNil(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
println("err", err.Error())
|
||||
}
|
||||
|
|
|
@ -294,3 +294,45 @@ type DescribeAppsOutput struct {
|
|||
RetCode *int `json:"ret_code" name:"ret_code" location:"elements"`
|
||||
TotalCount *int `json:"total_count" name:"total_count" location:"elements"`
|
||||
}
|
||||
|
||||
// Documentation URL: https://docs.qingcloud.com/api/bot/describe_app_version_attachments.html
|
||||
func (s *AppService) GetGlobalUniqueId(i *GetGlobalUniqueIdInput) (*GetGlobalUniqueIdOutput, error) {
|
||||
if i == nil {
|
||||
i = &GetGlobalUniqueIdInput{}
|
||||
}
|
||||
o := &data.Operation{
|
||||
Config: s.Config,
|
||||
Properties: s.Properties,
|
||||
APIName: "GetGlobalUniqueId",
|
||||
RequestMethod: "GET",
|
||||
}
|
||||
|
||||
x := &GetGlobalUniqueIdOutput{}
|
||||
r, err := request.New(o, i, x)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = r.Send()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return x, err
|
||||
}
|
||||
|
||||
type GetGlobalUniqueIdInput struct {
|
||||
UserID *string `json:"user_id" name:"user_id" location:"params"`
|
||||
}
|
||||
|
||||
func (v *GetGlobalUniqueIdInput) Validate() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type GetGlobalUniqueIdOutput struct {
|
||||
Message *string `json:"message" name:"message"`
|
||||
Action *string `json:"action" name:"action" location:"elements"`
|
||||
RetCode *int `json:"ret_code" name:"ret_code" location:"elements"`
|
||||
UUID *string `json:"uuid" name:"uuid" location:"elements"`
|
||||
}
|
||||
|
|
|
@ -1225,7 +1225,7 @@ type KeyPair struct {
|
|||
Owner *string `json:"owner" name:"owner"`
|
||||
PrivKey *string `json:"priv_key" name:"priv_key"`
|
||||
PubKey *string `json:"pub_key" name:"pub_key"`
|
||||
ResourceIDs *string `json:"resource_ids" name:"resource_ids"`
|
||||
ResourceIDs []*string `json:"resource_ids" name:"resource_ids"`
|
||||
Tags []*Tag `json:"tags" name:"tags"`
|
||||
}
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ type DescribeVolumesInput struct {
|
|||
Tags []*string `json:"tags" name:"tags" location:"params"`
|
||||
// Verbose's available values: 0, 1
|
||||
Verbose *int `json:"verbose" name:"verbose" default:"0" location:"params"`
|
||||
// VolumeType's available values: 0, 1, 2, 3
|
||||
// VolumeType's available values: 0, 1, 2, 3, 5
|
||||
VolumeType *int `json:"volume_type" name:"volume_type" location:"params"`
|
||||
Volumes []*string `json:"volumes" name:"volumes" location:"params"`
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ func (v *DescribeVolumesInput) Validate() error {
|
|||
}
|
||||
|
||||
if v.VolumeType != nil {
|
||||
volumeTypeValidValues := []string{"0", "1", "2", "3"}
|
||||
volumeTypeValidValues := []string{"0", "1", "2", "3", "5"}
|
||||
volumeTypeParameterValue := fmt.Sprint(*v.VolumeType)
|
||||
|
||||
volumeTypeIsValid := false
|
||||
|
|
Loading…
Reference in New Issue