From 2d75e69cd546c0900d7f447ffdc9f97b88d46485 Mon Sep 17 00:00:00 2001 From: fate0 Date: Sun, 31 May 2020 13:57:46 +0800 Subject: [PATCH] add docs --- README-ZH.md | 20 ++++++++++++++++ README.md | 24 +++++++++++++++++++ docs/LIBRARY.md | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/README-ZH.md b/README-ZH.md index d265c31..e187fa9 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -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** diff --git a/README.md b/README.md index 4b1b4e5..92bbeb5 100644 --- a/README.md +++ b/README.md @@ -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 -------- diff --git a/docs/LIBRARY.md b/docs/LIBRARY.md index 12a9420..bef9977 100644 --- a/docs/LIBRARY.md +++ b/docs/LIBRARY.md @@ -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)) +} + +``` \ No newline at end of file