Skip to content

Commit 8d82933

Browse files
committed
update fixed status code issue
1 parent 08eae68 commit 8d82933

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

coverage.out

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
mode: set
2-
github.com/GolangToolKits/go-http-proxy/goProxy.go:15.62,20.16 5 1
3-
github.com/GolangToolKits/go-http-proxy/goProxy.go:20.16,24.3 3 1
4-
github.com/GolangToolKits/go-http-proxy/goProxy.go:24.8,28.19 4 1
5-
github.com/GolangToolKits/go-http-proxy/goProxy.go:28.19,31.4 2 1
6-
github.com/GolangToolKits/go-http-proxy/goProxy.go:31.9,34.4 2 1
7-
github.com/GolangToolKits/go-http-proxy/goProxy.go:36.2,36.24 1 1
8-
github.com/GolangToolKits/go-http-proxy/goProxy.go:40.31,42.2 1 1
2+
github.com/GolangToolKits/go-http-proxy/goProxy.go:15.62,20.52 5 1
3+
github.com/GolangToolKits/go-http-proxy/goProxy.go:20.52,23.18 3 1
4+
github.com/GolangToolKits/go-http-proxy/goProxy.go:23.18,25.4 1 1
5+
github.com/GolangToolKits/go-http-proxy/goProxy.go:25.9,27.4 1 1
6+
github.com/GolangToolKits/go-http-proxy/goProxy.go:28.8,32.19 4 1
7+
github.com/GolangToolKits/go-http-proxy/goProxy.go:32.19,35.4 2 1
8+
github.com/GolangToolKits/go-http-proxy/goProxy.go:35.9,38.4 2 1
9+
github.com/GolangToolKits/go-http-proxy/goProxy.go:40.2,40.24 1 1
10+
github.com/GolangToolKits/go-http-proxy/goProxy.go:44.31,46.2 1 1
911
github.com/GolangToolKits/go-http-proxy/mockGoProxy.go:17.66,21.18 4 1
1012
github.com/GolangToolKits/go-http-proxy/mockGoProxy.go:21.18,25.3 3 1
1113
github.com/GolangToolKits/go-http-proxy/mockGoProxy.go:26.2,26.41 1 1

goProxy.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ func (p *GoProxy) Do(req *http.Request, obj any) (bool, int) {
1717
var statusCode int
1818
client := &http.Client{}
1919
resp, err := client.Do(req)
20-
if err != nil {
20+
if err != nil || resp.StatusCode != http.StatusOK {
2121
log.Println("go-http-proxy Do err: ", err)
2222
log.Println("resp in fail: ", resp)
23-
statusCode = http.StatusNotFound
23+
if resp != nil {
24+
statusCode = resp.StatusCode
25+
} else {
26+
statusCode = http.StatusNotFound
27+
}
2428
} else {
2529
defer resp.Body.Close()
2630
decoder := json.NewDecoder(resp.Body)

goProxy_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestGoProxy_New(t *testing.T) {
4747
func TestGoProxy_Do(t *testing.T) {
4848

4949
var sURL = "http://localhost:3002/rs/product/get/list/59/0/100"
50+
var sURL4 = "http://localhost:3002/rs/product2/get/list/59/0/100"
5051

5152
r1, rErr := http.NewRequest("GET", sURL, nil)
5253
if rErr != nil {
@@ -58,6 +59,15 @@ func TestGoProxy_Do(t *testing.T) {
5859

5960
r2, _ := http.NewRequest("GET", "http:///", nil)
6061

62+
63+
r4, rErr4 := http.NewRequest("GET", sURL4, nil)
64+
if rErr4 != nil {
65+
fmt.Println("request error: ", rErr4)
66+
}
67+
r4.Header.Set("Content-Type", "application/json")
68+
r4.Header.Set("apiKey", "GDG651GFD66FD16151sss651f651ff65555ddfhjklyy5")
69+
r4.Header.Set("storeName", "defaultLocalStore")
70+
6171
var uRes []prod
6272

6373
type args struct {
@@ -99,6 +109,15 @@ func TestGoProxy_Do(t *testing.T) {
99109
want: false,
100110
want1: 0,
101111
},
112+
{
113+
name: "test 4",
114+
args: args{
115+
req: r4,
116+
obj: uRes, //non pointer fail
117+
},
118+
want: false,
119+
want1: 404,
120+
},
102121
}
103122
for _, tt := range tests {
104123
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)