diff --git a/cmd/completion.go b/cmd/completion.go index 43b6aa948..d2f1e2aab 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -16,7 +16,7 @@ func newCompletionCommand(config *settings.Config) *cobra.Command { PersistentPreRun: func(cmd *cobra.Command, _ []string) { telemetryClient := create_telemetry.CreateTelemetry(config) defer telemetryClient.Close() - telemetryClient.Track(telemetry.CreateCompletionCommand(create_telemetry.GetCommandInformation(cmd, false))) + _ = telemetryClient.Track(telemetry.CreateCompletionCommand(create_telemetry.GetCommandInformation(cmd, false))) }, Run: func(cmd *cobra.Command, _ []string) { err := cmd.Help() diff --git a/cmd/config.go b/cmd/config.go index 7465e20bf..fddb791a3 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -89,7 +89,7 @@ func newConfigCommand(globalConfig *settings.Config) *cobra.Command { IgnoreDeprecatedImages: ignoreDeprecatedImages, VerboseOutput: verboseOutput, }) - telemetryClient.Track(telemetry.CreateConfigEvent(create_telemetry.GetCommandInformation(cmd, true), err)) + _ = telemetryClient.Track(telemetry.CreateConfigEvent(create_telemetry.GetCommandInformation(cmd, true), err)) return err }, @@ -131,7 +131,7 @@ func newConfigCommand(globalConfig *settings.Config) *cobra.Command { PipelineParamsFilePath: pipelineParamsFilePath, VerboseOutput: verboseOutput, }) - telemetryClient.Track(telemetry.CreateConfigEvent(create_telemetry.GetCommandInformation(cmd, true), err)) + _ = telemetryClient.Track(telemetry.CreateConfigEvent(create_telemetry.GetCommandInformation(cmd, true), err)) if err != nil { return err } diff --git a/cmd/diagnostic.go b/cmd/diagnostic.go index 898c97222..44784c2ff 100644 --- a/cmd/diagnostic.go +++ b/cmd/diagnostic.go @@ -35,7 +35,7 @@ func newDiagnosticCommand(config *settings.Config) *cobra.Command { defer telemetryClient.Close() err := diagnostic(opts) - telemetryClient.Track(telemetry.CreateDiagnosticEvent(err)) + _ = telemetryClient.Track(telemetry.CreateDiagnosticEvent(err)) return err }, diff --git a/cmd/follow.go b/cmd/follow.go index 89005badd..9eac8b942 100644 --- a/cmd/follow.go +++ b/cmd/follow.go @@ -60,7 +60,7 @@ func followProjectCommand(config *settings.Config) *cobra.Command { defer telemetryClient.Close() err := followProject(opts) - telemetryClient.Track(telemetry.CreateFollowEvent(err)) + _ = telemetryClient.Track(telemetry.CreateFollowEvent(err)) return err }, diff --git a/cmd/namespace_test.go b/cmd/namespace_test.go index 03cf5daeb..06fff16e1 100644 --- a/cmd/namespace_test.go +++ b/cmd/namespace_test.go @@ -46,7 +46,7 @@ var _ = Describe("Namespace integration tests", func() { tempSettings.TestServer.AppendHandlers(func(res http.ResponseWriter, req *http.Request) { res.WriteHeader(http.StatusOK) - res.Write([]byte(`{"data":{"organization":{"name":"test-org","id":"bb604b45-b6b0-4b81-ad80-796f15eddf87"}}}`)) + _, _ = res.Write([]byte(`{"data":{"organization":{"name":"test-org","id":"bb604b45-b6b0-4b81-ad80-796f15eddf87"}}}`)) }) session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) diff --git a/cmd/orb.go b/cmd/orb.go index 5134209b0..f8443706b 100644 --- a/cmd/orb.go +++ b/cmd/orb.go @@ -392,7 +392,7 @@ Please note that at this time all orbs created in the registry are world-readabl telemetryClient := create_telemetry.CreateTelemetry(config) defer telemetryClient.Close() - telemetryClient.Track(telemetry.CreateOrbEvent(create_telemetry.GetCommandInformation(cmd, true))) + _ = telemetryClient.Track(telemetry.CreateOrbEvent(create_telemetry.GetCommandInformation(cmd, true))) // PersistentPreRunE overwrites the inherited persistent hook from rootCmd // So we explicitly call it here to retain that behavior. diff --git a/cmd/orb_test.go b/cmd/orb_test.go index 2c80d86b1..cd0741144 100644 --- a/cmd/orb_test.go +++ b/cmd/orb_test.go @@ -55,7 +55,7 @@ var _ = Describe("Orb telemetry", func() { tempSettings.TestServer.AppendHandlers(func(res http.ResponseWriter, req *http.Request) { res.WriteHeader(http.StatusOK) - res.Write([]byte(`{"orbConfig": {"sourceYaml": "{}", "valid": true, "errors": []} }`)) + _, _ = res.Write([]byte(`{"orbConfig": {"sourceYaml": "{}", "valid": true, "errors": []} }`)) }) session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) diff --git a/cmd/policy/policy.go b/cmd/policy/policy.go index cbd246e57..be13a0ae4 100644 --- a/cmd/policy/policy.go +++ b/cmd/policy/policy.go @@ -39,7 +39,7 @@ func NewCommand(globalConfig *settings.Config, preRunE validator.Validator) *cob PersistentPreRunE: func(cmd *cobra.Command, args []string) error { telemetryClient := create_telemetry.CreateTelemetry(globalConfig) defer telemetryClient.Close() - telemetryClient.Track(telemetry.CreatePolicyEvent(create_telemetry.GetCommandInformation(cmd, true))) + _ = telemetryClient.Track(telemetry.CreatePolicyEvent(create_telemetry.GetCommandInformation(cmd, true))) if preRunE != nil { return preRunE(cmd, args) diff --git a/cmd/runner/resource_class.go b/cmd/runner/resource_class.go index 3bb4e666a..4cfad2d12 100644 --- a/cmd/runner/resource_class.go +++ b/cmd/runner/resource_class.go @@ -19,7 +19,7 @@ func newResourceClassCommand(o *runnerOpts, preRunE validator.Validator) *cobra. PersistentPreRun: func(cmd *cobra.Command, _ []string) { telemetryClient := o.createTelemetry() defer telemetryClient.Close() - telemetryClient.Track(telemetry.CreateRunnerResourceClassEvent(create_telemetry.GetCommandInformation(cmd, true))) + _ = telemetryClient.Track(telemetry.CreateRunnerResourceClassEvent(create_telemetry.GetCommandInformation(cmd, true))) }, } diff --git a/cmd/runner/token.go b/cmd/runner/token.go index d59c003f8..2a249c5a4 100644 --- a/cmd/runner/token.go +++ b/cmd/runner/token.go @@ -17,7 +17,7 @@ func newTokenCommand(o *runnerOpts, preRunE validator.Validator) *cobra.Command PersistentPreRun: func(cmd *cobra.Command, _ []string) { telemetryClient := o.createTelemetry() defer telemetryClient.Close() - telemetryClient.Track(telemetry.CreateRunnerResourceClassEvent(create_telemetry.GetCommandInformation(cmd, true))) + _ = telemetryClient.Track(telemetry.CreateRunnerResourceClassEvent(create_telemetry.GetCommandInformation(cmd, true))) }, } diff --git a/cmd/update.go b/cmd/update.go index d11941082..a326fbbb2 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -34,7 +34,7 @@ func newUpdateCommand(config *settings.Config) *cobra.Command { opts.cfg.SkipUpdateCheck = true telemetryClient := create_telemetry.CreateTelemetry(config) defer telemetryClient.Close() - telemetryClient.Track(telemetry.CreateUpdateEvent(create_telemetry.GetCommandInformation(cmd, cmd.Name() != "update"))) + _ = telemetryClient.Track(telemetry.CreateUpdateEvent(create_telemetry.GetCommandInformation(cmd, cmd.Name() != "update"))) }, PreRun: func(cmd *cobra.Command, args []string) { opts.args = args diff --git a/cmd/update_test.go b/cmd/update_test.go index ee37f17dd..97fec68bc 100644 --- a/cmd/update_test.go +++ b/cmd/update_test.go @@ -73,11 +73,29 @@ var _ = Describe("Update", func() { Describe("telemetry", func() { It("should send telemetry event when calling parent command", func() { - command = exec.Command(pathCLI, + updateCLI, err := gexec.Build("github.com/CircleCI-Public/circleci-cli") + Expect(err).ShouldNot(HaveOccurred()) + + command = exec.Command(updateCLI, "update", "--github-api", tempSettings.TestServer.URL(), "--mock-telemetry", tempSettings.TelemetryDestPath, ) + + assetBytes := golden.Get(GinkgoT(), filepath.FromSlash("update/foo.zip")) + assetResponse := string(assetBytes) + + tempSettings.TestServer.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodGet, "/repos/CircleCI-Public/circleci-cli/releases"), + ghttp.RespondWith(http.StatusOK, response), + ), + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodGet, "/repos/CircleCI-Public/circleci-cli/releases/assets/1"), + ghttp.RespondWith(http.StatusOK, assetResponse), + ), + ) + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) Expect(err).ShouldNot(HaveOccurred()) diff --git a/telemetry/telemetry.go b/telemetry/telemetry.go index 59a0298dd..906ef1003 100644 --- a/telemetry/telemetry.go +++ b/telemetry/telemetry.go @@ -13,7 +13,7 @@ var ( // Overwrite this function for tests CreateActiveTelemetry = newSegmentClient - SegmentEndpoint = "localhost" + SegmentEndpoint = "http://localhost" SegmentKey = "" )