github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/qlog/qlog_suite_test.go (about) 1 package qlog 2 3 import ( 4 "encoding/json" 5 "os" 6 "strconv" 7 "testing" 8 "time" 9 10 . "github.com/onsi/ginkgo/v2" 11 . "github.com/onsi/gomega" 12 ) 13 14 func TestQlog(t *testing.T) { 15 RegisterFailHandler(Fail) 16 RunSpecs(t, "qlog Suite") 17 } 18 19 //nolint:unparam 20 func scaleDuration(t time.Duration) time.Duration { 21 scaleFactor := 1 22 if f, err := strconv.Atoi(os.Getenv("TIMESCALE_FACTOR")); err == nil { // parsing "" errors, so this works fine if the env is not set 23 scaleFactor = f 24 } 25 Expect(scaleFactor).ToNot(BeZero()) 26 return time.Duration(scaleFactor) * t 27 } 28 29 func checkEncoding(data []byte, expected map[string]interface{}) { 30 // unmarshal the data 31 m := make(map[string]interface{}) 32 ExpectWithOffset(2, json.Unmarshal(data, &m)).To(Succeed()) 33 ExpectWithOffset(2, m).To(HaveLen(len(expected))) 34 for key, value := range expected { 35 switch v := value.(type) { 36 case bool, string, map[string]interface{}: 37 ExpectWithOffset(1, m).To(HaveKeyWithValue(key, v)) 38 case int: 39 ExpectWithOffset(1, m).To(HaveKeyWithValue(key, float64(v))) 40 case [][]float64: // used in the ACK frame 41 ExpectWithOffset(1, m).To(HaveKey(key)) 42 for i, l := range v { 43 for j, s := range l { 44 ExpectWithOffset(1, m[key].([]interface{})[i].([]interface{})[j].(float64)).To(Equal(s)) 45 } 46 } 47 default: 48 Fail("unexpected type") 49 } 50 } 51 }