|
1 | | -# flames-library-mockserver-client |
| 1 | +# mockserver-client-go |
2 | 2 |
|
3 | 3 | The mockserver client is a golang client for use with the fantastic http://www.mock-server.com/ HTTP mock server. |
4 | 4 |
|
5 | 5 | Usage: |
6 | | -* Import the library `import "github.com/sandvikcode/flames-library-mockserver-client/pkg/mock"` |
| 6 | +* Import the library `import "github.com/sandvikcode/mockserver-client-go/pkg/mockclient"` |
7 | 7 |
|
8 | | -Example: |
| 8 | +Create an expectation example: |
9 | 9 | ``` |
10 | | -mockServer := mock.Client{ |
| 10 | +mockServer := mockclient.Client{ |
11 | 11 | T: t, |
12 | | - BaseURL: os.Getenv("MOCKSERVER_HOST") |
| 12 | + BaseURL: os.Getenv("MOCKSERVER_HOST"), |
13 | 13 | } |
14 | 14 |
|
15 | 15 | mockServer.AddExpectation( |
16 | | - mock.CreateExpectation( |
17 | | - mock.WhenRequestPath("/(.*)"), |
18 | | - mock.ThenResponseStatus(http.StatusOK), |
| 16 | + mockclient.CreateExpectation( |
| 17 | + mockclient.WhenRequestPath("/(.*)"), |
| 18 | + mockclient.ThenResponseStatus(http.StatusOK), |
19 | 19 | )) |
20 | 20 |
|
21 | 21 | defer mockServer.Clear("/(.*)") |
22 | 22 | ``` |
23 | 23 |
|
| 24 | +Create a verification example: |
| 25 | +``` |
| 26 | +mockServer := mockclient.Client{ |
| 27 | + T: t, |
| 28 | + BaseURL: os.Getenv("MOCKSERVER_HOST"), |
| 29 | +} |
| 30 | +
|
| 31 | +mockServer.AddVerification( |
| 32 | + mockclient.CreateVerification( |
| 33 | + mockclient.WhenRequestPath("/v1/jobs/(.*)"), |
| 34 | + mockclient.ThenAtLeastCalls(2), |
| 35 | + mockclient.ThenAtMostCalls(4), |
| 36 | + )) |
| 37 | +``` |
| 38 | + |
| 39 | +Expectation Defaults: |
| 40 | +* unlimited calls will respond to a match |
| 41 | +* calls are not delayed |
| 42 | +* status of matched calls is 200 OK |
| 43 | + |
| 44 | +Verification Defaults: |
| 45 | +* matched request occurs once i.e. at 1 least call and at most 1 call |
| 46 | + |
24 | 47 | Links: |
25 | 48 | * Expectations - http://www.mock-server.com/mock_server/creating_expectations.html |
26 | 49 | * Verifications - http://www.mock-server.com/mock_server/verification.html |
27 | 50 | * Clearing & Resetting http://www.mock-server.com/mock_server/clearing_and_resetting.html |
| 51 | + |
0 commit comments