Browse Source

Merge remote-tracking branch 'origin/master'

LingxinMeng 4 months ago
parent
commit
474c36c854
2 changed files with 87 additions and 87 deletions
  1. 5 5
      test/oss_test.go
  2. 82 82
      test/regenerate_test.go

+ 5 - 5
test/oss_test.go

@@ -27,11 +27,11 @@ func TestCompareSize(t *testing.T) {
 
 func TestDeleteDir(t *testing.T) {
 	// 配置 OSS 客户端
-	endpoint := "http://pji-bucket1.oss.icvdc.com"      // 替换为实际的 OSS Endpoint
-	accessKeyID := "n8glvFGS25MrLY7j"                   // 替换为实际的 AccessKeyID
-	accessKeySecret := "xZ2Fozoarpfw0z28FUhtg8cu0yDc5d" // 替换为实际的 AccessKeySecret
-	bucketName := "xinqi"                               // 替换为实际的 Bucket 名称
-	prefix := "your-prefix/"                            // 替换为实际的前缀
+	endpoint := "http://oss-cn-beijing-gqzl-d01-a.ops.gqzl-cloud.com/" // 替换为实际的 OSS Endpoint
+	accessKeyID := "nT7CCrjL6pcYGej6"                                  // 替换为实际的 AccessKeyID
+	accessKeySecret := "OPHAxk2c2YbG530ADx6KZi2PbcWHr7"                // 替换为实际的 AccessKeySecret
+	bucketName := "xinqi"                                              // 替换为实际的 Bucket 名称
+	prefix := "1"                                                      // 替换为实际的前缀
 
 	// 创建 OSS 客户端
 	client, err := oss.New(endpoint, accessKeyID, accessKeySecret)

+ 82 - 82
test/regenerate_test.go

@@ -7,88 +7,88 @@ import (
 	"testing"
 )
 
-// 删除除了 callback 文件之外的所有文件
-func TestDeleteExceptCallback(t *testing.T) {
-	// Define OSS configuration
-	endpoint := "http://pji-bucket1.oss.icvdc.com"
-	accessKeyID := "n8glvFGS25MrLY7j"
-	accessKeySecret := "xZ2Fozoarpfw0z28FUhtg8cu0yDc5d"
-	bucketName := "pji-bucket1"
-
-	// Create an OSS client
-	client, err := oss.New(endpoint, accessKeyID, accessKeySecret, oss.UseCname(true))
-	if err != nil {
-		fmt.Printf("Failed to create OSS client: %v\n", err)
-		return
-	}
-
-	// Get the bucket
-	bucket, err := client.Bucket(bucketName)
-	if err != nil {
-		fmt.Printf("Failed to get bucket: %v\n", err)
-		return
-	}
-
-	// Define an array of directories (prefixes) to scan
-	//directories := []string{
-	//	"pjibot_delivery/pjibot-P1YVPS1M22CM00020/data_parse/",
-	//	"pjibot_delivery/pjibot-P1YYPS1M227M00107/data_parse/",
-	//}
-	directories := []string{
-		"pjibot_patrol/pjibot-P1YVXJ1M231M00022/data_parse",
-		"pjibot_patrol/pjibot-P1YVXJ1M231M00023/data_parse",
-	}
-
-	for _, dir := range directories {
-		// List objects in the directory
-		marker := ""
-		for {
-			lsRes, err := bucket.ListObjects(oss.Prefix(dir), oss.Marker(marker))
-			if err != nil {
-				fmt.Printf("Failed to list objects in directory %s: %v\n", dir, err)
-				break
-			}
-
-			for _, object := range lsRes.Objects {
-				objectKey := object.Key
-
-				// Process files not containing "callback"
-				if !strings.Contains(objectKey, "callback") {
-					err := bucket.DeleteObject(objectKey)
-					if err != nil {
-						fmt.Printf("Failed to delete object %s: %v\n", objectKey, err)
-					} else {
-						fmt.Printf("Deleted object: %s\n", objectKey)
-					}
-					continue
-				}
-
-				// Rename files containing "callback_done" to "callback"
-				if strings.Contains(objectKey, "callback_done") {
-					newKey := strings.Replace(objectKey, "callback_done", "callback", 1)
-					err, _ = bucket.CopyObject(objectKey, newKey)
-					if err != nil {
-						fmt.Printf("Failed to copy object %s to %s: %v\n", objectKey, newKey, err)
-						err = bucket.DeleteObject(objectKey)
-					} else {
-						err = bucket.DeleteObject(objectKey)
-						if err != nil {
-							fmt.Printf("Failed to delete original object %s after renaming: %v\n", objectKey, err)
-						} else {
-							fmt.Printf("Renamed object: %s to %s\n", objectKey, newKey)
-						}
-					}
-				}
-			}
-
-			// Exit the loop if all objects are processed
-			if !lsRes.IsTruncated {
-				break
-			}
-			marker = lsRes.NextMarker
-		}
-	}
-}
+//// 删除除了 callback 文件之外的所有文件
+//func TestDeleteExceptCallback(t *testing.T) {
+//	// Define OSS configuration
+//	endpoint := "http://pji-bucket1.oss.icvdc.com"
+//	accessKeyID := "n8glvFGS25MrLY7j"
+//	accessKeySecret := "xZ2Fozoarpfw0z28FUhtg8cu0yDc5d"
+//	bucketName := "pji-bucket1"
+//
+//	// Create an OSS client
+//	client, err := oss.New(endpoint, accessKeyID, accessKeySecret, oss.UseCname(true))
+//	if err != nil {
+//		fmt.Printf("Failed to create OSS client: %v\n", err)
+//		return
+//	}
+//
+//	// Get the bucket
+//	bucket, err := client.Bucket(bucketName)
+//	if err != nil {
+//		fmt.Printf("Failed to get bucket: %v\n", err)
+//		return
+//	}
+//
+//	// Define an array of directories (prefixes) to scan
+//	//directories := []string{
+//	//	"pjibot_delivery/pjibot-P1YVPS1M22CM00020/data_parse/",
+//	//	"pjibot_delivery/pjibot-P1YYPS1M227M00107/data_parse/",
+//	//}
+//	directories := []string{
+//		"pjibot_patrol/pjibot-P1YVXJ1M231M00022/data_parse",
+//		"pjibot_patrol/pjibot-P1YVXJ1M231M00023/data_parse",
+//	}
+//
+//	for _, dir := range directories {
+//		// List objects in the directory
+//		marker := ""
+//		for {
+//			lsRes, err := bucket.ListObjects(oss.Prefix(dir), oss.Marker(marker))
+//			if err != nil {
+//				fmt.Printf("Failed to list objects in directory %s: %v\n", dir, err)
+//				break
+//			}
+//
+//			for _, object := range lsRes.Objects {
+//				objectKey := object.Key
+//
+//				// Process files not containing "callback"
+//				if !strings.Contains(objectKey, "callback") {
+//					err := bucket.DeleteObject(objectKey)
+//					if err != nil {
+//						fmt.Printf("Failed to delete object %s: %v\n", objectKey, err)
+//					} else {
+//						fmt.Printf("Deleted object: %s\n", objectKey)
+//					}
+//					continue
+//				}
+//
+//				// Rename files containing "callback_done" to "callback"
+//				if strings.Contains(objectKey, "callback_done") {
+//					newKey := strings.Replace(objectKey, "callback_done", "callback", 1)
+//					err, _ = bucket.CopyObject(objectKey, newKey)
+//					if err != nil {
+//						fmt.Printf("Failed to copy object %s to %s: %v\n", objectKey, newKey, err)
+//						err = bucket.DeleteObject(objectKey)
+//					} else {
+//						err = bucket.DeleteObject(objectKey)
+//						if err != nil {
+//							fmt.Printf("Failed to delete original object %s after renaming: %v\n", objectKey, err)
+//						} else {
+//							fmt.Printf("Renamed object: %s to %s\n", objectKey, newKey)
+//						}
+//					}
+//				}
+//			}
+//
+//			// Exit the loop if all objects are processed
+//			if !lsRes.IsTruncated {
+//				break
+//			}
+//			marker = lsRes.NextMarker
+//		}
+//	}
+//}
 
 // 删除指定csv文件,为了重新升成 report.pdf
 func TestDeleteAllTrajectoryPjiCsv(t *testing.T) {