Skip to content

Commit bc137df

Browse files
committed
Remove reference to runIOTestsLocal function that is no longer used or needed. Move gs-specific test to gs conformance test
1 parent 50f133d commit bc137df

File tree

3 files changed

+74
-87
lines changed

3 files changed

+74
-87
lines changed

backend/gs/conformance_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import (
66
"os"
77
"testing"
88

9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
912
"github.com/c2fo/vfs/v7/backend/testsuite"
13+
"github.com/c2fo/vfs/v7/utils"
1014
)
1115

1216
// TestConformance runs the VFS conformance test suite against the GCS backend.
@@ -56,3 +60,57 @@ func TestIOConformance(t *testing.T) {
5660

5761
testsuite.RunIOTests(t, location)
5862
}
63+
64+
// TestPersistentFolderHandling tests GCS-specific handling of persistent "folders".
65+
// When a persistent "folder" is created through the UI, it creates a zero-length object
66+
// with a trailing "/". The UI or gsutil interprets these as folders but they are still
67+
// just objects. List() should ignore these objects.
68+
func TestPersistentFolderHandling(t *testing.T) {
69+
bucket := os.Getenv("VFS_GS_BUCKET")
70+
if bucket == "" {
71+
t.Skip("VFS_GS_BUCKET not set, skipping GCS persistent folder test")
72+
}
73+
74+
testPath := os.Getenv("VFS_GS_TEST_PATH")
75+
if testPath == "" {
76+
testPath = "/vfs-integration-test/"
77+
}
78+
79+
fs := NewFileSystem()
80+
baseLoc, err := fs.NewLocation(bucket, testPath)
81+
require.NoError(t, err)
82+
83+
// Get client since VFS doesn't allow a File ending with a slash
84+
client, err := fs.Client()
85+
require.NoError(t, err)
86+
87+
objHandle := client.
88+
Bucket(bucket).
89+
Object(utils.RemoveLeadingSlash(baseLoc.Path() + "myfolder/"))
90+
91+
ctx := t.Context()
92+
93+
// Write zero-length object to simulate persistent folder
94+
writer := objHandle.NewWriter(ctx)
95+
_, err = writer.Write([]byte(""))
96+
require.NoError(t, err)
97+
require.NoError(t, writer.Close())
98+
99+
// Create a file inside the "folder"
100+
f, err := baseLoc.NewFile("myfolder/file.txt")
101+
require.NoError(t, err)
102+
103+
_, err = f.Write([]byte("some text"))
104+
require.NoError(t, err)
105+
require.NoError(t, f.Close())
106+
107+
// List "folder" should only return file.txt, not the zero-length folder object
108+
files, err := f.Location().List()
109+
require.NoError(t, err)
110+
assert.Len(t, files, 1, "check file count found")
111+
assert.Equal(t, "file.txt", files[0], "file.txt was found")
112+
113+
// Clean up
114+
require.NoError(t, f.Delete(), "clean up file.txt")
115+
require.NoError(t, objHandle.Delete(ctx))
116+
}

backend/testsuite/backend_integration_test.go

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import (
1616
"github.com/stretchr/testify/suite"
1717

1818
"github.com/c2fo/vfs/v7"
19-
"github.com/c2fo/vfs/v7/backend/gs"
2019
_ "github.com/c2fo/vfs/v7/backend/all" // register all core backends
21-
"github.com/c2fo/vfs/v7/utils"
2220
"github.com/c2fo/vfs/v7/vfssimple"
2321
)
2422

@@ -67,68 +65,12 @@ func (s *vfsTestSuite) TestScheme() {
6765
}
6866

6967
// Run the exported conformance tests
70-
s.T().Run(scheme, func(t *testing.T) {
71-
RunConformanceTests(t, location, opts)
68+
s.Run(scheme, func() {
69+
RunConformanceTests(s.T(), location, opts)
7270
})
73-
74-
// Run GS-specific tests if applicable
75-
if scheme == "gs" {
76-
s.gsList(location)
77-
}
7871
}
7972
}
8073

81-
// gsList is a GS-specific test for handling persistent "folders"
82-
func (s *vfsTestSuite) gsList(baseLoc vfs.Location) {
83-
/*
84-
test description:
85-
When a persistent "folder" is created through the UI, it simply creates a zero length object
86-
with a trailing "/". The UI or gsutil knows to interpret these objects as folders but they are
87-
still just objects. List(), in its current state, should ignore these objects.
88-
89-
If we create the following objects:
90-
gs://bucket/some/path/to/myfolder/ -- Note that object base name is "myfolder/"
91-
gs://bucket/some/path/to/myfolder/file.txt
92-
93-
List() from location "gs://bucket/some/path/to/myfolder/" should only return object name "file.txt";
94-
"myfolder/" should be ignored.
95-
*/
96-
97-
// getting client since VFS doesn't allow a File ending with a slash
98-
client, err := baseLoc.FileSystem().(*gs.FileSystem).Client()
99-
s.Require().NoError(err)
100-
101-
objHandle := client.
102-
Bucket("enterprise-test").
103-
Object(utils.RemoveLeadingSlash(baseLoc.Path() + "myfolder/"))
104-
105-
ctx := s.T().Context()
106-
107-
// write zero length object
108-
writer := objHandle.NewWriter(ctx)
109-
_, err = writer.Write([]byte(""))
110-
s.Require().NoError(err)
111-
s.Require().NoError(writer.Close())
112-
113-
// create a file inside the "folder"
114-
f, err := baseLoc.NewFile("myfolder/file.txt")
115-
s.Require().NoError(err)
116-
117-
_, err = f.Write([]byte("some text"))
118-
s.Require().NoError(err)
119-
s.Require().NoError(f.Close())
120-
121-
// list "folder" should only return file.txt
122-
files, err := f.Location().List()
123-
s.Require().NoError(err)
124-
s.Len(files, 1, "check file count found")
125-
s.Equal("file.txt", files[0], "file.txt was found")
126-
127-
// CLEAN UP
128-
s.Require().NoError(f.Delete(), "clean up file.txt")
129-
s.Require().NoError(objHandle.Delete(ctx))
130-
}
131-
13274
func TestVFS(t *testing.T) {
13375
suite.Run(t, new(vfsTestSuite))
13476
}

backend/testsuite/io_integration_test.go

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,40 @@ import (
2121
type ioTestSuite struct {
2222
suite.Suite
2323
testLocations map[string]vfs.Location
24-
localDir string
2524
}
2625

2726
func (s *ioTestSuite) SetupSuite() {
28-
uris := make([]string, 0)
29-
3027
// add VFS_INTEGRATION_LOCATIONS tests
31-
locs := os.Getenv("VFS_INTEGRATION_LOCATIONS")
32-
uris = append(uris, strings.Split(locs, ";")...)
28+
uris := strings.Split(os.Getenv("VFS_INTEGRATION_LOCATIONS"), ";")
3329

3430
s.testLocations = make(map[string]vfs.Location)
3531
for idx := range uris {
3632
if uris[idx] == "" {
3733
continue
3834
}
39-
if strings.HasPrefix(uris[idx], "/") {
40-
s.localDir = uris[idx]
41-
} else {
42-
l, err := vfssimple.NewLocation(uris[idx])
43-
s.Require().NoError(err)
35+
l, err := vfssimple.NewLocation(uris[idx])
36+
s.Require().NoError(err)
4437

45-
// For file:// locations, ensure directory exists
46-
if l.FileSystem().Scheme() == "file" {
47-
exists, err := l.Exists()
38+
// For file:// locations, ensure directory exists
39+
if l.FileSystem().Scheme() == "file" {
40+
exists, err := l.Exists()
41+
if err != nil {
42+
panic(err)
43+
}
44+
if !exists {
45+
err := os.Mkdir(l.Path(), 0750)
4846
if err != nil {
4947
panic(err)
5048
}
51-
if !exists {
52-
err := os.Mkdir(l.Path(), 0750)
53-
if err != nil {
54-
panic(err)
55-
}
56-
}
5749
}
58-
59-
// Store location by scheme - no type assertion needed
60-
s.testLocations[l.FileSystem().Scheme()] = l
6150
}
51+
52+
// Store location by scheme - no type assertion needed
53+
s.testLocations[l.FileSystem().Scheme()] = l
6254
}
6355
}
6456

6557
func (s *ioTestSuite) TestFileOperations() {
66-
if s.localDir != "" {
67-
s.Run("local_baseline", func() {
68-
runIOTestsLocal(s.T(), s.localDir, DefaultIOTestCases())
69-
})
70-
}
7158
for scheme, location := range s.testLocations {
7259
s.Run(scheme, func() {
7360
RunIOTests(s.T(), location)

0 commit comments

Comments
 (0)