From 7b33219617121ddf7f3b0cc22469a00944b651f3 Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Mon, 10 Aug 2026 09:29:00 +1000 Subject: [PATCH] fix: slow tests --- spinifex/handlers/ec2/volume/main_test.go | 41 +++++++++++++++++++ .../volume/service_impl_encryption_test.go | 2 +- .../handlers/ec2/volume/service_impl_test.go | 4 +- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 spinifex/handlers/ec2/volume/main_test.go diff --git a/spinifex/handlers/ec2/volume/main_test.go b/spinifex/handlers/ec2/volume/main_test.go new file mode 100644 index 000000000..f64549f0e --- /dev/null +++ b/spinifex/handlers/ec2/volume/main_test.go @@ -0,0 +1,41 @@ +package handlers_ec2_volume + +import ( + "io" + "net/http" + "net/http/httptest" + "os" + "testing" +) + +// fakeS3Host is the endpoint the test volume services point Predastore at. +// Pointing it at an unserved port makes every CreateVolume burn the AWS SDK +// retry backoff in Backend.Init before failing. +var fakeS3Host string + +// TestMain stands up one in-process S3 stand-in for the package: ListObjectsV2 +// succeeds so Backend.Init's reachability probe returns immediately, and every +// other request 404s so CreateVolume still fails at the storage layer. +func TestMain(m *testing.M) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/xml") + if r.URL.Query().Get("list-type") == "2" { + w.WriteHeader(http.StatusOK) + io.WriteString(w, ``+ + ``+ + `test-bucket0`+ + `1000false`) + return + } + w.WriteHeader(http.StatusNotFound) + io.WriteString(w, ``+ + `NoSuchKey`+ + `The specified key does not exist.`) + })) + fakeS3Host = srv.URL + + code := m.Run() + + srv.Close() + os.Exit(code) +} diff --git a/spinifex/handlers/ec2/volume/service_impl_encryption_test.go b/spinifex/handlers/ec2/volume/service_impl_encryption_test.go index a81a28726..8907644cb 100644 --- a/spinifex/handlers/ec2/volume/service_impl_encryption_test.go +++ b/spinifex/handlers/ec2/volume/service_impl_encryption_test.go @@ -84,7 +84,7 @@ func newTestVolumeServiceWithEncryptionKey(az, keyFile string) *VolumeServiceImp Predastore: config.PredastoreConfig{ Bucket: "test-bucket", Region: "ap-southeast-2", - Host: "localhost:9000", + Host: fakeS3Host, AccessKey: "testkey", SecretKey: "testsecret", }, diff --git a/spinifex/handlers/ec2/volume/service_impl_test.go b/spinifex/handlers/ec2/volume/service_impl_test.go index 6598e7049..a4dcb8aeb 100644 --- a/spinifex/handlers/ec2/volume/service_impl_test.go +++ b/spinifex/handlers/ec2/volume/service_impl_test.go @@ -30,7 +30,7 @@ func newTestVolumeService(az string) *VolumeServiceImpl { Predastore: config.PredastoreConfig{ Bucket: "test-bucket", Region: "ap-southeast-2", - Host: "localhost:9000", + Host: fakeS3Host, AccessKey: "testkey", SecretKey: "testsecret", }, @@ -397,7 +397,7 @@ func newTestVolumeServiceWithStore(az string, store *objectstore.MemoryObjectSto Predastore: config.PredastoreConfig{ Bucket: "test-bucket", Region: "ap-southeast-2", - Host: "localhost:9000", + Host: fakeS3Host, AccessKey: "testkey", SecretKey: "testsecret", },