-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_file_test.go
64 lines (53 loc) · 1.37 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package tg
import (
"io/ioutil"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewInputFile(t *testing.T) {
file := NewInputFile("test.txt", strings.NewReader("test"))
if assert.NotNil(t, file) {
assert.Equal(t, "test.txt", file.Name)
assert.NotNil(t, file.Body)
err := file.Close()
assert.NoError(t, err)
}
}
func TestNewInputFileBytes(t *testing.T) {
file := NewInputFileBytes("test.txt", []byte("test"))
if assert.NotNil(t, file) {
assert.Equal(t, "test.txt", file.Name)
data, err := ioutil.ReadAll(file.Body)
assert.NoError(t, err, "read file")
assert.Equal(t, []byte("test"), data)
}
}
func TestNewInputFileLocal(t *testing.T) {
t.Run("OK", func(t *testing.T) {
file, err := NewInputFileLocal("./README.md")
if assert.NoError(t, err) {
defer file.Close()
assert.Equal(t, "README.md", file.Name)
}
})
t.Run("FAIL", func(t *testing.T) {
file, err := NewInputFileLocal("./NOT_FOUND.txt")
assert.Error(t, err)
assert.Nil(t, file)
})
}
func TestNewInputFileLocalBuffer(t *testing.T) {
t.Run("OK", func(t *testing.T) {
file, err := NewInputFileLocalBuffer("./README.md")
if assert.NoError(t, err) {
defer file.Close()
assert.Equal(t, "README.md", file.Name)
}
})
t.Run("FAIL", func(t *testing.T) {
file, err := NewInputFileLocalBuffer("./NOT_FOUND.txt")
assert.Error(t, err)
assert.Nil(t, file)
})
}