github.com/saucelabs/saucectl@v0.175.1/internal/report/buildtable/buildtable.go (about) 1 package buildtable 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 8 "github.com/fatih/color" 9 "github.com/saucelabs/saucectl/internal/report" 10 "github.com/saucelabs/saucectl/internal/report/table" 11 ) 12 13 // Reporter is an implementation of report.Reporter 14 // It wraps a table reporter and decorates it with additional metadata 15 type Reporter struct { 16 VDCTableReport table.Reporter 17 RDCTableReport table.Reporter 18 } 19 20 func New() Reporter { 21 return Reporter{ 22 VDCTableReport: table.Reporter{ 23 Dst: os.Stdout, 24 }, 25 RDCTableReport: table.Reporter{ 26 Dst: os.Stdout, 27 }, 28 } 29 } 30 31 // Add adds a TestResult to the report 32 func (r *Reporter) Add(t report.TestResult) { 33 if t.RDC { 34 r.RDCTableReport.Add(t) 35 } else { 36 r.VDCTableReport.Add(t) 37 } 38 } 39 40 // Render renders the report 41 func (r *Reporter) Render() { 42 printPadding(2) 43 printTitle() 44 printPadding(2) 45 46 if len(r.VDCTableReport.TestResults) > 0 { 47 r.VDCTableReport.Render() 48 49 var bURL string 50 for _, result := range r.VDCTableReport.TestResults { 51 if result.BuildURL != "" { 52 bURL = result.BuildURL 53 break 54 } 55 } 56 57 if bURL == "" { 58 bURL = "N/A" 59 } 60 printPadding(1) 61 printBuildLink(bURL) 62 printPadding(2) 63 } 64 if len(r.RDCTableReport.TestResults) > 0 { 65 r.RDCTableReport.Render() 66 67 var bURL string 68 for _, result := range r.RDCTableReport.TestResults { 69 if result.BuildURL != "" { 70 bURL = result.BuildURL 71 break 72 } 73 } 74 75 if bURL == "" { 76 bURL = "N/A" 77 } 78 printPadding(1) 79 printBuildLink(bURL) 80 printPadding(2) 81 } 82 } 83 84 // Reset resets the report 85 func (r *Reporter) Reset() { 86 r.VDCTableReport.Reset() 87 r.RDCTableReport.Reset() 88 } 89 90 // ArtifactRequirements returns a list of artifact types are this reporter requires to create a proper report. 91 func (r *Reporter) ArtifactRequirements() []report.ArtifactType { 92 return nil 93 } 94 95 func printPadding(repeat int) { 96 fmt.Print(strings.Repeat("\n", repeat)) 97 } 98 99 func printTitle() { 100 rl := color.New(color.FgBlue, color.Underline, color.Bold).Sprintf("Results:") 101 fmt.Printf(" %s", rl) 102 } 103 104 func printBuildLink(buildURL string) { 105 label := color.New(color.FgBlue).Sprint("Build Link:") 106 link := color.New(color.Underline).Sprint(buildURL) 107 108 fmt.Printf(" %s %s", label, link) 109 }