-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexists_test.go
More file actions
73 lines (62 loc) · 1.63 KB
/
Copy pathexists_test.go
File metadata and controls
73 lines (62 loc) · 1.63 KB
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
package gs
import (
"context"
"encoding/json"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/viant/afs/asset"
"github.com/viant/afs/storage"
"github.com/viant/afs/url"
"google.golang.org/api/option"
)
func TestStorager_Exists(t *testing.T) {
ctx := context.Background()
jwtConfig, err := NewTestJwtConfig()
if err != nil {
t.Skip(err)
return
}
JSON, err := json.Marshal(jwtConfig)
var useCases = []struct {
description string
URL string
assets []*asset.Resource
}{
{
description: "exists with custom option",
URL: fmt.Sprintf("gs://%v/", TestBucket),
assets: []*asset.Resource{
asset.NewFile("option001/folder1/asset1.txt", []byte("test is test 2"), 0655),
asset.NewFile("option001/folder1/asset2.txt", []byte("test is test 3"), 0655),
},
},
}
jsonAuth := option.WithCredentialsJSON(JSON)
mgr := New(NewClientOptions(jsonAuth), NewProject(TestProject))
defer func() {
_ = mgr.Delete(ctx, fmt.Sprintf("gs://%v/", TestBucket))
}()
for _, useCase := range useCases {
err = asset.Create(mgr, useCase.URL, useCase.assets)
checker := mgr.(storage.Checker)
err = asset.Create(mgr, useCase.URL, useCase.assets)
if !assert.Nil(t, err, useCase.description) {
continue
}
for _, resource := range useCase.assets {
{
URL := url.Join(useCase.URL, resource.Name)
exists, err := checker.Exists(ctx, URL)
assert.Nil(t, err)
assert.True(t, exists)
}
{
URL := url.Join(useCase.URL, resource.Name+".not")
exists, err := checker.Exists(ctx, URL)
assert.Nil(t, err)
assert.False(t, exists, useCase.description)
}
}
}
}