forked from quic-go/quic-go
* qlog: implement a Trace and a Writer struct * qlog: rename Trace to FileSeq * split qlog trace writer and QUIC qlog events into separate packages * use the new qlog.Recorder instead of the logging.ConnectionTracer
43 lines
979 B
Go
43 lines
979 B
Go
package qlog
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/quic-go/quic-go/internal/protocol"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestQLOGDIRSet(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
|
|
connID, _ := protocol.GenerateConnectionIDForInitial()
|
|
qlogDir := filepath.Join(tmpDir, "qlogs")
|
|
t.Setenv("QLOGDIR", qlogDir)
|
|
|
|
tracer := DefaultConnectionTracer(context.Background(), true, connID)
|
|
require.NotNil(t, tracer)
|
|
|
|
// adddng and closing a producer makes the tracer close the file
|
|
recorder := tracer.AddProducer()
|
|
recorder.Close()
|
|
|
|
_, err := os.Stat(qlogDir)
|
|
qlogDirCreated := !os.IsNotExist(err)
|
|
require.True(t, qlogDirCreated)
|
|
|
|
entries, err := os.ReadDir(qlogDir)
|
|
require.NoError(t, err)
|
|
require.Len(t, entries, 1)
|
|
}
|
|
|
|
func TestQLOGDIRNotSet(t *testing.T) {
|
|
connID, _ := protocol.GenerateConnectionIDForInitial()
|
|
t.Setenv("QLOGDIR", "")
|
|
|
|
tracer := DefaultConnectionTracer(context.Background(), true, connID)
|
|
require.Nil(t, tracer)
|
|
}
|