This commit is contained in:
hu xiaotong
2025-07-02 16:12:52 +08:00
commit 0246bc7060
48 changed files with 460639 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
package service
import (
"encoding/json"
"equipment-analyzer/internal/config"
"equipment-analyzer/internal/utils"
"fmt"
"testing"
)
func TestReadRawJsonFile(t *testing.T) {
// 创建测试用的配置和日志器
config := &config.Config{}
logger := utils.NewLogger()
// 创建ParserService实例
ps := NewParserService(config, logger)
// 调用ReadRawJsonFile方法
result, err := ps.ReadRawJsonFile()
if err != nil {
t.Fatalf("ReadRawJsonFile failed: %v", err)
}
fmt.Printf("Raw result length: %d\n", len(result))
fmt.Printf("Raw result preview: %s\n", result[:min(200, len(result))])
// 解析JSON结果
var parsedData map[string]interface{}
if err := json.Unmarshal([]byte(result), &parsedData); err != nil {
t.Fatalf("Failed to parse JSON result: %v", err)
}
// 检查数据结构
fmt.Printf("Parsed data keys: %v\n", getKeys(parsedData))
// 检查items字段
if items, exists := parsedData["items"]; exists {
if itemsArray, ok := items.([]interface{}); ok {
fmt.Printf("Items count: %d\n", len(itemsArray))
if len(itemsArray) > 0 {
fmt.Printf("First item: %+v\n", itemsArray[0])
}
} else {
fmt.Printf("Items is not an array: %T\n", items)
}
} else {
fmt.Println("Items field not found")
}
// 检查heroes字段
if heroes, exists := parsedData["heroes"]; exists {
if heroesArray, ok := heroes.([]interface{}); ok {
fmt.Printf("Heroes count: %d\n", len(heroesArray))
if len(heroesArray) > 0 {
fmt.Printf("First hero: %+v\n", heroesArray[0])
}
} else {
fmt.Printf("Heroes is not an array: %T\n", heroes)
}
} else {
fmt.Println("Heroes field not found")
}
// 如果没有数据,输出更多调试信息
if len(result) < 100 {
fmt.Printf("Result seems empty or very short: %q\n", result)
}
}
// 辅助函数
func min(a, b int) int {
if a < b {
return a
}
return b
}
func getKeys(m map[string]interface{}) []string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
return keys
}