mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-31 05:19:38 +08:00
refactor: move converter from hrp internal to pkg
This commit is contained in:
38
hrp/pkg/httpstat/demo/main_test.go
Normal file
38
hrp/pkg/httpstat/demo/main_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package demo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/httpstat"
|
||||
)
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
var httpStat httpstat.Stat
|
||||
|
||||
req, _ := http.NewRequest("GET", "https://httprunner.com", nil)
|
||||
ctx := httpstat.WithHTTPStat(req, &httpStat)
|
||||
|
||||
client := &http.Client{
|
||||
Timeout: time.Second * 10,
|
||||
}
|
||||
|
||||
req = req.WithContext(ctx)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if resp != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
|
||||
// get stat
|
||||
httpStat.Finish()
|
||||
result := httpStat.Durations()
|
||||
fmt.Println(result)
|
||||
|
||||
// print stat
|
||||
httpStat.Print()
|
||||
}
|
||||
Reference in New Issue
Block a user