From b5349bf6df24d9a587aba396fe0af574503b2584 Mon Sep 17 00:00:00 2001 From: chrislu Date: Sun, 24 Aug 2025 12:34:58 -0700 Subject: [PATCH] fix: Resolve compilation errors in Keycloak integration tests - Remove unused imports (time, bytes) from test files - Add missing S3 object manipulation methods to test framework - Fix io.Copy usage for reading S3 object content - Ensure all Keycloak integration tests compile successfully Changes: - Remove unused 'time' import from s3_keycloak_integration_test.go - Remove unused 'bytes' import from s3_iam_framework.go - Add io import for proper stream handling - Implement PutTestObject, GetTestObject, ListTestObjects, DeleteTestObject methods - Fix content reading using io.Copy instead of non-existent ReadFrom method All tests now compile successfully and the distributed IAM system is ready for testing with both mock and real Keycloak authentication. --- test/s3/iam/s3_iam_framework.go | 58 ++++++++++++++++++++- test/s3/iam/s3_keycloak_integration_test.go | 1 - 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/test/s3/iam/s3_iam_framework.go b/test/s3/iam/s3_iam_framework.go index 1d2b2db2b..1cd1c921e 100644 --- a/test/s3/iam/s3_iam_framework.go +++ b/test/s3/iam/s3_iam_framework.go @@ -1,13 +1,13 @@ package iam import ( - "bytes" "context" "crypto/rand" "crypto/rsa" "encoding/base64" "encoding/json" "fmt" + "io" "net/http" "net/http/httptest" "net/url" @@ -578,6 +578,62 @@ func (f *S3IAMTestFramework) WaitForS3Service() error { return fmt.Errorf("S3 service not available after %d retries", maxRetries) } +// PutTestObject puts a test object in the specified bucket +func (f *S3IAMTestFramework) PutTestObject(client *s3.S3, bucket, key, content string) error { + _, err := client.PutObject(&s3.PutObjectInput{ + Bucket: aws.String(bucket), + Key: aws.String(key), + Body: strings.NewReader(content), + }) + return err +} + +// GetTestObject retrieves a test object from the specified bucket +func (f *S3IAMTestFramework) GetTestObject(client *s3.S3, bucket, key string) (string, error) { + result, err := client.GetObject(&s3.GetObjectInput{ + Bucket: aws.String(bucket), + Key: aws.String(key), + }) + if err != nil { + return "", err + } + defer result.Body.Close() + + content := strings.Builder{} + _, err = io.Copy(&content, result.Body) + if err != nil { + return "", err + } + + return content.String(), nil +} + +// ListTestObjects lists objects in the specified bucket +func (f *S3IAMTestFramework) ListTestObjects(client *s3.S3, bucket string) ([]string, error) { + result, err := client.ListObjects(&s3.ListObjectsInput{ + Bucket: aws.String(bucket), + }) + if err != nil { + return nil, err + } + + var keys []string + for _, obj := range result.Contents { + keys = append(keys, *obj.Key) + } + + return keys, nil +} + +// DeleteTestObject deletes a test object from the specified bucket +func (f *S3IAMTestFramework) DeleteTestObject(client *s3.S3, bucket, key string) error { + _, err := client.DeleteObject(&s3.DeleteObjectInput{ + Bucket: aws.String(bucket), + Key: aws.String(key), + }) + return err +} + // WaitForS3Service waits for the S3 service to be available (simplified version) func (f *S3IAMTestFramework) WaitForS3ServiceSimple() error { // This is a simplified version that just checks if the endpoint responds diff --git a/test/s3/iam/s3_keycloak_integration_test.go b/test/s3/iam/s3_keycloak_integration_test.go index 9f3f4c460..007097c87 100644 --- a/test/s3/iam/s3_keycloak_integration_test.go +++ b/test/s3/iam/s3_keycloak_integration_test.go @@ -3,7 +3,6 @@ package iam import ( "os" "testing" - "time" "github.com/aws/aws-sdk-go/service/s3" "github.com/stretchr/testify/assert"