@@ -15,7 +15,7 @@ import (
1515
1616// CreateResultsDir creates and returns the name of the results directory for a test.
1717func CreateResultsDir (testName , version string ) (string , error ) {
18- pwd , err := GetWorkingDir ()
18+ pwd , err := os . Getwd ()
1919 if err != nil {
2020 return "" , err
2121 }
@@ -31,13 +31,12 @@ func CreateResultsDir(testName, version string) (string, error) {
3131 }
3232 }
3333
34- return dirName , MkdirAll (dirName , 0o777 )
34+ return dirName , os . MkdirAll (dirName , 0o777 )
3535}
3636
3737// CreateResultsFile creates and returns the results file for a test.
3838func CreateResultsFile (filename string ) (* os.File , error ) {
39- GinkgoWriter .Printf ("Creating results file %q\n " , filename )
40- outFile , err := OpenFile (filename , os .O_TRUNC | os .O_WRONLY | os .O_CREATE , 0o644 )
39+ outFile , err := os .OpenFile (filename , os .O_TRUNC | os .O_WRONLY | os .O_CREATE , 0o644 )
4140 if err != nil {
4241 GinkgoWriter .Printf ("ERROR occurred during creating results file %q, error: %s\n " , filename , err )
4342
@@ -89,7 +88,7 @@ func WriteSystemInfoToFile(file *os.File, ci ClusterInfo, plus bool) error {
8988}
9089
9190func generatePNG (resultsDir , inputFilename , outputFilename , configFilename string ) error {
92- pwd , err := GetWorkingDir ()
91+ pwd , err := os . Getwd ()
9392 if err != nil {
9493 return err
9594 }
@@ -158,115 +157,25 @@ func WriteContent(resultsFile *os.File, content string) error {
158157 return nil
159158}
160159
161- // GetWorkingDir returns the current working directory.
162- func GetWorkingDir () (string , error ) {
163- pwd , err := os .Getwd ()
164- if err != nil {
165- GinkgoWriter .Printf ("ERROR occurred during getting current working directory %q, error: %s\n " , pwd , err )
166- }
167-
168- return pwd , err
169- }
170-
171- // CreateFile creates a new file with the given name.
172- func CreateFile (fileName string ) (* os.File , error ) {
173- file , err := os .Create (fileName )
174- if err != nil {
175- GinkgoWriter .Printf ("ERROR occurred during creating file %q, error: %s\n " , fileName , err )
176- }
177-
178- return file , err
179- }
180-
181- // OpenFile opens an existing file with the given name.
182- func OpenFile (name string , flag int , perm os.FileMode ) (* os.File , error ) {
183- file , err := os .OpenFile (name , flag , perm )
184- if err != nil {
185- GinkgoWriter .Printf ("ERROR occurred during openning results file %q, error: %s\n " , name , err )
186- }
187-
188- return file , err
189- }
190-
191- // MkdirAll creates a directory with the specified permissions.
192- func MkdirAll (path string , perm os.FileMode ) error {
193- err := os .MkdirAll (path , perm )
194- if err != nil {
195- GinkgoWriter .Printf ("ERROR occurred during creating directory %q, error: %s\n " , path , err )
196- }
197-
198- return err
199- }
200-
201- // ReadFile reads the contents of a file.
202- func ReadFile (file string ) ([]byte , error ) {
203- result , err := os .ReadFile (file )
204- if err != nil {
205- GinkgoWriter .Printf ("ERROR occurred during reading file %q, error: %s\n " , file , err )
206- }
207-
208- return result , err
209- }
210-
211- // WriteString writes a string to the given file.
212- func WriteString (file * os.File , content string ) (int , error ) {
213- result , err := io .WriteString (file , content )
214- if err != nil {
215- GinkgoWriter .Printf ("ERROR writing error log file: %v\n " , err )
216- }
217- return result , err
218- }
219-
220- // WriteCSVRecord writes a CSV record using the given writer.
221- func WriteCSVRecord (writer * csv.Writer , record []string ) error {
222- err := writer .Write (record )
223- if err != nil {
224- GinkgoWriter .Printf ("ERROR writing CSV record: %v\n " , err )
225- }
226-
227- return err
228- }
229-
230- // UserHomeDir returns the user's home directory.
231- func UserHomeDir () (string , error ) {
232- dir , err := os .UserHomeDir ()
233- if err != nil {
234- GinkgoWriter .Printf ("ERROR getting user home directory, error: %s\n " , err )
235- }
236- GinkgoWriter .Printf ("User home directory is %q\n " , dir )
237-
238- return dir , err
239- }
240-
241- // Remove removes the specified file or empty directory.
242- func Remove (name string ) error {
243- err := os .Remove (name )
244- if err != nil {
245- GinkgoWriter .Printf ("ERROR occurred during removing %q, error: %s\n " , name , err )
246- }
247-
248- return err
249- }
250-
251160// NewVegetaCSVEncoder returns a vegeta CSV encoder.
252161func NewVegetaCSVEncoder (w io.Writer ) vegeta.Encoder {
253162 return vegeta .NewCSVEncoder (w )
254163}
255164
256165// NewCSVResultsWriter creates and returns a CSV results file and writer.
257166func NewCSVResultsWriter (resultsDir , fileName string , resultHeaders ... string ) (* os.File , * csv.Writer , error ) {
258- if err := MkdirAll (resultsDir , 0o750 ); err != nil {
167+ if err := os . MkdirAll (resultsDir , 0o750 ); err != nil {
259168 return nil , nil , err
260169 }
261170
262- file , err := OpenFile (filepath .Join (resultsDir , fileName ), os .O_APPEND | os .O_WRONLY | os .O_CREATE , 0o644 )
171+ file , err := os . OpenFile (filepath .Join (resultsDir , fileName ), os .O_APPEND | os .O_WRONLY | os .O_CREATE , 0o644 )
263172 if err != nil {
264173 return nil , nil , err
265174 }
266175
267176 writer := csv .NewWriter (file )
268177
269- if err = WriteCSVRecord ( writer , resultHeaders ); err != nil {
178+ if err = writer . Write ( resultHeaders ); err != nil {
270179 return nil , nil , err
271180 }
272181
0 commit comments