@@ -93,7 +93,7 @@ func TestRunVersionFlagPrintsAndExits(t *testing.T) {
9393 })
9494
9595 version = "v1.2.3"
96- benchmarkMain = func (jsonOut , prettyOut bool , htmlPath string , stdout , stderr io.Writer ) int {
96+ benchmarkMain = func (jsonOut , prettyOut bool , htmlPath , htmlTitle string , stdout , stderr io.Writer ) int {
9797 t .Fatal ("benchmark path should not run for version flags" )
9898 return 1
9999 }
@@ -122,7 +122,7 @@ func TestRunShortVersionFlagPrintsAndExits(t *testing.T) {
122122 })
123123
124124 version = "v9.9.9"
125- benchmarkMain = func (jsonOut , prettyOut bool , htmlPath string , stdout , stderr io.Writer ) int {
125+ benchmarkMain = func (jsonOut , prettyOut bool , htmlPath , htmlTitle string , stdout , stderr io.Writer ) int {
126126 t .Fatal ("benchmark path should not run for version flags" )
127127 return 1
128128 }
@@ -149,7 +149,7 @@ func TestRunHelpFlagPrintsUsageAndExitsZero(t *testing.T) {
149149 benchmarkMain = oldBenchmark
150150 })
151151
152- benchmarkMain = func (jsonOut , prettyOut bool , htmlPath string , stdout , stderr io.Writer ) int {
152+ benchmarkMain = func (jsonOut , prettyOut bool , htmlPath , htmlTitle string , stdout , stderr io.Writer ) int {
153153 t .Fatal ("benchmark path should not run for help flags" )
154154 return 1
155155 }
@@ -170,21 +170,44 @@ func TestRunHelpFlagPrintsUsageAndExitsZero(t *testing.T) {
170170 }
171171}
172172
173- func TestRunHTMLFlagPassesOutputPath (t * testing.T ) {
173+ func TestRunHTMLFlagsPassOutputOptions (t * testing.T ) {
174174 oldBenchmark := benchmarkMain
175175 t .Cleanup (func () {
176176 benchmarkMain = oldBenchmark
177177 })
178178
179- benchmarkMain = func (jsonOut , prettyOut bool , htmlPath string , stdout , stderr io.Writer ) int {
179+ benchmarkMain = func (jsonOut , prettyOut bool , htmlPath , htmlTitle string , stdout , stderr io.Writer ) int {
180180 if htmlPath != "report.html" {
181181 t .Fatalf ("htmlPath = %q, want %q" , htmlPath , "report.html" )
182182 }
183+ if htmlTitle != "Home" {
184+ t .Fatalf ("htmlTitle = %q, want %q" , htmlTitle , "Home" )
185+ }
183186 return 0
184187 }
185188
186- if exitCode := run ([]string {"-html" , "report.html" }, io .Discard , io .Discard ); exitCode != 0 {
187- t .Fatalf ("run(-html report.html) exit code = %d, want 0" , exitCode )
189+ if exitCode := run ([]string {"-html" , "report.html" , "-html-title" , "Home" }, io .Discard , io .Discard ); exitCode != 0 {
190+ t .Fatalf ("run() exit code = %d, want 0" , exitCode )
191+ }
192+ }
193+
194+ func TestRunRejectsHTMLTitleWithoutHTMLPath (t * testing.T ) {
195+ oldBenchmark := benchmarkMain
196+ t .Cleanup (func () {
197+ benchmarkMain = oldBenchmark
198+ })
199+
200+ benchmarkMain = func (jsonOut , prettyOut bool , htmlPath , htmlTitle string , stdout , stderr io.Writer ) int {
201+ t .Fatal ("benchmark path should not run for invalid flags" )
202+ return 1
203+ }
204+
205+ var stderr bytes.Buffer
206+ if exitCode := run ([]string {"-html-title" , "Home" }, io .Discard , & stderr ); exitCode != 2 {
207+ t .Fatalf ("run() exit code = %d, want 2" , exitCode )
208+ }
209+ if got := stderr .String (); ! strings .Contains (got , "-html-title requires -html" ) {
210+ t .Fatalf ("stderr = %q, want dependency error" , got )
188211 }
189212}
190213
@@ -195,7 +218,7 @@ func TestWriteHTMLReport(t *testing.T) {
195218 t .Fatalf ("os.WriteFile() error = %v" , err )
196219 }
197220
198- if err := writeHTMLReport (path , reporter.Result {DownloadMbps : & download }); err != nil {
221+ if err := writeHTMLReport (path , "Home" , reporter.Result {DownloadMbps : & download }); err != nil {
199222 t .Fatalf ("writeHTMLReport() error = %v" , err )
200223 }
201224
@@ -206,6 +229,9 @@ func TestWriteHTMLReport(t *testing.T) {
206229 if output := string (data ); ! strings .Contains (output , "123.40" ) {
207230 t .Fatalf ("HTML report missing download speed:\n %s" , output )
208231 }
232+ if output := string (data ); ! strings .Contains (output , "Internet Speed Report - Home" ) {
233+ t .Fatalf ("HTML report missing custom title:\n %s" , output )
234+ }
209235 if strings .Contains (string (data ), "old report" ) {
210236 t .Fatalf ("HTML report did not replace existing file:\n %s" , data )
211237 }
0 commit comments