@@ -7,16 +7,11 @@ import (
7
7
"os"
8
8
"os/exec"
9
9
"path/filepath"
10
- "reflect"
11
10
"strings"
12
11
"testing"
13
12
"time"
14
13
)
15
14
16
- var (
17
- update = flag .Bool ("update" , false , "update .golden files" )
18
- )
19
-
20
15
var binaryName = "clibgen"
21
16
var binaryPath = ""
22
17
@@ -42,12 +37,6 @@ func TestMain(m *testing.M) {
42
37
os .Exit (m .Run ())
43
38
}
44
39
45
- func runBinary (args []string ) ([]byte , error ) {
46
- cmd := exec .Command (binaryPath , args ... )
47
- cmd .Env = append (os .Environ (), "GOCOVERDIR=.coverdata" )
48
- return cmd .CombinedOutput ()
49
- }
50
-
51
40
func runBinaryWithFileInput (args []string , bytesToWrite []byte ) ([]byte , error ) {
52
41
fmt .Println ("Running binary with file input" , bytesToWrite )
53
42
fmt .Printf ("Executing command: %s" , binaryPath )
@@ -99,38 +88,6 @@ func runBinaryWithFileInput(args []string, bytesToWrite []byte) ([]byte, error)
99
88
return out , err
100
89
}
101
90
102
- func TestStaticCliArgs (t * testing.T ) {
103
- tests := []struct {
104
- name string
105
- args []string
106
- fixture string
107
- }{
108
- {"help args" , []string {"--help" }, "help.golden" },
109
- }
110
-
111
- for _ , tt := range tests {
112
- t .Run (tt .name , func (t * testing.T ) {
113
- output , err := runBinary (tt .args )
114
-
115
- if err != nil {
116
- t .Fatal (err )
117
- }
118
-
119
- if * update {
120
- writeFixture (t , tt .fixture , output )
121
- }
122
-
123
- actual := string (output )
124
-
125
- expected := loadFixture (t , tt .fixture )
126
-
127
- if ! reflect .DeepEqual (actual , expected ) {
128
- t .Fatalf ("actual = %s, expected = %s" , actual , expected )
129
- }
130
- })
131
- }
132
- }
133
-
134
91
func TestSearch (t * testing.T ) {
135
92
tests := []struct {
136
93
name string
@@ -158,40 +115,3 @@ func TestSearch(t *testing.T) {
158
115
})
159
116
}
160
117
}
161
-
162
- func removeLastLine (str string , num int ) string {
163
- lines := strings .Split (str , "\n " )
164
-
165
- if len (lines ) > 0 {
166
- lines = lines [:len (lines )- num ]
167
- }
168
-
169
- return strings .Join (lines , "\n " )
170
- }
171
-
172
- func writeFixture (t * testing.T , goldenFile string , actual []byte ) {
173
- t .Helper ()
174
- goldenPath := "testdata/" + goldenFile
175
-
176
- f , err := os .OpenFile (goldenPath , os .O_RDWR , 0644 )
177
- defer f .Close ()
178
-
179
- _ , err = f .WriteString (string (actual ))
180
-
181
- if err != nil {
182
- t .Fatalf ("Error writing to file %s: %s" , goldenPath , err )
183
- }
184
- }
185
-
186
- func loadFixture (t * testing.T , goldenFile string ) string {
187
- goldenPath := "testdata/" + goldenFile
188
-
189
- f , err := os .OpenFile (goldenPath , os .O_RDWR , 0644 )
190
-
191
- content , err := ioutil .ReadAll (f )
192
- if err != nil {
193
- t .Fatalf ("Error opening file %s: %s" , goldenPath , err )
194
- }
195
-
196
- return string (content )
197
- }
0 commit comments