-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e84d89
commit ac02039
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
) | ||
|
||
func TestInputReader(t *testing.T) { | ||
table := []struct { | ||
name string | ||
path string | ||
dflag bool | ||
err bool | ||
}{ | ||
{ | ||
"stdin test", | ||
"", | ||
true, | ||
false, | ||
}, | ||
{ | ||
"no stdin test", | ||
"", | ||
false, | ||
true, | ||
}, | ||
{ | ||
"file test", | ||
"./main.go", | ||
true, | ||
false, | ||
}, | ||
{ | ||
"bad file test", | ||
"./file_not_found", | ||
true, | ||
true, | ||
}, | ||
{ | ||
"explicit stdin test", | ||
"-", | ||
false, | ||
false, | ||
}, | ||
} | ||
|
||
for _, v := range table { | ||
t.Run(v.name, func(t *testing.T) { | ||
buff, err := inputReader(v.path, v.dflag) | ||
|
||
if err != nil && !v.err { | ||
t.Errorf("Error thrown %v", err) | ||
} else if err == nil && v.err { | ||
t.Error("Error was expected") | ||
} else if !v.err { | ||
_, ok := buff.(io.ByteReader) | ||
if !ok { | ||
t.Error("no reader returned") | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters