This repository was archived by the owner on Jun 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paths3_test.go
More file actions
77 lines (60 loc) · 2.29 KB
/
Copy paths3_test.go
File metadata and controls
77 lines (60 loc) · 2.29 KB
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
package filecache_test
import (
"context"
"os"
"time"
. "github.com/Nitro/filecache"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("S3", func() {
var (
manager *S3RegionManagedDownloader
localFile *os.File
)
BeforeEach(func() {
// Reset between runs
manager = NewS3RegionManagedDownloader("us-west-2")
var err error
localFile, err = os.Create("foo.pdf")
Expect(err).To(BeNil())
})
AfterEach(func() { localFile.Close() })
Describe("NewS3RegionManagedDownloader()", func() {
It("returns a properly configured instance", func() {
Expect(manager).NotTo(BeNil())
Expect(manager.DefaultRegion).To(Equal("us-west-2"))
Expect(manager.DownloaderCache).NotTo(BeNil())
})
})
// This test will actually contact S3... not in love with that
// but don't want to mock it out, either. Could be mocked out:
// https://docs.aws.amazon.com/sdk-for-go/api/service/s3/s3iface/#S3API
Describe("GetDownloader()", func() {
It("returns a newly created downloader", func() {
dLoader, err := manager.GetDownloader(context.Background(), "nitro-public")
Expect(err).To(BeNil())
Expect(dLoader).NotTo(BeNil())
Expect(dLoader.S3).NotTo(BeNil())
})
It("returns a cached downloader", func() {
dLoader1, err := manager.GetDownloader(context.Background(), "nitro-public")
Expect(err).To(BeNil())
dLoader2, err := manager.GetDownloader(context.Background(), "nitro-public")
Expect(err).To(BeNil())
Expect(dLoader1).To(Equal(dLoader2))
})
It("returns an error when trying to fetch a file from a non-existent bucket", func() {
err := manager.Download(&DownloadRecord{Path: "non-existent-bucket/foo.pdf"}, localFile, 10*time.Second)
Expect(err.Error()).To(ContainSubstring("Unable to get downloader for non-existent-bucket: Region for non-existent-bucket not found"))
})
It("returns an error when trying to fetch a file which doesn't exist", func() {
err := manager.Download(&DownloadRecord{Path: "nitro-junk/non-existent-foo.pdf"}, localFile, 10*time.Second)
Expect(err.Error()).To(ContainSubstring("Could not fetch from S3"))
})
It("returns an error when getting a 0 length file", func() {
err := manager.Download(&DownloadRecord{Path: "nitro-junk/foo.pdf"}, localFile, 10*time.Second)
Expect(err.Error()).NotTo(BeNil())
})
})
})