|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +@test "Create and Verify Seeweedfs Bucket" { |
| 4 | + # Create the bucket resource |
| 5 | + name='test' |
| 6 | + kubectl apply -f - <<EOF |
| 7 | +apiVersion: apps.cozystack.io/v1alpha1 |
| 8 | +kind: Bucket |
| 9 | +metadata: |
| 10 | + name: ${name} |
| 11 | + namespace: tenant-test |
| 12 | +spec: {} |
| 13 | +EOF |
| 14 | + |
| 15 | + # Wait for the bucket to be ready |
| 16 | + kubectl -n tenant-test wait hr bucket-${name} --timeout=100s --for=condition=ready |
| 17 | + kubectl -n tenant-test wait bucketclaims.objectstorage.k8s.io bucket-${name} --timeout=300s --for=jsonpath='{.status.bucketReady}' |
| 18 | + kubectl -n tenant-test wait bucketaccesses.objectstorage.k8s.io bucket-${name} --timeout=300s --for=jsonpath='{.status.accessGranted}' |
| 19 | + |
| 20 | + # Get and decode credentials |
| 21 | + kubectl -n tenant-test get secret bucket-${name} -ojsonpath='{.data.BucketInfo}' | base64 -d > bucket-test-credentials.json |
| 22 | + |
| 23 | + # Get credentials from the secret |
| 24 | + ACCESS_KEY=$(jq -r '.spec.secretS3.accessKeyID' bucket-test-credentials.json) |
| 25 | + SECRET_KEY=$(jq -r '.spec.secretS3.accessSecretKey' bucket-test-credentials.json) |
| 26 | + BUCKET_NAME=$(jq -r '.spec.bucketName' bucket-test-credentials.json) |
| 27 | + |
| 28 | + # Start port-forwarding |
| 29 | + bash -c 'timeout 100s kubectl port-forward service/seaweedfs-s3 -n tenant-root 8333:8333 > /dev/null 2>&1 &' |
| 30 | + |
| 31 | + # Wait for port-forward to be ready |
| 32 | + timeout 30 sh -ec 'until nc -z localhost 8333; do sleep 1; done' |
| 33 | + |
| 34 | + # Set up MinIO alias with error handling |
| 35 | + mc alias set local https://localhost:8333 $ACCESS_KEY $SECRET_KEY --insecure |
| 36 | + |
| 37 | + # Upload file to bucket |
| 38 | + mc cp bucket-test-credentials.json $BUCKET_NAME/bucket-test-credentials.json |
| 39 | + |
| 40 | + # Verify file was uploaded |
| 41 | + mc ls $BUCKET_NAME/bucket-test-credentials.json |
| 42 | + |
| 43 | + # Clean up uploaded file |
| 44 | + mc rm $BUCKET_NAME/bucket-test-credentials.json |
| 45 | + |
| 46 | + kubectl -n tenant-test delete bucket.apps.cozystack.io ${name} |
| 47 | +} |
0 commit comments