-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from vearne/develop
Develop
- Loading branch information
Showing
39 changed files
with
2,921 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
HOST=localhost:8080 | ||
HOST=localhost:8080 | ||
GRPC_SERVER=localhost:50031 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
- id: 1 | ||
desc: "get one book" | ||
request: | ||
address: "{{ GRPC_SERVER }}" | ||
symbol: "Bookstore/GetBook" | ||
body: | | ||
{ | ||
"id": 1 | ||
} | ||
rules: | ||
- name: "GrpcCodeEqualRule" | ||
expected: "OK" | ||
- name: "GrpcBodyEqualRule" | ||
xpath: "/code" | ||
expected: "Success" | ||
- name: "GrpcBodyEqualRule" | ||
xpath: "/data/title" | ||
expected: "The Go Programming Language" | ||
|
||
- id: 2 | ||
desc: "list all books" | ||
request: | ||
address: "{{ GRPC_SERVER }}" | ||
symbol: "Bookstore/ListBook" | ||
body: "{}" | ||
rules: | ||
- name: "GrpcCodeEqualRule" | ||
expected: "OK" | ||
- name: "GrpcBodyEqualRule" | ||
xpath: "/code" | ||
expected: "Success" | ||
- name: "GrpcBodyAtLeastOneRule" | ||
xpath: "//title" | ||
expected: "The Go Programming Language" | ||
|
||
- id: 3 | ||
desc: "add new book" | ||
request: | ||
address: "{{ GRPC_SERVER }}" | ||
symbol: "Bookstore/AddBook" | ||
body: | | ||
{ | ||
"title": "title3", | ||
"author": "author3" | ||
} | ||
rules: | ||
- name: "GrpcCodeEqualRule" | ||
expected: "OK" | ||
- name: "GrpcBodyEqualRule" | ||
xpath: "/code" | ||
expected: "Success" | ||
- name: "GrpcBodyEqualRule" | ||
xpath: "/data/title" | ||
expected: "title3" | ||
export: | ||
xpath: "/data/id" | ||
# Extract the id value and export it to the variable MY_BOOK_ID | ||
exportTo: "MY_BOOK_ID" | ||
# default is string, optional value: integer | string | float | ||
type: integer | ||
|
||
- id: 4 | ||
desc: "get book 3" | ||
dependOnIDs: [3] | ||
request: | ||
address: "{{ GRPC_SERVER }}" | ||
symbol: "Bookstore/GetBook" | ||
body: | | ||
{ | ||
"id": {{ MY_BOOK_ID }} | ||
} | ||
rules: | ||
- name: "GrpcCodeEqualRule" | ||
expected: "OK" | ||
- name: "GrpcBodyEqualRule" | ||
xpath: "/code" | ||
expected: "Success" | ||
- name: "GrpcBodyEqualRule" | ||
xpath: "//title" | ||
expected: "title3" | ||
|
||
- id: 5 | ||
desc: "update book 2" | ||
request: | ||
address: "{{ GRPC_SERVER }}" | ||
symbol: "Bookstore/UpdateBook" | ||
body: | | ||
{ | ||
"id": 2, | ||
"title": "title2-2", | ||
"author": "author2-2" | ||
} | ||
rules: | ||
- name: "GrpcCodeEqualRule" | ||
expected: "OK" | ||
- name: "GrpcBodyEqualRule" | ||
xpath: "/code" | ||
expected: "Success" | ||
- name: "GrpcBodyEqualRule" | ||
xpath: "/data/title" | ||
expected: "title2-2" | ||
|
||
- id: 6 | ||
desc: "get book 2" | ||
delay: 1s | ||
dependOnIDs: [5] | ||
request: | ||
address: "{{ GRPC_SERVER }}" | ||
symbol: "Bookstore/GetBook" | ||
body: | | ||
{ | ||
"id": 2 | ||
} | ||
rules: | ||
- name: "GrpcCodeEqualRule" | ||
expected: "OK" | ||
- name: "GrpcBodyEqualRule" | ||
xpath: "/code" | ||
expected: "Success" | ||
- name: "GrpcBodyEqualRule" | ||
xpath: "/data/title" | ||
expected: "title2-2" | ||
|
||
- id: 7 | ||
desc: "get book 2" | ||
delay: 1s | ||
dependOnIDs: [6] | ||
request: | ||
address: "{{ GRPC_SERVER }}" | ||
symbol: "Bookstore/GetBook" | ||
body: | | ||
{ | ||
"id": 2 | ||
} | ||
rules: | ||
- name: "GrpcCodeEqualRule" | ||
expected: "OK" | ||
- name: "GrpcLuaRule" | ||
lua: | | ||
function verify(r) | ||
local json = require "json"; | ||
local body = json.decode(r:body()); | ||
return body.data.title == "title2-2" and body.data.author == "author2-2"; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# 使用更新的 golang 基础镜像 | ||
FROM golang:1.21 AS builder | ||
|
||
ARG PROJECT="github.com/vearne/autotest/example/grpc_api" | ||
|
||
# Copy代码 | ||
ADD . $GOPATH/src/$PROJECT | ||
# 设置工作目录 | ||
WORKDIR $GOPATH/src/$PROJECT | ||
|
||
# 下载依赖 | ||
RUN go mod download | ||
|
||
# 使用 CGO_DISABLED=0 来构建 Go 二进制文件 | ||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /app/grpcapi . | ||
|
||
# 使用轻量级的 Alpine Linux 基础镜像 | ||
FROM alpine:latest | ||
|
||
# 设置工作目录 | ||
WORKDIR /app | ||
|
||
# 从构建阶段将二进制文件复制到最终镜像中 | ||
COPY --from=builder /app/grpcapi . | ||
|
||
# 暴露应用运行的端口 | ||
EXPOSE 50031 | ||
|
||
# 运行二进制文件 | ||
CMD ["./grpcapi"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
LDFLAGS := -ldflags "-s -w" | ||
IMAGE := woshiaotian/grpcapi:latest | ||
|
||
.PHONY: build | ||
build: | ||
env go build ${LDFLAGS} -o grpcapi ./ | ||
|
||
.PHONY: image-multiple | ||
image-multiple: | ||
docker buildx build -f ./Dockerfile \ | ||
--platform linux/amd64,linux/arm64 --push -t ${IMAGE} . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## generate *.pb.go | ||
``` | ||
protoc --go_out=plugins=grpc:. ./proto/*.proto | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# list | ||
grpcurl --plaintext 127.0.0.1:50031 list | ||
|
||
# describe | ||
grpcurl --plaintext 127.0.0.1:50031 describe | ||
|
||
# add book | ||
grpcurl --plaintext -emit-defaults -d '{"title": "title3","author": "author3"}'\ | ||
127.0.0.1:50031 Bookstore/AddBook | ||
|
||
# delete book | ||
grpcurl --plaintext -emit-defaults -d '{"id": 1}'\ | ||
127.0.0.1:50031 Bookstore/DeleteBook | ||
|
||
# update book | ||
grpcurl --plaintext -emit-defaults -d '{"id":2, "title": "title2-2","author": "author2-2"}'\ | ||
127.0.0.1:50031 Bookstore/UpdateBook | ||
|
||
# list book | ||
grpcurl --plaintext -emit-defaults -d '{}'\ | ||
127.0.0.1:50031 Bookstore/ListBook | ||
|
||
# get book | ||
grpcurl --plaintext -emit-defaults -d '{"id":1}'\ | ||
127.0.0.1:50031 Bookstore/GetBook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module github.com/vearne/autotest/example/grpc_api | ||
|
||
go 1.21.0 | ||
|
||
require ( | ||
golang.org/x/net v0.22.0 // indirect | ||
golang.org/x/sys v0.18.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect | ||
google.golang.org/grpc v1.64.0 // indirect | ||
google.golang.org/protobuf v1.33.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= | ||
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= | ||
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= | ||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= | ||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= | ||
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= | ||
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= | ||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= | ||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= |
Oops, something went wrong.