-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_test.go
69 lines (60 loc) · 1.55 KB
/
api_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
65
66
67
68
69
package ydfs
import (
"bytes"
"context"
"fmt"
"net/http"
"os"
"testing"
)
var client *apiclient
func TestMain(m *testing.M) {
token, ok := os.LookupEnv("YD")
if !ok {
fmt.Println("environment variable YD not set. skipping integration tests")
os.Exit(0)
}
client = newApiClient(token, http.DefaultClient)
os.Exit(m.Run())
}
func Test_doRequest(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, urlBase, nil)
if err != nil {
t.Errorf("error creating request %v", err)
}
_, err = client.do(context.TODO(), r, http.StatusOK)
if err != nil {
t.Errorf("client.do returned %v", err)
}
}
func Test_requestInterface(t *testing.T) {
var d = &diskInfo{}
err := client.requestInterface(http.MethodGet, http.StatusOK, urlBase, nil, d)
if err != nil {
t.Errorf("client.requestInterface returned: %v", err)
}
}
func Test_getResourceMinTraffic(t *testing.T) {
res, err := client.getResourceMinTraffic("/")
if err != nil {
t.Errorf("client.getResourceMinTraffic returned: %v", err)
}
if res.Name == "" && res.Path == "" && res.Modified.IsZero() && res.Type == "" {
t.Errorf("missing required data in response from client.getResourceMinTraffic")
}
}
func Test_putFile(t *testing.T) {
err := client.putFileTruncate(testFileName, testFileBody)
if err != nil {
t.Logf("upload test file failed: %v", err)
}
}
func Test_getFile(t *testing.T) {
b, err := client.getFile(testFileName)
if err != nil {
t.Errorf("getting test file failed: %v", err)
}
if !bytes.Equal(b, testFileBody) {
t.Errorf("error comparing testfile with fetched result")
}
}