github.com/diamondo25/ghz@v0.12.0/reporter_test.go (about)

     1  package ghz
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestReport_MarshalJSON(t *testing.T) {
    12  	z, _ := time.Parse(time.RFC822Z, "02 Jan 06 15:04 -0700")
    13  	r := &Report{
    14  		Date:    z,
    15  		Count:   1000,
    16  		Total:   time.Duration(10) * time.Second,
    17  		Average: time.Duration(500) * time.Millisecond,
    18  		Fastest: time.Duration(10) * time.Millisecond,
    19  		Slowest: time.Duration(1000) * time.Millisecond,
    20  		Rps:     34567.89,
    21  	}
    22  
    23  	json, err := json.Marshal(&r)
    24  	assert.NoError(t, err)
    25  
    26  	expected := `{"date":"2006-01-02T15:04:00-07:00","count":1000,"total":10000000000,"average":500000000,"fastest":10000000,"slowest":1000000000,"rps":34567.89,"errorDistribution":null,"statusCodeDistribution":null,"latencyDistribution":null,"histogram":null,"details":null}`
    27  	assert.Equal(t, expected, string(json))
    28  }