Move StartTime initialization to application startup hook
- Remove StartTime initialization from globals.New() - Add setupGlobals function in app.go to set StartTime during fx OnStart - Simplify globals package to be just a key/value store - Remove fx dependencies from globals test
This commit is contained in:
@@ -3,6 +3,7 @@ package s3_test
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go-v2/config"
|
||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/aws/smithy-go/logging"
|
||||
"github.com/johannesboyne/gofakes3"
|
||||
"github.com/johannesboyne/gofakes3/backend/s3mem"
|
||||
)
|
||||
@@ -32,6 +34,7 @@ type TestServer struct {
|
||||
backend gofakes3.Backend
|
||||
s3Client *s3.Client
|
||||
tempDir string
|
||||
logBuf *bytes.Buffer
|
||||
}
|
||||
|
||||
// NewTestServer creates and starts a new test server
|
||||
@@ -62,7 +65,10 @@ func NewTestServer(t *testing.T) *TestServer {
|
||||
// Wait for server to be ready
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Create S3 client
|
||||
// Create a buffer to capture logs
|
||||
logBuf := &bytes.Buffer{}
|
||||
|
||||
// Create S3 client with custom logger
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(),
|
||||
config.WithRegion(testRegion),
|
||||
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
|
||||
@@ -71,6 +77,13 @@ func NewTestServer(t *testing.T) *TestServer {
|
||||
"",
|
||||
)),
|
||||
config.WithClientLogMode(aws.LogRetries|aws.LogRequestWithBody|aws.LogResponseWithBody),
|
||||
config.WithLogger(logging.LoggerFunc(func(classification logging.Classification, format string, v ...interface{}) {
|
||||
// Capture logs to buffer instead of stdout
|
||||
fmt.Fprintf(logBuf, "SDK %s %s %s\n",
|
||||
time.Now().Format("2006/01/02 15:04:05"),
|
||||
string(classification),
|
||||
fmt.Sprintf(format, v...))
|
||||
})),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create AWS config: %v", err)
|
||||
@@ -86,8 +99,16 @@ func NewTestServer(t *testing.T) *TestServer {
|
||||
backend: backend,
|
||||
s3Client: s3Client,
|
||||
tempDir: tempDir,
|
||||
logBuf: logBuf,
|
||||
}
|
||||
|
||||
// Register cleanup to show logs on test failure
|
||||
t.Cleanup(func() {
|
||||
if t.Failed() && logBuf.Len() > 0 {
|
||||
t.Logf("S3 SDK Debug Output:\n%s", logBuf.String())
|
||||
}
|
||||
})
|
||||
|
||||
// Create test bucket
|
||||
_, err = s3Client.CreateBucket(context.Background(), &s3.CreateBucketInput{
|
||||
Bucket: aws.String(testBucket),
|
||||
|
||||
Reference in New Issue
Block a user