@@ -18,6 +18,7 @@ package telemetry
1818
1919import (
2020 "errors"
21+ "fmt"
2122 "runtime"
2223 "testing"
2324 "time"
@@ -262,9 +263,12 @@ func TestSanitizePrompt(t *testing.T) {
262263 },
263264 }
264265
265- for _ , testCase := range testCases {
266- got := sanitizePrompt (testCase .input )
267- assert .Equal (t , testCase .expected , got )
266+ for i , tc := range testCases {
267+ t .Run (fmt .Sprintf ("case_%d" , i ), func (t * testing.T ) {
268+ t .Parallel ()
269+ got := sanitizePrompt (tc .input )
270+ assert .Equal (t , tc .expected , got )
271+ })
268272 }
269273}
270274
@@ -283,9 +287,12 @@ func TestSanitizeSelectOption(t *testing.T) {
283287 },
284288 }
285289
286- for _ , testCase := range testCases {
287- got := sanitizeSelectOption (testCase .input )
288- assert .Equal (t , testCase .expected , got )
290+ for i , tc := range testCases {
291+ t .Run (fmt .Sprintf ("case_%d" , i ), func (t * testing.T ) {
292+ t .Parallel ()
293+ got := sanitizeSelectOption (tc .input )
294+ assert .Equal (t , tc .expected , got )
295+ })
289296 }
290297}
291298
@@ -384,6 +391,55 @@ func TestWithEmptySearchIndexType(t *testing.T) {
384391 assert .Nil (t , e .Properties ["search_index_type" ])
385392}
386393
394+ func Test_withOutput (t * testing.T ) {
395+ tests := []struct {
396+ name string
397+ flagValue string
398+ configValue string
399+ want string
400+ }{
401+ {
402+ name : "from flag" ,
403+ flagValue : "json" ,
404+ configValue : "" ,
405+ want : "json" ,
406+ },
407+ {
408+ name : "from config" ,
409+ flagValue : "" ,
410+ configValue : "json" ,
411+ want : "json" ,
412+ },
413+ {
414+ name : "no value" ,
415+ flagValue : "" ,
416+ configValue : "" ,
417+ want : "plaintext" ,
418+ },
419+ }
420+ for _ , tc := range tests {
421+ t .Run (tc .name , func (t * testing.T ) {
422+ t .Parallel ()
423+ cmd := & cobra.Command {
424+ Use : "test-command" ,
425+ Run : func (_ * cobra.Command , _ []string ) {},
426+ }
427+ var p string
428+ cmd .Flags ().StringVar (& p , flag .Output , "" , "" )
429+ if tc .flagValue != "" {
430+ require .NoError (t , cmd .Flags ().Set (flag .Output , tc .flagValue ))
431+ }
432+ c := & configMock {}
433+ if tc .configValue != "" {
434+ c .out = tc .configValue
435+ }
436+ require .NoError (t , cmd .ExecuteContext (NewContext ()))
437+ e := newEvent (withOutput (cmd , c ))
438+ assert .Equal (t , tc .want , e .Properties ["output" ])
439+ })
440+ }
441+ }
442+
387443type configMock struct {
388444 name string
389445 publicKey string
@@ -393,6 +449,7 @@ type configMock struct {
393449 url string
394450 project string
395451 org string
452+ out string
396453}
397454
398455var _ Authenticator = configMock {}
@@ -428,3 +485,7 @@ func (c configMock) PrivateAPIKey() string {
428485func (c configMock ) AccessToken () string {
429486 return c .accessToken
430487}
488+
489+ func (c configMock ) Output () string {
490+ return c .out
491+ }
0 commit comments