-
Notifications
You must be signed in to change notification settings - Fork 3
/
s3Fs_test.go
108 lines (87 loc) · 2.37 KB
/
s3Fs_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package aferoS3
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
)
// hold aws sesssion in mem
var sess *session.Session
// setup return a aws session, doesnt recreate if exisits
func setup() *session.Session {
if sess == nil {
// server is the mock server that simply writes a 200 status back to the client
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}))
return session.Must(session.NewSession(&aws.Config{
DisableSSL: aws.Bool(true),
Endpoint: aws.String(server.URL),
Credentials: credentials.NewStaticCredentials("AKID", "SECRET", "SESSION"),
Region: aws.String("mock-region"),
}))
}
return sess
}
// TestChmod(name string, mode os.FileMode) : error
// TestChtimes(name string, atime time.Time, mtime time.Time) : error
// TestCreate(name string) : File, error
func TestCreate(t *testing.T) {
appFs := NewS3Fs(setup(), "bucket_name")
file, err := appFs.Create("output.jpg")
if err != nil {
t.Fatal(err)
}
info, err := file.Stat()
if err != nil {
t.Fatal(err)
}
if info.Name() != "output.jpg" {
t.Fatal("couldnt open file")
}
}
// TestMkdir(name string, perm os.FileMode) : error
// TestMkdirAll(path string, perm os.FileMode) : error
// TestName() : string
func TestName(t *testing.T) {
appFs := NewS3Fs(setup(), "bucket_name")
if appFs.Name() != "S3Fs" {
t.Fatal("unknown module name")
}
}
// TestOpen(name string) : File, error
func TestOpen(t *testing.T) {
appFs := NewS3Fs(setup(), "bucket_name")
file, err := appFs.Open("output.jpg")
if err != nil {
t.Fatal(err)
}
info, err := file.Stat()
if err != nil {
t.Fatal(err)
}
if info.Name() != "output.jpg" {
t.Fatal("couldnt open file")
}
}
// TestOpenFile(name string, flag int, perm os.FileMode) : File, error
func TestS3OpenFile(t *testing.T) {
appFs := NewS3Fs(setup(), "bucket_name")
file, err := appFs.OpenFile("output.jpg", 0, 0777)
if err != nil {
t.Fatal(err)
}
info, err := file.Stat()
if err != nil {
t.Fatal(err)
}
if info.Name() != "output.jpg" {
t.Fatal("couldnt open file")
}
}
// TestRemove(name string) : error
// TestRemoveAll(path string) : error
// TestRename(oldname, newname string) : error
// TestStat(name string) : os.FileInfo, error