@@ -2,46 +2,50 @@ package util
22
33import (
44 "reflect"
5+ "strings"
56 "testing"
67)
78
89func TestBrowserCommand (t * testing.T ) {
910 t .Run ("darwin" , func (t * testing.T ) {
10- name , args , err := browserCommand ("darwin" , "https://lets-cli.org" )
11+ cmd , err := browserCommand ("darwin" , "https://lets-cli.org" )
1112 if err != nil {
1213 t .Fatalf ("unexpected error: %v" , err )
1314 }
1415
15- if name != "open" {
16- t .Fatalf ("expected open, got %q" , name )
16+ if cmd . Args [ 0 ] != "open" {
17+ t .Fatalf ("expected open, got %q" , cmd . Args [ 0 ] )
1718 }
1819
19- expectedArgs := []string {"https://lets-cli.org" }
20- if ! reflect .DeepEqual (args , expectedArgs ) {
21- t .Fatalf ("expected args %v, got %v" , expectedArgs , args )
20+ expectedArgs := []string {"open" , " https://lets-cli.org" }
21+ if ! reflect .DeepEqual (cmd . Args , expectedArgs ) {
22+ t .Fatalf ("expected args %v, got %v" , expectedArgs , cmd . Args )
2223 }
2324 })
2425
2526 t .Run ("linux" , func (t * testing.T ) {
26- name , args , err := browserCommand ("linux" , "https://lets-cli.org" )
27+ cmd , err := browserCommand ("linux" , "https://lets-cli.org" )
2728 if err != nil {
2829 t .Fatalf ("unexpected error: %v" , err )
2930 }
3031
31- if name != "xdg-open" {
32- t .Fatalf ("expected xdg-open, got %q" , name )
32+ if cmd . Args [ 0 ] != "xdg-open" {
33+ t .Fatalf ("expected xdg-open, got %q" , cmd . Args [ 0 ] )
3334 }
3435
35- expectedArgs := []string {"https://lets-cli.org" }
36- if ! reflect .DeepEqual (args , expectedArgs ) {
37- t .Fatalf ("expected args %v, got %v" , expectedArgs , args )
36+ expectedArgs := []string {"xdg-open" , " https://lets-cli.org" }
37+ if ! reflect .DeepEqual (cmd . Args , expectedArgs ) {
38+ t .Fatalf ("expected args %v, got %v" , expectedArgs , cmd . Args )
3839 }
3940 })
4041
4142 t .Run ("unsupported" , func (t * testing.T ) {
42- _ , _ , err := browserCommand ("windows" , "https://lets-cli.org" )
43+ _ , err := browserCommand ("windows" , "https://lets-cli.org" )
4344 if err == nil {
4445 t .Fatal ("expected unsupported platform error" )
4546 }
47+ if ! strings .Contains (err .Error (), "windows" ) {
48+ t .Fatalf ("expected error to mention platform %q, got %q" , "windows" , err .Error ())
49+ }
4650 })
4751}
0 commit comments