-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathfaker_test.go
96 lines (86 loc) · 2.09 KB
/
faker_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
package afs
import (
"context"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/viant/afs/option"
"github.com/viant/afs/storage"
"io"
"io/ioutil"
"os"
"strings"
"testing"
)
func TestNewFaker(t *testing.T) {
var useCases = []struct {
description string
URL string
data string
errorType string
mode os.FileMode
options []storage.Option
}{
{
description: "simple upload/download",
URL: "s3://myBucket/folder/asset.txt",
mode: 0644,
data: "this is test",
},
{
description: "upload error",
URL: "s3://myBucket/folder/errUpload.txt",
options: []storage.Option{
option.NewUploadError(io.EOF),
},
errorType: option.ErrorTypeUpload,
mode: 0644,
data: "this is test",
},
{
description: "download error",
URL: "s3://myBucket/folder/errDownload.txt",
options: []storage.Option{
option.NewDownloadError(io.EOF),
},
errorType: option.ErrorTypeDownload,
mode: 0644,
data: "this is test",
},
{
description: "download error",
URL: "s3://myBucket/folder/errReader.txt",
errorType: option.ErrorTypeReader,
options: []storage.Option{
option.NewReaderError(fmt.Errorf("this it test")),
},
mode: 0644,
data: "this is test",
},
}
ctx := context.Background()
for _, useCase := range useCases {
service := NewFaker()
err := service.Upload(ctx, useCase.URL, useCase.mode, strings.NewReader(useCase.data), useCase.options...)
var reader io.ReadCloser
if err == nil {
reader, err = service.OpenURL(ctx, useCase.URL)
}
switch useCase.errorType {
case option.ErrorTypeUpload:
assert.NotNil(t, err)
continue
case option.ErrorTypeDownload:
assert.NotNil(t, err)
continue
case option.ErrorTypeReader:
_, err := ioutil.ReadAll(reader)
assert.NotNil(t, err)
continue
default:
assert.Nil(t, err, useCase.description)
actual, err := ioutil.ReadAll(reader)
assert.Nil(t, err, useCase.description)
assert.EqualValues(t, useCase.data, string(actual), useCase.description)
}
}
}