Skip to content

Commit c0312b6

Browse files
committed
add: table tests for s3 config variations
1 parent f15d17e commit c0312b6

File tree

3 files changed

+715
-620
lines changed

3 files changed

+715
-620
lines changed

pkg/client/client_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
var c, _ = New(context.Background(), Options{
1616
S3BucketName: os.Getenv("WORKSPACE_PROVIDER_S3_BUCKET"),
1717
S3BaseEndpoint: os.Getenv("WORKSPACE_PROVIDER_S3_BASE_ENDPOINT"),
18+
S3UsePathStyle: os.Getenv("WORKSPACE_PROVIDER_S3_USE_PATH_STYLE") == "true",
1819
})
1920

2021
func TestProviders(t *testing.T) {
@@ -73,7 +74,7 @@ func TestCreateAndRmS3Provider(t *testing.T) {
7374
bucket, dir, _ := strings.Cut(strings.TrimPrefix(id, S3Provider+"://"), "/")
7475
testS3Provider := &s3Provider{
7576
bucket: bucket,
76-
client: s3Prv.client,
77+
client: s3TestSetups[0].provider.client,
7778
}
7879

7980
// Nothing should be created
@@ -308,6 +309,10 @@ func TestCreateAndRmS3ProviderFromDirectoryProvider(t *testing.T) {
308309
t.Errorf("unexpected error when listing workspaceContent: %v", err)
309310
}
310311

312+
if len(workspaceContent) == 0 {
313+
t.Fatalf("workspaceContent is empty")
314+
}
315+
311316
if len(workspaceContent) != 1 {
312317
t.Errorf("unexpected number of workspaceContent: %d", len(workspaceContent))
313318
}

pkg/client/directory_test.go

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ import (
1313
"testing"
1414
)
1515

16+
type s3TestSetup struct {
17+
name string
18+
factory workspaceFactory
19+
testingID string
20+
provider *s3Provider
21+
}
22+
1623
var (
1724
directoryFactory workspaceFactory
18-
s3Factory workspaceFactory
1925
directoryTestingID string
20-
s3TestingID string
2126
dirPrv workspaceClient
22-
s3Prv *s3Provider
27+
s3TestSetups []s3TestSetup
2328
skipS3Tests = os.Getenv("WORKSPACE_PROVIDER_S3_BUCKET") == ""
2429
)
2530

@@ -29,12 +34,31 @@ func TestMain(m *testing.M) {
2934
dirPrv, _ = directoryFactory.New(directoryTestingID)
3035

3136
if !skipS3Tests {
32-
s3Factory, _ = newS3(context.Background(), os.Getenv("WORKSPACE_PROVIDER_S3_BUCKET"), os.Getenv("WORKSPACE_PROVIDER_S3_BASE_ENDPOINT"), os.Getenv("WORKSPACE_PROVIDER_S3_USE_PATH_STYLE") == "true")
33-
// This won't ever error because it doesn't create anything.
34-
s3TestingID = s3Factory.Create()
37+
if os.Getenv("WORKSPACE_PROVIDER_S3_USE_PATH_STYLE") != "true" {
38+
s3Factory, _ := newS3(context.Background(), os.Getenv("WORKSPACE_PROVIDER_S3_BUCKET"), os.Getenv("WORKSPACE_PROVIDER_S3_BASE_ENDPOINT"), false)
39+
// This won't ever error because it doesn't create anything.
40+
s3TestingID := s3Factory.Create()
41+
42+
s3Client, _ := s3Factory.New(s3TestingID)
43+
s3Prv := s3Client.(*s3Provider)
44+
s3TestSetups = append(s3TestSetups, s3TestSetup{
45+
name: "default",
46+
factory: s3Factory,
47+
testingID: s3TestingID,
48+
provider: s3Prv,
49+
})
50+
}
51+
52+
s3PathStyleFactory, _ := newS3(context.Background(), os.Getenv("WORKSPACE_PROVIDER_S3_BUCKET"), os.Getenv("WORKSPACE_PROVIDER_S3_BASE_ENDPOINT"), true)
53+
s3PathStyleTestingID := s3PathStyleFactory.Create()
54+
s3PathStyleClient, _ := s3PathStyleFactory.New(s3PathStyleTestingID)
55+
s3TestSetups = append(s3TestSetups, s3TestSetup{
56+
name: "use-path-style",
57+
factory: s3PathStyleFactory,
58+
testingID: s3PathStyleTestingID,
59+
provider: s3PathStyleClient.(*s3Provider),
60+
})
3561

36-
s3Client, _ := s3Factory.New(s3TestingID)
37-
s3Prv = s3Client.(*s3Provider)
3862
}
3963

4064
exitCode := m.Run()
@@ -45,8 +69,10 @@ func TestMain(m *testing.M) {
4569
}
4670

4771
if !skipS3Tests {
48-
if err := s3Factory.Rm(context.Background(), s3TestingID); err != nil {
49-
errs = append(errs, fmt.Errorf("error removing s3 workspace: %v", err))
72+
for _, s3TS := range s3TestSetups {
73+
if err := s3TS.factory.Rm(context.Background(), s3TS.testingID); err != nil {
74+
errs = append(errs, fmt.Errorf("error removing s3 workspace: %v", err))
75+
}
5076
}
5177
}
5278

0 commit comments

Comments
 (0)