/
mocks3.go
93 lines (83 loc) · 2.42 KB
/
mocks3.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
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"io/ioutil"
"path"
"strings"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3iface"
)
type mockS3 struct {
s3iface.S3API
}
func (m *mockS3) GetObject(i *s3.GetObjectInput) (*s3.GetObjectOutput, error) {
body := []byte("test")
meta := map[string]*string{}
contentType := "application/octet-stream"
switch strings.Split(*i.Key, "/")[0] {
case "page":
switch path.Base(*i.Key) {
case "index.md":
contentType = "text/x-markdown"
meta["Title"] = aws.String(base64.StdEncoding.EncodeToString([]byte("testTitle")))
meta["Author"] = aws.String("testauthor")
meta["Public"] = aws.String("true")
case "index.html":
contentType = "text/html"
meta["Title"] = aws.String(base64.StdEncoding.EncodeToString([]byte("testTitle")))
default:
contentType = "image/jpeg"
}
case "user":
contentType = "text/plain"
user := userData{
Name: "user",
ID: "userID",
}
body, _ = json.Marshal(user)
case "session":
contentType = "text/plain"
session := sessionData{
ID: "id",
Challange: "challange",
User: "user",
Login: true,
}
body, _ = json.Marshal(session)
}
return &s3.GetObjectOutput{
Body: ioutil.NopCloser(bytes.NewReader(body)),
Metadata: meta,
LastModified: aws.Time(time.Now()),
ContentType: aws.String(contentType),
}, nil
}
func (m *mockS3) HeadObject(*s3.HeadObjectInput) (*s3.HeadObjectOutput, error) {
meta := map[string]*string{}
meta["Title"] = aws.String(base64.StdEncoding.EncodeToString([]byte("testTitle")))
meta["ID"] = aws.String("testID")
meta["Author"] = aws.String("testauthor")
return &s3.HeadObjectOutput{
Metadata: meta,
LastModified: aws.Time(time.Now()),
}, nil
}
func (m *mockS3) PutObjectAcl(*s3.PutObjectAclInput) (*s3.PutObjectAclOutput, error) {
return &s3.PutObjectAclOutput{}, nil
}
func (m *mockS3) GetObjectAcl(*s3.GetObjectAclInput) (*s3.GetObjectAclOutput, error) {
return &s3.GetObjectAclOutput{}, nil
}
func (m *mockS3) PutObject(i *s3.PutObjectInput) (*s3.PutObjectOutput, error) {
return &s3.PutObjectOutput{}, nil
}
func (m *mockS3) DeleteObject(i *s3.DeleteObjectInput) (*s3.DeleteObjectOutput, error) {
return &s3.DeleteObjectOutput{}, nil
}
func (m *mockS3) ListObjectsV2(*s3.ListObjectsV2Input) (*s3.ListObjectsV2Output, error) {
return &s3.ListObjectsV2Output{}, nil
}