forked from bblfsh/go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_test.go
49 lines (38 loc) · 1.1 KB
/
request_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
package bblfsh
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestParseRequest_Configuration(t *testing.T) {
req := ParseRequest{}
req.Filename("file.py").Language("python").Content("a=b+c")
require.Equal(t, "file.py", req.options.Filename)
require.Equal(t, "python", req.options.Language)
require.Equal(t, "a=b+c", req.content)
}
func TestParseRequest_ReadFile(t *testing.T) {
tmpfile := tempFile(t)
defer os.RemoveAll(tmpfile.Name())
req := &ParseRequest{}
req = req.ReadFile(tmpfile.Name())
require.Equal(t, filepath.Base(tmpfile.Name()), req.options.Filename)
require.Equal(t, "foo", req.content)
}
func TestParseRequest_ReadFileError(t *testing.T) {
req := ParseRequest{}
_, err := req.ReadFile("NO_EXISTS").Do()
require.Errorf(t, err, "open NO_EXISTS: no such file or directory")
}
func tempFile(t *testing.T) *os.File {
content := []byte("foo")
tmpfile, err := ioutil.TempFile("", "example")
require.NoError(t, err)
_, err = tmpfile.Write(content)
require.NoError(t, err)
err = tmpfile.Close()
require.NoError(t, err)
return tmpfile
}