-
Notifications
You must be signed in to change notification settings - Fork 0
/
storager_path.go
70 lines (50 loc) · 1.3 KB
/
storager_path.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
package tests
import (
"bytes"
"fmt"
"io"
"math/rand"
"github.com/google/uuid"
"github.com/stretchr/testify/suite"
"github.com/fastone-open/go-storage/pkg/randbytes"
)
type storagePathSuite struct {
suite.Suite
p *StorageSuite
base string
path string
}
func (s *storagePathSuite) SetupTest() {
s.base = uuid.NewString()
s.path = uuid.NewString()
}
func (s *storagePathSuite) TearDownTest() {
path := fmt.Sprintf("%s/%s", s.base, s.path)
err := s.p.store.Delete(path)
s.NoError(err)
}
func (s *storagePathSuite) TestAbsPath() {
m := s.p.store.Metadata()
path := fmt.Sprintf("%s%s/%s", m.WorkDir, s.base, s.path)
size := rand.Int63n(4 * 1024 * 1024)
content, err := io.ReadAll(io.LimitReader(randbytes.NewRand(), size))
s.NoError(err)
_, err = s.p.store.Write(path, bytes.NewReader(content), size)
s.NoError(err)
var buf bytes.Buffer
n, err := s.p.store.Read(path, &buf)
s.NoError(err)
s.Equal(size, n)
}
func (s *storagePathSuite) TestBackslash() {
path := s.base + "\\" + s.path
size := rand.Int63n(4 * 1024 * 1024)
content, err := io.ReadAll(io.LimitReader(randbytes.NewRand(), size))
s.NoError(err)
_, err = s.p.store.Write(path, bytes.NewReader(content), size)
s.NoError(err)
var buf bytes.Buffer
n, err := s.p.store.Read(path, &buf)
s.NoError(err)
s.Equal(size, n)
}