-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbucket_test.go
71 lines (53 loc) · 1.9 KB
/
bucket_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
package gcpbatchtracker_test
import (
"fmt"
"os"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/dgruber/gcpbatchtracker"
)
var _ = Describe("Bucket", func() {
testBucketName := "gs://dg-testbucket-creation-test"
Context("Bucket tests with mock", func() {
It("should create a bucket", func() {
if os.Getenv("GCPBATCHTRACKER_BUCKET_TEST") != "true" {
Skip("GCPBATCHTRACKER_BUCKET_TEST not set")
}
fmt.Printf("GCPBATCHTRACKER_BUCKET_TEST: %s\n",
os.Getenv("GCPBATCHTRACKER_BUCKET_TEST"))
if os.Getenv("GCPBATCHTRACKER_PROJECT") == "" {
Skip("GCPBATCHTRACKER_PROJECT not set")
}
fmt.Printf("GCPBATCHTRACKER_PROJECT: %s\n",
os.Getenv("GCPBATCHTRACKER_PROJECT"))
// bucket should not exist hence we expect an error
err := gcpbatchtracker.CopyFileToBucket(testBucketName,
"testdata/bucket_test", "bucket_test.test")
Expect(err).To(HaveOccurred())
// create bucket
err = gcpbatchtracker.CreateMissingStageOutBuckets(
os.Getenv("GCPBATCHTRACKER_PROJECT"),
map[string]string{"/output": testBucketName})
Expect(err).ToNot(HaveOccurred())
// copy file to bucket
err = gcpbatchtracker.CopyFileToBucket(testBucketName,
"testdata/bucket_test.test", "bucket_test.test")
Expect(err).NotTo(HaveOccurred())
// copy file from bucket to local
err = gcpbatchtracker.CopyFileFromBucket(testBucketName,
"testdata/bucket_test.test", "bucket_test.test_copy")
Expect(err).NotTo(HaveOccurred())
// check if file exists
fi, err := os.Stat("./bucket_test.test")
Expect(err).NotTo(HaveOccurred())
Expect(fi.Size()).To(BeNumerically(">", 0))
// delete file in bucket
err = gcpbatchtracker.DeleteFileInBucket(testBucketName,
"testdata/bucket_test.test")
Expect(err).NotTo(HaveOccurred())
// delete bucket
err = gcpbatchtracker.DeleteBucket(testBucketName)
Expect(err).NotTo(HaveOccurred())
})
})
})