-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_linux_test.go
66 lines (54 loc) · 1.28 KB
/
server_linux_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
//go:build linux
package fs
import (
"context"
"github.com/hown3d/s3-csi/internal/aws/s3"
"github.com/stretchr/testify/assert"
"io"
"os"
"path/filepath"
"syscall"
"testing"
"time"
)
func TestMkdir(t *testing.T) {
cfg := new(Config)
setupEnvironment(t, cfg)
dirName := "testdir"
fullDirName := filepath.Join(cfg.MountDir, dirName)
err := os.Mkdir(fullDirName, 0755)
failIfErr(t, err)
ctx := context.Background()
obj := cfg.S3Client.NewObject(cfg.BucketName, dirName+"/")
assert.True(t, obj.Exists(ctx))
r, err := obj.Read(ctx, nil)
failIfErr(t, err)
data, err := io.ReadAll(r)
failIfErr(t, err)
assert.Equal(t, 0, len(data))
}
func TestSetAttrs(t *testing.T) {
now := time.Date(2000, 1, 1, 1, 1, 1, 1, time.Local)
originalTimeNow := s3.TimeNowFunc
s3.TimeNowFunc = func() time.Time {
return now
}
defer func() {
s3.TimeNowFunc = originalTimeNow
}()
cfg := new(Config)
setupEnvironment(t, cfg)
key := "testfile"
name := filepath.Join(cfg.MountDir, key)
f, err := os.Create(name)
defer f.Close()
assert.NoError(t, err)
fileInfo, err := f.Stat()
assert.NoError(t, err)
sysFileInfo := fileInfo.Sys()
stat, ok := sysFileInfo.(*syscall.Stat_t)
if !ok {
t.Fatalf("%T is not syscall.Stat_t", sysFileInfo)
}
assert.Equal(t, now, time.Unix(stat.Ctim.Unix()))
}