Skip to content

Commit 4e23a91

Browse files
committed
solved 500
1 parent e7ae5c5 commit 4e23a91

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/leodido/go-urn v1.2.0 // indirect
1818
github.com/mattn/go-colorable v0.1.4 // indirect
1919
github.com/mattn/go-isatty v0.0.12 // indirect
20+
github.com/stretchr/testify v1.4.0
2021
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
2122
github.com/valyala/fasttemplate v1.1.0 // indirect
2223
github.com/wuhan-support/shimo-openapi v0.0.0-20200225002748-3bd957c1837c

main.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func main() {
9999
// 返回住宿信息列表
100100
e.GET("/accommodations", func(c echo.Context) error {
101101
fileId := "6c6GKvX83hRCVdG8"
102-
opt := shimo_openapi.Opts{"工作表1", 278, "R", "(", time.Minute * 5}
102+
opt := shimo_openapi.Opts{"main", 278, "R", "(", time.Minute * 5}
103103
message, err := shimoC.GetFileWithOpts(fileId, opt)
104104
if err != nil {
105105
Log.Printf("failed to get document: %v", err)
@@ -111,7 +111,7 @@ func main() {
111111
// 返回心理咨询机构列表
112112
e.GET("/platforms/psychological", func(c echo.Context) error {
113113
fileId := "Dpy6Q668cj3Xx8Rq"
114-
opt := shimo_openapi.Opts{"上线版本", 19, "M", "\n", time.Minute * 30}
114+
opt := shimo_openapi.Opts{"main", 19, "M", "\n", time.Minute * 30}
115115
message, err := shimoC.GetFileWithOpts(fileId, opt)
116116
if err != nil {
117117
Log.Printf("failed to get document: %v", err)
@@ -123,7 +123,7 @@ func main() {
123123
// 返回线上医疗平台列表
124124
e.GET("/platforms/medical", func(c echo.Context) error {
125125
fileId := "kDQJ6vWgWWwq8r8H"
126-
opt := shimo_openapi.Opts{"上线版本", 30, "D", " (", time.Minute * 30}
126+
opt := shimo_openapi.Opts{"main", 30, "D", " (", time.Minute * 30}
127127
message, err := shimoC.GetFileWithOpts(fileId, opt)
128128
if err != nil {
129129
Log.Printf("failed to get document: %v", err)
@@ -135,7 +135,7 @@ func main() {
135135
// 返回医院需求列表
136136
e.GET("/hospital/supplies", func(c echo.Context) error {
137137
fileId := "zN32MwmPjmCLF0Av"
138-
opt := shimo_openapi.Opts{"已合成", 426, "AP", " ", time.Minute * 5}
138+
opt := shimo_openapi.Opts{"main", 426, "AP", " ", time.Minute * 5}
139139
message, err := shimoC.GetFileWithOpts(fileId, opt)
140140
if err != nil {
141141
Log.Printf("failed to get document: %v", err)
@@ -147,7 +147,7 @@ func main() {
147147
// 返回第二版的医院需求列表
148148
e.GET("/hospital/supplies/v2", func(c echo.Context) error {
149149
fileId := "DqpyXVgXCwdvqrht"
150-
opt := shimo_openapi.Opts{"总表", 300, "BR", "----", time.Minute * 30}
150+
opt := shimo_openapi.Opts{"main", 300, "BR", "----", time.Minute * 30}
151151
message, err := shimoC.GetFileWithOpts(fileId, opt)
152152
if err != nil {
153153
Log.Printf("failed to get document: %v", err)
@@ -159,7 +159,7 @@ func main() {
159159
// 返回武汉在外人员住宿信息
160160
e.GET("/people/accommodations", func(c echo.Context) error {
161161
fileId := "DR3OV8MN9yUxFnAB"
162-
opt := shimo_openapi.Opts{"工作表1", 934, "L", " ", time.Hour * 1}
162+
opt := shimo_openapi.Opts{"main", 934, "L", " ", time.Hour * 1}
163163
message, err := shimoC.GetFileWithOpts(fileId, opt)
164164
if err != nil {
165165
Log.Printf("failed to get document: %v", err)
@@ -168,10 +168,10 @@ func main() {
168168
return c.JSONBlob(http.StatusOK, message)
169169
})
170170

171-
// 返回零散信息
171+
// 返回信息看板
172172
e.GET("/wiki/stream", func(c echo.Context) error {
173173
fileId := "XRkgJOMRW0CrFbqM"
174-
opt := shimo_openapi.Opts{"实时", 100, "H", " ", time.Minute * 30}
174+
opt := shimo_openapi.Opts{"main", 100, "H", " ", time.Minute * 30}
175175
message, err := shimoC.GetFileWithOpts(fileId, opt)
176176
if err != nil {
177177
Log.Printf("failed to get document: %v", err)

service_test.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package main
2+
3+
// PLEASE BE AWARE:
4+
// This file is only intended to be using under the assumption of
5+
// the service has been deployed at [http://localhost:80] and not
6+
// intended to be testing right away.
7+
8+
import (
9+
"fmt"
10+
"github.com/labstack/echo"
11+
"net/http"
12+
"testing"
13+
"time"
14+
)
15+
16+
var paths = map[string]string{
17+
"住宿信息列表": "/accommodations",
18+
"心理咨询机构列表": "/platforms/psychological",
19+
"线上医疗平台列表": "/platforms/medical",
20+
//"/hospital/supplies",
21+
"第二版的医院需求列表": "/hospital/supplies/v2",
22+
"武汉在外人员住宿信息": "/people/accommodations",
23+
"信息看板": "/wiki/stream",
24+
"社区物资需求列表": "/community/supplies",
25+
}
26+
27+
var client = http.Client{
28+
Timeout: time.Minute,
29+
}
30+
31+
func TestAll(t *testing.T) {
32+
for name, path := range paths {
33+
t.Logf("> now testing %v (%v)", name, path)
34+
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost%v", path), nil)
35+
if err != nil {
36+
t.Errorf(" failed to initialize request %v (%v): %v", path, name, err)
37+
}
38+
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
39+
40+
resp, err := client.Do(req)
41+
if err != nil {
42+
t.Errorf(" failed to fetch request %v (%v): %v", path, name, err)
43+
}
44+
45+
if resp.StatusCode != http.StatusOK {
46+
t.Errorf(" response not ok for %v (%v): %v", path, name, resp.StatusCode)
47+
} else {
48+
t.Logf(" > PASSED %v (%v) is ok (statuscode=%v)", path, name, resp.StatusCode)
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)