From d1d89210b8f290d3158af668ca778468be902080 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Tue, 26 Jul 2022 16:27:48 +0300 Subject: [PATCH] fix: Disable telemetry by default in tests (#3200) I also noticed we don't have `goleak` enabled for CLI tests, this commit adds it, but commented out. The reason being that we're nowhere near being able to enable it yet. Co-authored-by: Cian Johnston --- cli/root.go | 5 +++++ cli/root_internal_test.go | 7 +++++++ cli/server.go | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cli/root.go b/cli/root.go index b38b7c7244..df96949992 100644 --- a/cli/root.go +++ b/cli/root.go @@ -1,6 +1,7 @@ package cli import ( + "flag" "fmt" "net/url" "os" @@ -175,6 +176,10 @@ func versionCmd() *cobra.Command { } } +func isTest() bool { + return flag.Lookup("test.v") != nil +} + // createClient returns a new client from the command context. // It reads from global configuration files if flags are not set. func createClient(cmd *cobra.Command) (*codersdk.Client, error) { diff --git a/cli/root_internal_test.go b/cli/root_internal_test.go index ab472ba53d..64586e243d 100644 --- a/cli/root_internal_test.go +++ b/cli/root_internal_test.go @@ -1,6 +1,7 @@ package cli import ( + "os" "testing" "github.com/stretchr/testify/require" @@ -64,3 +65,9 @@ func Test_formatExamples(t *testing.T) { }) } } + +func TestMain(m *testing.M) { + // Replace with goleak.VerifyTestMain(m) when we enable goleak. + os.Exit(m.Run()) + // goleak.VerifyTestMain(m) +} diff --git a/cli/server.go b/cli/server.go index bbe5edc1be..362e303c18 100644 --- a/cli/server.go +++ b/cli/server.go @@ -566,7 +566,8 @@ func server() *cobra.Command { "Specifies teams inside organizations the user must be a member of to authenticate with GitHub. Formatted as: /.") cliflag.BoolVarP(root.Flags(), &oauth2GithubAllowSignups, "oauth2-github-allow-signups", "", "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS", false, "Specifies whether new users can sign up with GitHub.") - cliflag.BoolVarP(root.Flags(), &telemetryEnable, "telemetry", "", "CODER_TELEMETRY", true, "Specifies whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product.") + enableTelemetryByDefault := !isTest() + cliflag.BoolVarP(root.Flags(), &telemetryEnable, "telemetry", "", "CODER_TELEMETRY", enableTelemetryByDefault, "Specifies whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product.") cliflag.StringVarP(root.Flags(), &telemetryURL, "telemetry-url", "", "CODER_TELEMETRY_URL", "https://telemetry.coder.com", "Specifies a URL to send telemetry to.") _ = root.Flags().MarkHidden("telemetry-url") cliflag.BoolVarP(root.Flags(), &tlsEnable, "tls-enable", "", "CODER_TLS_ENABLE", false, "Specifies if TLS will be enabled")