forked from vladimirvivien/gowfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs_test.go
55 lines (46 loc) · 1.17 KB
/
fs_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
package webhdfs
import "net/url"
import "testing"
import "os/user"
func Test_NewFileSystem(t *testing.T) {
conf := Configuration{Addr: "localhost:8080"}
fs, err := NewFileSystem(conf)
if err != nil {
t.Fatal(err)
}
if &fs.Config == nil {
t.Fatal("Filesystem missing Configuration")
}
if &fs.client == nil {
t.Fatal("http.Client not set")
}
}
func Test_buildRequestUrl(t *testing.T) {
user, _ := user.Current()
url1 := url.URL{Scheme: "http", Host: "localhost:8080", Path: "/webhdfs/v1/test"}
q := url1.Query()
q.Set("user.name", user.Username)
url1.RawQuery = q.Encode()
conf := Configuration{Addr: url1.Host}
u, err := buildRequestUrl(conf, &Path{Name: "/test"}, nil)
if err != nil {
t.Fatal(err)
}
if url1 != *u {
t.Errorf("Expecting url [%v], but got [%v]", url1.String(), u.String())
}
// test with params
v := url.Values{}
v.Add("op1", "OP_1")
v.Add("op2", "OP_2")
v.Add("user.name", user.Username)
url1.RawQuery = v.Encode()
params := map[string]string{
"op1": "OP_1",
"op2": "OP_2",
}
u, err = buildRequestUrl(conf, &Path{Name: "/test"}, ¶ms)
if url1 != *u {
t.Errorf("Expecting url [%v], but got [%v]", url1.String(), u.String())
}
}