-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput_file_test.go
45 lines (37 loc) · 922 Bytes
/
input_file_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package modzy_test
import (
"io/ioutil"
"strings"
"testing"
modzy "github.com./modzy/sdk-go"
"github.com./spf13/afero"
)
func TestFileInputReader(t *testing.T) {
expectedReader := strings.NewReader("a")
r, err := modzy.FileInputReader(expectedReader)()
if r != expectedReader {
t.Errorf("did not pass through reader")
}
if err != nil {
t.Errorf("expected nil error: %v", err)
}
}
func TestFileInputFile(t *testing.T) {
modzy.AppFs = afero.NewMemMapFs()
_ = afero.WriteFile(modzy.AppFs, "src/a/b", []byte("file b"), 0644)
r, err := modzy.FileInputFile("src/a/b")()
b, _ := ioutil.ReadAll(r)
if string(b) != "file b" {
t.Fatalf("did not read file")
}
if err != nil {
t.Errorf("expected nil error: %v", err)
}
}
func TestFileInputFileError(t *testing.T) {
modzy.AppFs = afero.NewMemMapFs()
_, err := modzy.FileInputFile("not/a/file")()
if err == nil {
t.Errorf("expected an error")
}
}