Skip to content

Commit d1d8921

Browse files
mafredrijohnstcn
andauthored
fix: Disable telemetry by default in tests (coder#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 <cian@coder.com>
1 parent 122c6f0 commit d1d8921

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

cli/root.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"flag"
45
"fmt"
56
"net/url"
67
"os"
@@ -175,6 +176,10 @@ func versionCmd() *cobra.Command {
175176
}
176177
}
177178

179+
func isTest() bool {
180+
return flag.Lookup("test.v") != nil
181+
}
182+
178183
// createClient returns a new client from the command context.
179184
// It reads from global configuration files if flags are not set.
180185
func createClient(cmd *cobra.Command) (*codersdk.Client, error) {

cli/root_internal_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"os"
45
"testing"
56

67
"github.com/stretchr/testify/require"
@@ -64,3 +65,9 @@ func Test_formatExamples(t *testing.T) {
6465
})
6566
}
6667
}
68+
69+
func TestMain(m *testing.M) {
70+
// Replace with goleak.VerifyTestMain(m) when we enable goleak.
71+
os.Exit(m.Run())
72+
// goleak.VerifyTestMain(m)
73+
}

cli/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ func server() *cobra.Command {
566566
"Specifies teams inside organizations the user must be a member of to authenticate with GitHub. Formatted as: <organization-name>/<team-slug>.")
567567
cliflag.BoolVarP(root.Flags(), &oauth2GithubAllowSignups, "oauth2-github-allow-signups", "", "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS", false,
568568
"Specifies whether new users can sign up with GitHub.")
569-
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.")
569+
enableTelemetryByDefault := !isTest()
570+
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.")
570571
cliflag.StringVarP(root.Flags(), &telemetryURL, "telemetry-url", "", "CODER_TELEMETRY_URL", "https://telemetry.coder.com", "Specifies a URL to send telemetry to.")
571572
_ = root.Flags().MarkHidden("telemetry-url")
572573
cliflag.BoolVarP(root.Flags(), &tlsEnable, "tls-enable", "", "CODER_TLS_ENABLE", false, "Specifies if TLS will be enabled")

0 commit comments

Comments
 (0)