|
1 |
| -# go-sdk |
| 1 | +# Keploy Go-SDK |
| 2 | + |
| 3 | +This is the client SDK for Keploy API testing platform. There are 2 modes: |
| 4 | +1. **Capture mode** |
| 5 | + 1. Captures requests, response and all external calls and sends to Keploy server. |
| 6 | + 2. After keploy server removes duplicates, it then runs the request on the API again to identify noisy fields. |
| 7 | + 3. Sends the noisy fields to the keploy server to be saved along with the testcase. |
| 8 | +2. **Test mode** |
| 9 | + 1. Fetches testcases for the app from keploy server. |
| 10 | + 2. Calls the API with same request payload in testcase. |
| 11 | + 3. Mocks external calls based on data stored in the testcase. |
| 12 | + 4. Validates the respones and uploads results to the keploy server |
| 13 | + |
| 14 | + |
| 15 | +## Contents |
| 16 | + |
| 17 | +1. [Installation](#installation) |
| 18 | +2. [Usage](#usage) |
| 19 | +3. [Configure](#configure) |
| 20 | +4. [Supported Routers](#supported-routers) |
| 21 | +5. [Supported Databases](#supported-databases) |
| 22 | +6. [Support Clients](#supported-clients) |
| 23 | + |
| 24 | +## Installation |
| 25 | +```bash |
| 26 | +go get -u github.com/keploy/go-sdk |
| 27 | +``` |
| 28 | +## Usage |
| 29 | + |
| 30 | +```go |
| 31 | +import( |
| 32 | + "github.com/keploy/go-sdk/integrations" |
| 33 | + "github.com/keploy/go-sdk/keploy" |
| 34 | +) |
| 35 | +``` |
| 36 | + |
| 37 | +Create your app instance |
| 38 | +```go |
| 39 | +kApp := keploy.NewApp("<app_name>", "<license_key>", "<keploy_host>", "app_ip_addr", "app_port") |
| 40 | +``` |
| 41 | +For example: |
| 42 | +```go |
| 43 | +kApp := keploy.NewApp("my_app", "adkjhf9adf9adf", "", "0.0.0.0", "8080") |
| 44 | +``` |
| 45 | + |
| 46 | +## Configure |
| 47 | +``` |
| 48 | +export KEPLOY_SDK_MODE="test" |
| 49 | +``` |
| 50 | +### KEPLOY_SDK_MODE |
| 51 | +There are 3 modes: |
| 52 | + - **Capture**: Sets to capture mode. |
| 53 | + - **Test**: Sets to test mode. |
| 54 | + - **Off**: Turns off all the functionality provided by the API |
| 55 | + |
| 56 | +**Note:** `KEPLOY_SDK_MODE` value is case sensitive. |
| 57 | + |
| 58 | +## Supported Routers |
| 59 | +### 1. WebGo |
| 60 | +#### WebGoV4 |
| 61 | +```go |
| 62 | +kApp := keploy.NewApp("my_app", "adkjhf9adf9adf", "", "0.0.0.0", "8080") |
| 63 | +integrations.WebGoV4(kApp, router) |
| 64 | +router.Start() |
| 65 | +``` |
| 66 | +#### WebGoV6 |
| 67 | +```go |
| 68 | +kApp := keploy.NewApp("my_app", "adkjhf9adf9adf", "", "0.0.0.0", "8080") |
| 69 | +integrations.WebGoV6(kApp, router) |
| 70 | +router.Start() |
| 71 | +``` |
| 72 | + |
| 73 | +### 2. Echo |
| 74 | +```go |
| 75 | +e := echo.New() |
| 76 | +kApp := keploy.NewApp("my_app", "adkjhf9adf9adf", "", "0.0.0.0", "8080") |
| 77 | +integrations.EchoV4(kApp, e) |
| 78 | +e.Start(":8080") |
| 79 | +``` |
| 80 | + |
| 81 | +## Supported Databases |
| 82 | +### 1. MongoDB |
| 83 | +```go |
| 84 | +db := client.Database("testDB") |
| 85 | +col := integrations.NewMongoDB(db.Collection("Demo-Collection")) |
| 86 | +``` |
| 87 | +Following operations are supported:<br> |
| 88 | +- FindOne - Err and Decode method of mongo.SingleResult<br> |
| 89 | +- Find - Next and Decode methods of mongo.cursor<br> |
| 90 | +- InsertOne<br> |
| 91 | +- InsertMany<br> |
| 92 | +- UpdateOne<br> |
| 93 | +- UpdateMany<br> |
| 94 | +- DeleteOne<br> |
| 95 | +- DeleteMany |
| 96 | +### 2. DynamoDB |
| 97 | +```go |
| 98 | +client := integrations.NewDynamoDB(dynamodb.New(sess)) |
| 99 | +``` |
| 100 | +Following operations are supported:<br> |
| 101 | +- QueryWithContext |
| 102 | +- GetItemWithContext |
| 103 | +- PutItemWithContext |
| 104 | +## Supported Clients |
| 105 | +### gRPC |
| 106 | +```go |
| 107 | +kApp := keploy.NewApp("my_app", "adkjhf9adf9adf", "", "0.0.0.0", "8080") |
| 108 | +conn, err := grpc.Dial(address, grpc.WithInsecure(), integrations.WithClientUnaryInterceptor(kApp)) |
| 109 | +``` |
| 110 | +Note: Currently streaming is not yet supported. |
0 commit comments