forked from quic-go/quic-go
use testing.T.Tempdir and Setenv in QLOGDIR integration test (#4868)
This commit is contained in:
@@ -15,15 +15,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestQlogDirEnvironmentVariable(t *testing.T) {
|
func TestQlogDirEnvironmentVariable(t *testing.T) {
|
||||||
originalQlogDirValue := os.Getenv("QLOGDIR")
|
tempDir := t.TempDir()
|
||||||
tempTestDirPath, err := os.MkdirTemp("", "temp_test_dir")
|
qlogDir := path.Join(tempDir, "qlogs")
|
||||||
require.NoError(t, err)
|
t.Setenv("QLOGDIR", qlogDir)
|
||||||
t.Cleanup(func() {
|
|
||||||
require.NoError(t, os.Setenv("QLOGDIR", originalQlogDirValue))
|
|
||||||
require.NoError(t, os.RemoveAll(tempTestDirPath))
|
|
||||||
})
|
|
||||||
qlogDir := path.Join(tempTestDirPath, "qlogs")
|
|
||||||
require.NoError(t, os.Setenv("QLOGDIR", qlogDir))
|
|
||||||
|
|
||||||
serverStopped := make(chan struct{})
|
serverStopped := make(chan struct{})
|
||||||
server, err := quic.Listen(
|
server, err := quic.Listen(
|
||||||
@@ -60,7 +54,7 @@ func TestQlogDirEnvironmentVariable(t *testing.T) {
|
|||||||
server.Close()
|
server.Close()
|
||||||
<-serverStopped
|
<-serverStopped
|
||||||
|
|
||||||
_, err = os.Stat(tempTestDirPath)
|
_, err = os.Stat(qlogDir)
|
||||||
qlogDirCreated := !os.IsNotExist(err)
|
qlogDirCreated := !os.IsNotExist(err)
|
||||||
require.True(t, qlogDirCreated)
|
require.True(t, qlogDirCreated)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user