-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuller_test.go
62 lines (55 loc) · 1.64 KB
/
puller_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
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestRetrieveResources(t *testing.T) {
testFileName := "test.jpg"
testFileType := "image"
testFileData := "some file data blah blah blah"
testServer := httptest.NewServer(
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
//w.Header().Set("Content-Type", "application/xml")
fmt.Fprint(w, testFileData)
}))
defer testServer.Close()
resource := RetrieveResource(testServer.URL+"/"+testFileName, testFileType)
if resource.Filename != testFileName {
t.Errorf("Expected Filename: %q, got %q", testFileName, resource.Filename)
}
if resource.Filetype != testFileType {
t.Errorf("Expected Filetype: %q, got %q", testFileType, resource.Filetype)
}
if string(resource.Data) != testFileData {
t.Errorf("Expected Filetype: %q, got %q", testFileData, resource.Data)
}
}
//TODO: How do i test filesystem in go?
// func TestSaveResource(t *testing.T) {
// testDirectory := "testdata"
// testFileName := "testfile.jpg"
// testFileData := "some bytes"
// resource := &puller.RemoteResource{
// Filename: testFileName,
// Filetype: "image",
// Data: []byte(testFileData),
// }
// absoluteFilePath, err := filepath.Abs(testDirectory)
// if err != nil {
// t.Errorf("Error determining filepath: %s", err)
// }
// err = resource.SaveResource(absoluteFilePath)
// if err != nil {
// t.Error(err)
// }
// fileData, err := ioutil.ReadFile(absoluteFilePath)
// if err != nil {
// t.Errorf("Error readinf file: %s", testFileName)
// }
// if string(fileData) != testFileData {
// t.Error("File data was not read correctly!")
// }
// }