github.com/msales/pkg/v3@v3.24.0/clix/profiler_test.go (about) 1 package clix_test 2 3 import ( 4 "net" 5 "testing" 6 "time" 7 8 "github.com/msales/pkg/v3/clix" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestRunProfiler_Enabled(t *testing.T) { 13 c, fs := newTestContext() 14 fs.Bool(clix.FlagProfiler, true, "doc") 15 fs.String(clix.FlagProfilerPort, "62874", "doc") 16 17 clix.RunProfiler(c) 18 defer clix.StopProfiler() 19 20 time.Sleep(10 * time.Millisecond) 21 22 conn, err := net.DialTimeout("tcp", ":62874", time.Second) 23 assert.NoError(t, err) 24 25 if err == nil { 26 conn.Close() 27 } 28 } 29 30 func TestRunProfiler_Disabled(t *testing.T) { 31 c, _ := newTestContext() 32 33 clix.RunProfiler(c) 34 35 _, err := net.DialTimeout("tcp", ":62874", time.Second) 36 37 assert.Error(t, err) 38 }