diff --git a/test/s3/acl/Makefile b/test/s3/acl/Makefile index 7d9796e62..dfa994fc8 100644 --- a/test/s3/acl/Makefile +++ b/test/s3/acl/Makefile @@ -6,12 +6,12 @@ # Build SeaweedFS binary if not exists build: @echo "Building SeaweedFS binary..." - @cd ../../../ && make build - @test -f ../../../weed || (echo "SeaweedFS binary not found" && exit 1) + @cd ../../../ && make install + @which weed > /dev/null 2>&1 || (echo "SeaweedFS binary not found in PATH" && exit 1) # Check dependencies check-deps: build - @test -f ../../../weed || (echo "SeaweedFS binary not found" && exit 1) + @which weed > /dev/null 2>&1 || (echo "SeaweedFS binary not found in PATH" && exit 1) @echo "✅ Dependencies available" # Run all tests (auto-manages weed mini server via TestMain) diff --git a/test/s3/acl/s3_test_main.go b/test/s3/acl/s3_test_main.go index f9999e129..b1e3a83bf 100644 --- a/test/s3/acl/s3_test_main.go +++ b/test/s3/acl/s3_test_main.go @@ -5,10 +5,10 @@ import ( "os" "testing" - "../testutil" + "github.com/seaweedfs/seaweedfs/test/s3/testutil" ) -var testServer *testutil.Server +var testServer *testutil.TestServer // TestMain sets up and tears down the test environment using weed mini func TestMain(m *testing.M) { diff --git a/test/s3/basic/Makefile b/test/s3/basic/Makefile index 849fb65e1..0e37d757a 100644 --- a/test/s3/basic/Makefile +++ b/test/s3/basic/Makefile @@ -6,12 +6,12 @@ # Build SeaweedFS binary if not exists build: @echo "Building SeaweedFS binary..." - @cd ../../../ && make build - @test -f ../../../weed || (echo "SeaweedFS binary not found" && exit 1) + @cd ../../../ && make install + @which weed > /dev/null 2>&1 || (echo "SeaweedFS binary not found in PATH" && exit 1) # Check dependencies check-deps: build - @test -f ../../../weed || (echo "SeaweedFS binary not found" && exit 1) + @which weed > /dev/null 2>&1 || (echo "SeaweedFS binary not found in PATH" && exit 1) @echo "✅ Dependencies available" # Run all tests (auto-manages weed mini server via TestMain) diff --git a/test/s3/basic/basic_test.go b/test/s3/basic/basic_test.go index b2a6ae14b..0ab0ad6dc 100644 --- a/test/s3/basic/basic_test.go +++ b/test/s3/basic/basic_test.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" + "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" ) @@ -18,25 +19,46 @@ var ( ) func init() { - // Initialize a session in us-west-2 that the SDK will use to load - // credentials from the shared credentials file ~/.aws/credentials. - sess, err := session.NewSession(&aws.Config{ - Region: aws.String("us-west-2"), - Endpoint: aws.String("localhost:8333"), - DisableSSL: aws.Bool(true), - }) - if err != nil { - exitErrorf("create session, %v", err) - } + // Session will be created lazily in tests after environment variables are set +} + +func getS3Client() *s3.S3 { + if svc == nil { + // Get credentials from environment or use defaults + accessKey := os.Getenv("AWS_ACCESS_KEY_ID") + secretKey := os.Getenv("AWS_SECRET_ACCESS_KEY") + if accessKey == "" { + accessKey = "some_access_key1" + } + if secretKey == "" { + secretKey = "some_secret_key1" + } + + // Create session with explicit credentials + sess, err := session.NewSession(&aws.Config{ + Region: aws.String("us-east-1"), + Endpoint: aws.String("localhost:8333"), + DisableSSL: aws.Bool(true), + Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""), + }) + if err != nil { + panic(fmt.Sprintf("create session: %v", err)) + } - // Create S3 service client - svc = s3.New(sess) + // Create S3 service client + svc = s3.New(sess) + } + return svc } func TestCreateBucket(t *testing.T) { + fmt.Printf("TestCreateBucket: AWS_ACCESS_KEY_ID=%s, AWS_SECRET_ACCESS_KEY=%s\n", + os.Getenv("AWS_ACCESS_KEY_ID"), strings.Repeat("*", len(os.Getenv("AWS_SECRET_ACCESS_KEY")))) + + svc := getS3Client() input := &s3.CreateBucketInput{ - Bucket: aws.String("theBucket"), + Bucket: aws.String(Bucket), } result, err := svc.CreateBucket(input) @@ -63,11 +85,12 @@ func TestCreateBucket(t *testing.T) { } func TestPutObject(t *testing.T) { + svc := getS3Client() input := &s3.PutObjectInput{ ACL: aws.String("authenticated-read"), Body: aws.ReadSeekCloser(strings.NewReader("filetoupload")), - Bucket: aws.String("theBucket"), + Bucket: aws.String(Bucket), Key: aws.String("exampleobject"), } @@ -91,6 +114,7 @@ func TestPutObject(t *testing.T) { } func TestListBucket(t *testing.T) { + svc := getS3Client() result, err := svc.ListBuckets(nil) if err != nil { @@ -107,6 +131,7 @@ func TestListBucket(t *testing.T) { } func TestListObjectV2(t *testing.T) { + svc := getS3Client() listObj, err := svc.ListObjectsV2(&s3.ListObjectsV2Input{ Bucket: aws.String(Bucket), @@ -129,17 +154,30 @@ func exitErrorf(msg string, args ...interface{}) { } const ( - Bucket = "theBucket" + Bucket = "test-bucket" object = "foo/bar" Data = "" ) func TestObjectOp(t *testing.T) { + svc := getS3Client() _, err := svc.CreateBucket(&s3.CreateBucketInput{ Bucket: aws.String(Bucket), }) if err != nil { - exitErrorf("Unable to create bucket, %v", err) + if aerr, ok := err.(awserr.Error); ok { + switch aerr.Code() { + case s3.ErrCodeBucketAlreadyExists: + fmt.Println(s3.ErrCodeBucketAlreadyExists, aerr.Error()) + case s3.ErrCodeBucketAlreadyOwnedByYou: + fmt.Println(s3.ErrCodeBucketAlreadyOwnedByYou, aerr.Error()) + default: + fmt.Println(aerr.Error()) + } + } else { + // Handle non-AWS errors (like MethodNotAllowed) + fmt.Printf("Bucket creation failed (possibly already exists): %v\n", err) + } } _, err = svc.PutObject(&s3.PutObjectInput{ diff --git a/test/s3/basic/s3_test_main.go b/test/s3/basic/s3_test_main_test.go similarity index 66% rename from test/s3/basic/s3_test_main.go rename to test/s3/basic/s3_test_main_test.go index ef5e3f2e6..2bcdced37 100644 --- a/test/s3/basic/s3_test_main.go +++ b/test/s3/basic/s3_test_main_test.go @@ -3,12 +3,13 @@ package basic import ( "fmt" "os" + "strings" "testing" - "../testutil" + "github.com/seaweedfs/seaweedfs/test/s3/testutil" ) -var testServer *testutil.Server +var testServer *testutil.TestServer // TestMain sets up and tears down the test environment using weed mini func TestMain(m *testing.M) { @@ -24,6 +25,14 @@ func TestMain(m *testing.M) { config.AccessKey = "some_access_key1" config.SecretKey = "some_secret_key1" + fmt.Println("TestMain: Setting environment variables...") + // Set AWS credentials for tests + os.Setenv("AWS_ACCESS_KEY_ID", config.AccessKey) + os.Setenv("AWS_SECRET_ACCESS_KEY", config.SecretKey) + os.Setenv("AWS_REGION", "us-east-1") + fmt.Printf("TestMain: Set AWS_ACCESS_KEY_ID=%s, AWS_SECRET_ACCESS_KEY=%s, AWS_REGION=us-east-1\n", + config.AccessKey, strings.Repeat("*", len(config.SecretKey))) + var err error testServer, err = testutil.StartServer(config) if err != nil { diff --git a/test/s3/basic/weed-test.pid b/test/s3/basic/weed-test.pid new file mode 100644 index 000000000..fd305fe9e --- /dev/null +++ b/test/s3/basic/weed-test.pid @@ -0,0 +1 @@ +79189 \ No newline at end of file diff --git a/test/s3/copying/s3_test_main.go b/test/s3/copying/s3_test_main.go index b6cf17503..670a09f73 100644 --- a/test/s3/copying/s3_test_main.go +++ b/test/s3/copying/s3_test_main.go @@ -5,12 +5,7 @@ import ( "os" "testing" -"../testutil" -) - -var testServer *testutil.Server - -// TestMain sets up and tears down the test environment using weed mini + "github.com/seaweedfs/seaweedfs/test/s3/testutil" func TestMain(m *testing.M) { var exitCode int diff --git a/test/s3/cors/s3_test_main.go b/test/s3/cors/s3_test_main.go index 2dfeb2265..9c2118593 100644 --- a/test/s3/cors/s3_test_main.go +++ b/test/s3/cors/s3_test_main.go @@ -5,12 +5,7 @@ import ( "os" "testing" -"../testutil" -) - -var testServer *testutil.Server - -// TestMain sets up and tears down the test environment using weed mini + "github.com/seaweedfs/seaweedfs/test/s3/testutil" func TestMain(m *testing.M) { var exitCode int diff --git a/test/s3/delete/Makefile b/test/s3/delete/Makefile index 3b015d1b7..2eee21143 100644 --- a/test/s3/delete/Makefile +++ b/test/s3/delete/Makefile @@ -6,12 +6,12 @@ # Build SeaweedFS binary if not exists build: @echo "Building SeaweedFS binary..." - @cd ../../../ && make build - @test -f ../../../weed || (echo "SeaweedFS binary not found" && exit 1) + @cd ../../../ && make install + @which weed > /dev/null 2>&1 || (echo "SeaweedFS binary not found in PATH" && exit 1) # Check dependencies check-deps: build - @test -f ../../../weed || (echo "SeaweedFS binary not found" && exit 1) + @which weed > /dev/null 2>&1 || (echo "SeaweedFS binary not found in PATH" && exit 1) @echo "✅ Dependencies available" # Run all tests (auto-manages weed mini server via TestMain) diff --git a/test/s3/delete/s3_test_main.go b/test/s3/delete/s3_test_main.go index e1482e23f..7ac26d022 100644 --- a/test/s3/delete/s3_test_main.go +++ b/test/s3/delete/s3_test_main.go @@ -5,12 +5,7 @@ import ( "os" "testing" -"../testutil" -) - -var testServer *testutil.Server - -// TestMain sets up and tears down the test environment using weed mini + "github.com/seaweedfs/seaweedfs/test/s3/testutil" func TestMain(m *testing.M) { var exitCode int diff --git a/test/s3/etag/s3_test_main.go b/test/s3/etag/s3_test_main.go index 81992eba8..9b1d47d2f 100644 --- a/test/s3/etag/s3_test_main.go +++ b/test/s3/etag/s3_test_main.go @@ -5,12 +5,7 @@ import ( "os" "testing" -"../testutil" -) - -var testServer *testutil.Server - -// TestMain sets up and tears down the test environment using weed mini + "github.com/seaweedfs/seaweedfs/test/s3/testutil" func TestMain(m *testing.M) { var exitCode int diff --git a/test/s3/filer_group/s3_test_main.go b/test/s3/filer_group/s3_test_main.go index 2af59360e..0520f9c3d 100644 --- a/test/s3/filer_group/s3_test_main.go +++ b/test/s3/filer_group/s3_test_main.go @@ -5,12 +5,7 @@ import ( "os" "testing" -"../testutil" -) - -var testServer *testutil.Server - -// TestMain sets up and tears down the test environment using weed mini + "github.com/seaweedfs/seaweedfs/test/s3/testutil" func TestMain(m *testing.M) { var exitCode int diff --git a/test/s3/iam/s3_test_main.go b/test/s3/iam/s3_test_main.go index 1064349e1..29d038b88 100644 --- a/test/s3/iam/s3_test_main.go +++ b/test/s3/iam/s3_test_main.go @@ -5,10 +5,10 @@ import ( "os" "testing" - "../testutil" + "github.com/seaweedfs/seaweedfs/test/s3/testutil" ) -var testServer *testutil.Server +var testServer *testutil.TestServer // TestMain sets up and tears down the test environment using weed mini func TestMain(m *testing.M) { diff --git a/test/s3/remote_cache/s3_test_main.go b/test/s3/remote_cache/s3_test_main.go index 23d5fb20c..c66c898fa 100644 --- a/test/s3/remote_cache/s3_test_main.go +++ b/test/s3/remote_cache/s3_test_main.go @@ -5,12 +5,7 @@ import ( "os" "testing" -"../testutil" -) - -var testServer *testutil.Server - -// TestMain sets up and tears down the test environment using weed mini + "github.com/seaweedfs/seaweedfs/test/s3/testutil" func TestMain(m *testing.M) { var exitCode int diff --git a/test/s3/retention/s3_test_main.go b/test/s3/retention/s3_test_main.go index 77b77cbb6..aa1a1270b 100644 --- a/test/s3/retention/s3_test_main.go +++ b/test/s3/retention/s3_test_main.go @@ -5,12 +5,7 @@ import ( "os" "testing" -"../testutil" -) - -var testServer *testutil.Server - -// TestMain sets up and tears down the test environment using weed mini + "github.com/seaweedfs/seaweedfs/test/s3/testutil" func TestMain(m *testing.M) { var exitCode int diff --git a/test/s3/sse/s3_test_main.go b/test/s3/sse/s3_test_main.go index f335da4e8..d56f46cff 100644 --- a/test/s3/sse/s3_test_main.go +++ b/test/s3/sse/s3_test_main.go @@ -5,12 +5,7 @@ import ( "os" "testing" -"../testutil" -) - -var testServer *testutil.Server - -// TestMain sets up and tears down the test environment using weed mini + "github.com/seaweedfs/seaweedfs/test/s3/testutil" func TestMain(m *testing.M) { var exitCode int diff --git a/test/s3/tagging/s3_test_main.go b/test/s3/tagging/s3_test_main.go index 5ff49d303..770b0c37a 100644 --- a/test/s3/tagging/s3_test_main.go +++ b/test/s3/tagging/s3_test_main.go @@ -1,14 +1,14 @@ package tagging import ( -"fmt" -"os" -"testing" + "fmt" + "os" + "testing" -"../testutil" + "github.com/seaweedfs/seaweedfs/test/s3/testutil" ) -var testServer *testutil.Server +var testServer *testutil.TestServer // TestMain sets up and tears down the test environment using weed mini func TestMain(m *testing.M) { diff --git a/test/s3/testutil/server.go b/test/s3/testutil/server.go index d9fceca55..269cc9ce4 100644 --- a/test/s3/testutil/server.go +++ b/test/s3/testutil/server.go @@ -158,7 +158,7 @@ func (s *TestServer) Stop() error { // findWeedBinary searches for the weed binary in common locations func findWeedBinary() (string, error) { - // Try ../../../weed (from test/s3/testutil directory) + // Try various locations for weed binary paths := []string{ "../../../weed", "../../../../weed", @@ -168,9 +168,27 @@ func findWeedBinary() (string, error) { "/usr/bin/weed", } + // Add GOPATH/bin/weed + if gopath := os.Getenv("GOPATH"); gopath != "" { + paths = append(paths, filepath.Join(gopath, "bin", "weed")) + } + + // Add GOROOT/bin/weed + if goroot := os.Getenv("GOROOT"); goroot != "" { + paths = append(paths, filepath.Join(goroot, "bin", "weed")) + } + + // Add ~/go/bin/weed (common default GOPATH) + if home := os.Getenv("HOME"); home != "" { + paths = append(paths, filepath.Join(home, "go", "bin", "weed")) + } + for _, p := range paths { - if _, err := os.Stat(p); err == nil { - return p, nil + if info, err := os.Stat(p); err == nil { + // Check if it's a regular file and executable + if info.Mode().IsRegular() && (info.Mode().Perm()&0111) != 0 { + return p, nil + } } } diff --git a/test/s3/versioning/Makefile b/test/s3/versioning/Makefile index 993a9fa0b..2a424d55d 100644 --- a/test/s3/versioning/Makefile +++ b/test/s3/versioning/Makefile @@ -6,12 +6,12 @@ # Build SeaweedFS binary if not exists build: @echo "Building SeaweedFS binary..." - @cd ../../../ && make build - @test -f ../../../weed || (echo "SeaweedFS binary not found" && exit 1) + @cd ../../../ && make install + @which weed > /dev/null 2>&1 || (echo "SeaweedFS binary not found in PATH" && exit 1) # Check dependencies check-deps: build - @test -f ../../../weed || (echo "SeaweedFS binary not found" && exit 1) + @which weed > /dev/null 2>&1 || (echo "SeaweedFS binary not found in PATH" && exit 1) @echo "✅ Dependencies available" # Run all tests (auto-manages weed mini server) diff --git a/test/s3/versioning/s3_test_main.go b/test/s3/versioning/s3_test_main.go index 696b2bd52..d94bab4e5 100644 --- a/test/s3/versioning/s3_test_main.go +++ b/test/s3/versioning/s3_test_main.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "../testutil" + "github.com/seaweedfs/seaweedfs/test/s3/testutil" ) var testServer *testutil.TestServer