-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
56 lines (44 loc) · 1.25 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"encoding/json"
"os"
"github.com/khulnasoft/meshplay/getnighthawk/apinighthawk"
// "fortio.org/fortio/fhttp"
"fortio.org/fortio/periodic"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
func init() {
// Log as JSON instead of the default ASCII formatter.
log.SetFormatter(&log.JSONFormatter{})
// Output to stdout instead of the default stderr
log.SetOutput(os.Stdout)
}
func main() {
// Duration in seconds nighthawk default format
testConfig := &apinighthawk.NighthawkConfig{
Thread: 2,
DurationInSeconds: 5,
QPS: 2,
URL: "https://www.github.com",
}
result, err := apinighthawk.NighthawkRun(testConfig)
if err != nil {
msg := "Failed to run load-test"
err = errors.Wrapf(err, msg)
log.Fatal(err)
}
var result1 periodic.RunnerResults
err = json.Unmarshal(result, &result1)
if err != nil {
err = errors.Wrap(err, "Error while unmarshaling Nighthawk results to the FortioHTTPRunner")
log.Fatal(err)
}
resultsMap := map[string]interface{}{}
err = json.Unmarshal(result, &resultsMap)
if err != nil {
err = errors.Wrap(err, "Error while unmarshaling Nighthawk results to map")
log.Fatal(err)
}
log.Infof("Mapped version of the test: %+#v", resultsMap)
}