-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3p_test.go
99 lines (91 loc) · 2.39 KB
/
s3p_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
package iokit_aws
import (
"fmt"
"go4ml.xyz/iokit"
"gotest.tools/assert"
"io/ioutil"
"math/rand"
"testing"
)
/*
S3 tests use S3_AWS_TEST_URL and S3_DO_TEST_URL environment variables
S3_name_URL = s3://key:[email protected]/bucket/prefix
*/
func Test_S3Path1(t *testing.T) {
for i, url := range []string{
"s3://$do_test/go-iokit/test_s3path.txt",
"s3://$aws_test/go-iokit/test_s3path.txt"} {
S := fmt.Sprintf(`Hello world! %d`, i)
wh := iokit.Url(url).MustCreate()
defer wh.End()
wh.MustWrite([]byte(S))
wh.MustCommit()
rd := iokit.Url(url).MustOpen()
defer rd.Close()
q := rd.MustReadAll()
assert.Assert(t, string(q) == S)
}
}
func Test_S3Path2(t *testing.T) {
for i, url := range []string{
"s3://$do_test/go-iokit/test_s3path.txt",
"s3://$aws_test/go-iokit/test_s3path.txt"} {
S := fmt.Sprintf(`Hello world! %d`, i)
file := iokit.Url(url, iokit.Cache("go-iokit/test_s3path.txt"))
wh, err := file.Create()
assert.NilError(t, err)
defer wh.End()
_, err = wh.Write([]byte(S))
assert.NilError(t, err)
err = wh.Commit()
assert.NilError(t, err)
wh.End()
rd, err := file.Open()
assert.NilError(t, err)
defer rd.Close()
q, err := ioutil.ReadAll(rd)
assert.NilError(t, err)
assert.Assert(t, string(q) == S)
rd.Close()
}
for i, url := range []string{
"s3://$do_test/go-iokit/test_s3path.txt",
"s3://$aws_test/go-iokit/test_s3path.txt"} {
S := fmt.Sprintf(`Hello world! %d`, i)
rd, err := iokit.Url(url).Open()
assert.NilError(t, err)
defer rd.Close()
q, err := ioutil.ReadAll(rd)
assert.NilError(t, err)
assert.Assert(t, string(q) == S)
}
}
func Test_Example1(t *testing.T) {
url := "s3://$do_test/go-iokit/test_s3path.txt"
S := fmt.Sprintf(`Hello world! %d`, rand.Int())
wh := iokit.Url(url).MustCreate()
defer wh.End()
wh.MustWrite([]byte(S))
wh.MustCommit()
rd := iokit.Url(url).MustOpen()
defer rd.Close()
q := rd.MustReadAll()
assert.Assert(t, string(q) == S)
}
func Test_Example2(t *testing.T) {
url := "s3://$do_test/go-iokit/test_s3path.txt"
S := fmt.Sprintf(`Hello world! %d`, rand.Int())
wh, err := iokit.Url(url).Create()
assert.NilError(t, err)
defer wh.End()
_, err = wh.Write([]byte(S))
assert.NilError(t, err)
err = wh.Commit()
assert.NilError(t, err)
rd, err := iokit.Url(url).Open()
assert.NilError(t, err)
defer rd.Close()
q, err := ioutil.ReadAll(rd)
assert.NilError(t, err)
assert.Assert(t, string(q) == S)
}