2025-06-30 09:47:14 +05:30
|
|
|
package analytics
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-04-22 22:04:56 +05:30
|
|
|
"github.com/safedep/pmg/config"
|
2025-06-30 09:47:14 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
2026-05-19 14:40:54 +05:30
|
|
|
"github.com/stretchr/testify/require"
|
2025-06-30 09:47:14 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestIsDisabled(t *testing.T) {
|
|
|
|
|
t.Run("returns true if PMG_DISABLE_TELEMETRY is set to true", func(t *testing.T) {
|
2026-05-19 14:40:54 +05:30
|
|
|
require.NoError(t, os.Setenv(telemetryDisableEnvKey, "true"))
|
|
|
|
|
defer func() {
|
|
|
|
|
require.NoError(t, os.Unsetenv(telemetryDisableEnvKey))
|
|
|
|
|
}()
|
2025-06-30 09:47:14 +05:30
|
|
|
|
|
|
|
|
assert.True(t, IsDisabled())
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("returns false if PMG_DISABLE_TELEMETRY is not set", func(t *testing.T) {
|
2026-04-22 22:04:56 +05:30
|
|
|
config.Get().Config.DisableTelemetry = false
|
2025-06-30 09:47:14 +05:30
|
|
|
assert.False(t, IsDisabled())
|
|
|
|
|
})
|
2026-04-22 22:04:56 +05:30
|
|
|
|
|
|
|
|
t.Run("returns true if telemetry is disabled in config", func(t *testing.T) {
|
|
|
|
|
config.Get().Config.DisableTelemetry = true
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
config.Get().Config.DisableTelemetry = false
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
assert.True(t, IsDisabled())
|
|
|
|
|
})
|
2025-06-30 09:47:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCloseIsImmutable(t *testing.T) {
|
|
|
|
|
Close()
|
|
|
|
|
assert.Nil(t, globalPosthogClient)
|
|
|
|
|
|
|
|
|
|
Close()
|
|
|
|
|
assert.Nil(t, globalPosthogClient)
|
|
|
|
|
}
|