This repository was archived by the owner on Aug 7, 2022. It is now read-only.
File tree 1 file changed +46
-0
lines changed
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ # HTTP Server mocking for Go
2
+
3
+ [ ![ CI] ( https://github.com/mockingio/go/actions/workflows/main.yml/badge.svg )] ( https://github.com/mockingio/engine/actions/workflows/main.yml )
4
+ [ ![ codecov] ( https://codecov.io/gh/mockingio/go/branch/main/graph/badge.svg?token=0AXGI7UR85 )] ( https://codecov.io/gh/mockingio/go )
5
+ [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/mockingio/go )] ( https://goreportcard.com/report/github.com/mockingio/go )
6
+ [ ![ License] ( https://img.shields.io/badge/License-Apache_2.0-blue.svg )] ( https://opensource.org/licenses/Apache-2.0 )
7
+
8
+ ### Go package usage
9
+
10
+ ``` go
11
+ import (
12
+ " net/http"
13
+ " testing"
14
+
15
+ mock " github.com/mockingio/go"
16
+ )
17
+
18
+ func Test_Example (t *testing .T ) {
19
+ srv := mock.
20
+ New ().
21
+ Get (" /hello" ).
22
+ Response (http.StatusOK , " hello world" ).
23
+ Start (t)
24
+ defer srv.Close ()
25
+
26
+ req , _ := http.NewRequest (" GET" , srv.URL , nil )
27
+ client := &http.Client {}
28
+
29
+ resp , err := client.Do (req)
30
+ }
31
+
32
+ func Test_Example_WithRules (t *testing .T ) {
33
+ srv := mock.
34
+ New ().
35
+ Get (" /hello" ).
36
+ When (" cookie" , " name" , " equal" , " Chocolate" ).
37
+ Response (http.StatusOK , " hello world" ).
38
+ Start (t)
39
+ defer srv.Close ()
40
+
41
+ req , _ := http.NewRequest (" GET" , srv.URL , nil )
42
+ client := &http.Client {}
43
+
44
+ resp , err := client.Do (req)
45
+ }
46
+ ```
You can’t perform that action at this time.
0 commit comments