File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "bufio"
5
+ "io"
6
+ "os"
7
+ )
8
+
9
+ // dirExists check if a directory exists.
10
+ func dirExists (dirPath string ) bool {
11
+ _ , err := os .Stat (dirPath )
12
+ return ! os .IsNotExist (err )
13
+ }
14
+
15
+ // readLines read lines from file. Return error in case of having issues to read given file.
16
+ func readLines (filePath string ) ([]string , error ) {
17
+ f , err := os .Open (filePath )
18
+ if err != nil {
19
+ return []string {}, err
20
+ }
21
+ defer f .Close ()
22
+
23
+ var lines []string
24
+ reader := bufio .NewReader (f )
25
+ for {
26
+ line , _ , err := reader .ReadLine ()
27
+ if err != nil {
28
+ if err == io .EOF {
29
+ break
30
+ }
31
+ return []string {}, err
32
+ }
33
+ lines = append (lines , string (line ))
34
+ }
35
+ return lines , nil
36
+ }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ func TestUtilsDirExists (t * testing.T ) {
10
+ assert .True (t , dirExists ("." ))
11
+ assert .False (t , dirExists ("/x/y/z/path-helper" ))
12
+ }
13
+
14
+ func TestUtilsReadLines (t * testing.T ) {
15
+ lines , err := readLines ("utils_test.go" )
16
+ assert .NoError (t , err )
17
+ assert .True (t , len (lines ) > 0 )
18
+ }
You can’t perform that action at this time.
0 commit comments