Browse Source

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.
pull/7160/head
chrislu 1 month ago
parent
commit
b5349bf6df
  1. 58
      test/s3/iam/s3_iam_framework.go
  2. 1
      test/s3/iam/s3_keycloak_integration_test.go

58
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

1
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"

Loading…
Cancel
Save