Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fate0 committed May 31, 2020
1 parent ba84934 commit 2d75e69
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ Starting Load Test with 1000 requests using 10 concurrent users

```

示例:指定自定义 ca 证书
```bash
$ ./cassowary run -u http://localhost:8000 -c 10 -n 1000 --ca /path/to/ca.pem

Starting Load Test with 1000 requests using 10 concurrent users

[ omitted for brevity ]

```

示例:指定客户端证书信息
```bash
$ ./cassowary run -u http://localhost:8000 -c 10 -n 1000 --cert /path/to/client.pem --key /path/to/client-key.pem

Starting Load Test with 1000 requests using 10 concurrent users

[ omitted for brevity ]

```


**以模块或者library导入Cassowary**

Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,30 @@ Starting Load Test with 1000 requests using 10 concurrent users

```

### Specifying ca certificate
Example specifying ca certificate

```bash
$ ./cassowary run -u http://localhost:8000 -c 10 -n 1000 --ca /path/to/ca.pem

Starting Load Test with 1000 requests using 10 concurrent users

[ omitted for brevity ]

```

### Specifying client authentication certificate
Example specifying client authentication certificate

```bash
$ ./cassowary run -u http://localhost:8000 -c 10 -n 1000 --cert /path/to/client.pem --key /path/to/client-key.pem

Starting Load Test with 1000 requests using 10 concurrent users

[ omitted for brevity ]

```

Importing cassowary as a module/library
--------

Expand Down
62 changes: 62 additions & 0 deletions docs/LIBRARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,65 @@ func main() {
fmt.Println(string(jsonMetrics))
}
```

**Example 3: Custom TLS config**

```go
package main

import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"

cassowary "github.com/rogerwelin/cassowary/pkg/client"
)

func main() {
pemCerts, err := ioutil.ReadFile("testdata/ca.pem")
if err != nil {
panic("Invalid ca.pem path")
}

ca := x509.NewCertPool()
if !ca.AppendCertsFromPEM(pemCerts) {
panic("Failed to read CA from PEM")
}

cert, err := tls.LoadX509KeyPair("testdata/client.pem", "testdata/client-key.pem")
if err != nil {
panic("Invalid client.pem/client-key.pem path")
}

clientTLSConfig := &tls.Config{
RootCAs: ca,
Certificates: []tls.Certificate{cert},
}

cass := &cassowary.Cassowary{
BaseURL: "http://www.example.com",
ConcurrencyLevel: 1,
Requests: 10,
TLSConfig: clientTLSConfig,
DisableTerminalOutput: true,
}
metrics, err := cass.Coordinate()
if err != nil {
panic(err)
}

// print results
fmt.Printf("%+v\n", metrics)

// or print as json
jsonMetrics, err := json.Marshal(metrics)
if err != nil {
panic(err)
}

fmt.Println(string(jsonMetrics))
}

```

0 comments on commit 2d75e69

Please sign in to comment.