Skip to content

Commit

Permalink
add TestDefaultSettingsUploadDownload
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Dec 19, 2024
1 parent 8642135 commit 7dc696f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
11 changes: 7 additions & 4 deletions internal/test/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ type testClusterOptions struct {
hosts int
logger *zap.Logger
uploadPacking bool
skipSettingAutopilot bool
skipRunningAutopilot bool
skipSettingAutopilot bool
skipUpdatingSettings bool
walletKey *types.PrivateKey

autopilotCfg *config.Autopilot
Expand Down Expand Up @@ -474,9 +475,11 @@ func newTestCluster(t *testing.T, opts testClusterOptions) *TestCluster {
}

// Update the bus settings.
tt.OK(busClient.UpdateGougingSettings(ctx, test.GougingSettings))
tt.OK(busClient.UpdateUploadSettings(ctx, us))
tt.OK(busClient.UpdateS3Settings(ctx, s3))
if !opts.skipUpdatingSettings {
tt.OK(busClient.UpdateGougingSettings(ctx, test.GougingSettings))
tt.OK(busClient.UpdateUploadSettings(ctx, us))
tt.OK(busClient.UpdateS3Settings(ctx, s3))
}

// Fund the bus.
if funding {
Expand Down
60 changes: 60 additions & 0 deletions internal/test/e2e/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"go.sia.tech/renterd/internal/test"
"go.sia.tech/renterd/internal/utils"
"go.sia.tech/renterd/object"
"go.sia.tech/renterd/stores/sql"
"go.sia.tech/renterd/stores/sql/sqlite"
"lukechampine.com/frand"
)
Expand Down Expand Up @@ -3087,3 +3088,62 @@ func TestV1ToV2Transition(t *testing.T) {
return nil
})
}

func TestDefaultSettingsUploadDownload(t *testing.T) {
// create a test cluster
apCfg := test.AutopilotConfig
apCfg.Contracts.Amount = uint64(api.DefaultRedundancySettingsTestnet.TotalShards)
cluster := newTestCluster(t, testClusterOptions{
hosts: api.DefaultRedundancySettingsTestnet.TotalShards,
logger: newTestLogger(false),
skipUpdatingSettings: true,
autopilotConfig: &apCfg,
})
defer cluster.Shutdown()

b := cluster.Bus
w := cluster.Worker
tt := cluster.tt

// sanity check settings
_, err := cluster.bs.GougingSettings(context.Background())
tt.AssertIs(err, sql.ErrSettingNotFound)
_, err = cluster.bs.PinnedSettings(context.Background())
tt.AssertIs(err, sql.ErrSettingNotFound)
_, err = cluster.bs.S3Settings(context.Background())
tt.AssertIs(err, sql.ErrSettingNotFound)
_, err = cluster.bs.UploadSettings(context.Background())
tt.AssertIs(err, sql.ErrSettingNotFound)

// prepare a file
data := make([]byte, 128)
tt.OKAll(frand.Read(data))

// upload and download data the native way
path := "/regularFile"
tt.OKAll(w.UploadObject(context.Background(), bytes.NewReader(data), testBucket, path, api.UploadObjectOptions{}))
tt.OK(w.DownloadObject(context.Background(), bytes.NewBuffer(nil), testBucket, path, api.DownloadObjectOptions{}))

// upload and download a multipart upload
multipartPath := "/multipartFile"
mpu, err := b.CreateMultipartUpload(context.Background(), testBucket, multipartPath, api.CreateMultipartOptions{})
tt.OK(err)
offset := 0
part, err := w.UploadMultipartUploadPart(context.Background(), bytes.NewReader(data), testBucket, multipartPath, mpu.UploadID, 1, api.UploadMultipartUploadPartOptions{EncryptionOffset: &offset})
tt.OK(err)
tt.OKAll(b.CompleteMultipartUpload(context.Background(), testBucket, multipartPath, mpu.UploadID, []api.MultipartCompletedPart{
{
PartNumber: 1,
ETag: part.ETag,
},
}, api.CompleteMultipartOptions{}))
tt.OK(err)
tt.OK(w.DownloadObject(context.Background(), bytes.NewBuffer(nil), testBucket, multipartPath, api.DownloadObjectOptions{}))

// upload and download via s3 to test the default s3 settings
s3Path := "/s3File"
_, err = cluster.S3.PutObject(testBucket, s3Path, bytes.NewReader(data), putObjectOptions{})
if err == nil || !strings.Contains(err.Error(), "AccessDenied") {
t.Fatal("expected access denied error")
}
}
2 changes: 1 addition & 1 deletion internal/test/e2e/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var defaultHostSettings = settings.Settings{
IngressPrice: types.Siacoins(100).Div64(1e12),
WindowSize: 5,

PriceTableValidity: 10 * time.Second,
PriceTableValidity: 5 * time.Minute,

AccountExpiry: 30 * 24 * time.Hour, // 1 month
MaxAccountBalance: types.Siacoins(10),
Expand Down

0 comments on commit 7dc696f

Please sign in to comment.