-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathwrapper_test.go
More file actions
54 lines (43 loc) · 1.62 KB
/
Copy pathwrapper_test.go
File metadata and controls
54 lines (43 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package telemetry
import (
"sync"
"testing"
"time"
"github.com/stretchr/testify/suite"
)
// TelemetrySuite is a struct that holds the setup for the telemetry tests.
// It includes a mutex to ensure that tests that depend on the global state
// do not run in parallel, which can cause race conditions and unpredictable results.
type TelemetrySuite struct {
suite.Suite
mu sync.Mutex
}
// SetupTest is called before each test to reset the global state to a known disabled state.
// This ensures each test starts with the telemetry disabled
func (suite *TelemetrySuite) SetupTest() {
initTelemetry(false)
}
// TestNow tests the Now function when telemetry is enabled and disabled.
func (suite *TelemetrySuite) TestNow() {
suite.mu.Lock()
defer suite.mu.Unlock()
initTelemetry(true)
telemetryTime := Now()
suite.NotEqual(time.Time{}, telemetryTime, "Now() should not return zero time when telemetry is enabled")
initTelemetry(false)
telemetryTime = Now()
suite.Equal(time.Time{}, telemetryTime, "Now() should return zero time when telemetry is disabled")
}
// TestIsTelemetryEnabled tests the isTelemetryEnabled function.
func (suite *TelemetrySuite) TestIsTelemetryEnabled() {
suite.mu.Lock()
defer suite.mu.Unlock()
initTelemetry(true)
suite.True(isTelemetryEnabled(), "isTelemetryEnabled() should return true when globalTelemetryEnabled is set to true")
initTelemetry(false)
suite.False(isTelemetryEnabled(), "isTelemetryEnabled() should return false when globalTelemetryEnabled is set to false")
}
// TestTelemetrySuite initiates the test suite.
func TestTelemetrySuite(t *testing.T) {
suite.Run(t, new(TelemetrySuite))
}