maddy

Fork https://github.com/foxcpp/maddy

git clone git://git.lin.moe/go/maddy.git

 1package s3
 2
 3import (
 4	"net/http/httptest"
 5	"testing"
 6
 7	"github.com/foxcpp/maddy/framework/config"
 8	"github.com/foxcpp/maddy/framework/module"
 9	"github.com/foxcpp/maddy/internal/storage/blob"
10	"github.com/johannesboyne/gofakes3"
11	"github.com/johannesboyne/gofakes3/backend/s3mem"
12)
13
14func TestFS(t *testing.T) {
15	var (
16		backend gofakes3.Backend
17		faker   *gofakes3.GoFakeS3
18		ts      *httptest.Server
19	)
20
21	blob.TestStore(t, func() module.BlobStore {
22		backend = s3mem.New()
23		faker = gofakes3.New(backend)
24		ts = httptest.NewServer(faker.Server())
25
26		if err := backend.CreateBucket("maddy-test"); err != nil {
27			panic(err)
28		}
29
30		st := &Store{instName: "test"}
31		err := st.Init(config.NewMap(map[string]interface{}{}, config.Node{
32			Children: []config.Node{
33				{
34					Name: "endpoint",
35					Args: []string{ts.Listener.Addr().String()},
36				},
37				{
38					Name: "secure",
39					Args: []string{"false"},
40				},
41				{
42					Name: "access_key",
43					Args: []string{"access-key"},
44				},
45				{
46					Name: "secret_key",
47					Args: []string{"secret-key"},
48				},
49				{
50					Name: "bucket",
51					Args: []string{"maddy-test"},
52				},
53			},
54		}))
55		if err != nil {
56			panic(err)
57		}
58
59		return st
60	}, func(store module.BlobStore) {
61		ts.Close()
62
63		backend = s3mem.New()
64		faker = gofakes3.New(backend)
65		ts = httptest.NewServer(faker.Server())
66	})
67
68	if ts != nil {
69		ts.Close()
70	}
71}