1
1
package ssh
2
2
3
3
import (
4
+ "errors"
4
5
"fmt"
5
6
"net/url"
6
7
"os"
@@ -85,7 +86,13 @@ func TestHelperProcess(t *testing.T) {
85
86
return
86
87
}
87
88
if err := func (args []string ) error {
88
- fmt .Fprint (os .Stdout , "hostname github.com\n " )
89
+ if len (args ) < 3 || args [2 ] == "error" {
90
+ return errors .New ("fatal" )
91
+ }
92
+ if args [2 ] == "empty.io" {
93
+ return nil
94
+ }
95
+ fmt .Fprintf (os .Stdout , "hostname %s\n " , args [2 ])
89
96
return nil
90
97
}(os .Args [3 :]); err != nil {
91
98
fmt .Fprintln (os .Stderr , err )
@@ -111,32 +118,46 @@ func TestTranslator_caching(t *testing.T) {
111
118
},
112
119
}
113
120
114
- u1 , err := url .Parse ("ssh://github1.com/owner/repo.git" )
115
- if err != nil {
116
- t .Fatalf ("error parsing URL: %v" , err )
117
- }
118
- if res := tr .Translate (u1 ); res .Host != "github.com" {
119
- t .Errorf ("expected github.com, got: %q" , res .Host )
120
- }
121
- if res := tr .Translate (u1 ); res .Host != "github.com" {
122
- t .Errorf ("expected github.com, got: %q" , res .Host )
123
- }
124
-
125
- u2 , err := url .Parse ("ssh://github2.com/owner/repo.git" )
126
- if err != nil {
127
- t .Fatalf ("error parsing URL: %v" , err )
128
- }
129
- if res := tr .Translate (u2 ); res .Host != "github.com" {
130
- t .Errorf ("expected github.com, got: %q" , res .Host )
121
+ tests := []struct {
122
+ input string
123
+ result string
124
+ }{
125
+ {
126
+ input : "ssh://github1.com/owner/repo.git" ,
127
+ result : "github1.com" ,
128
+ },
129
+ {
130
+ input : "ssh://github2.com/owner/repo.git" ,
131
+ result : "github2.com" ,
132
+ },
133
+ {
134
+ input : "ssh://empty.io/owner/repo.git" ,
135
+ result : "empty.io" ,
136
+ },
137
+ {
138
+ input : "ssh://error/owner/repo.git" ,
139
+ result : "error" ,
140
+ },
131
141
}
132
- if res := tr .Translate (u2 ); res .Host != "github.com" {
133
- t .Errorf ("expected github.com, got: %q" , res .Host )
142
+ for _ , tt := range tests {
143
+ t .Run (tt .input , func (t * testing.T ) {
144
+ u , err := url .Parse (tt .input )
145
+ if err != nil {
146
+ t .Fatalf ("error parsing URL: %v" , err )
147
+ }
148
+ if res := tr .Translate (u ); res .Host != tt .result {
149
+ t .Errorf ("expected github.com, got: %q" , res .Host )
150
+ }
151
+ if res := tr .Translate (u ); res .Host != tt .result {
152
+ t .Errorf ("expected github.com, got: %q (second call)" , res .Host )
153
+ }
154
+ })
134
155
}
135
156
136
157
if countLookPath != 1 {
137
158
t .Errorf ("expected lookPath to happen 1 time; actual: %d" , countLookPath )
138
159
}
139
- if countNewCommand != 2 {
140
- t .Errorf ("expected ssh command to shell out 2 times; actual: %d" , countNewCommand )
160
+ if countNewCommand != len ( tests ) {
161
+ t .Errorf ("expected ssh command to shell out %d times; actual: %d" , len ( tests ) , countNewCommand )
141
162
}
142
163
}
0 commit comments