mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
* Add config-driven telemetry disable and surface telemetry status * Update config/config_template_test.go Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> --------- Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
41 lines
903 B
Go
41 lines
903 B
Go
package analytics
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/safedep/pmg/config"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIsDisabled(t *testing.T) {
|
|
t.Run("returns true if PMG_DISABLE_TELEMETRY is set to true", func(t *testing.T) {
|
|
os.Setenv(telemetryDisableEnvKey, "true")
|
|
defer os.Unsetenv(telemetryDisableEnvKey)
|
|
|
|
assert.True(t, IsDisabled())
|
|
})
|
|
|
|
t.Run("returns false if PMG_DISABLE_TELEMETRY is not set", func(t *testing.T) {
|
|
config.Get().Config.DisableTelemetry = false
|
|
assert.False(t, IsDisabled())
|
|
})
|
|
|
|
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())
|
|
})
|
|
}
|
|
|
|
func TestCloseIsImmutable(t *testing.T) {
|
|
Close()
|
|
assert.Nil(t, globalPosthogClient)
|
|
|
|
Close()
|
|
assert.Nil(t, globalPosthogClient)
|
|
}
|