fix bug
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
package collector
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"git.apinb.com/quant/collector/types"
|
||||
)
|
||||
|
||||
// TestCalculateHash 测试Hash计算功能
|
||||
func TestCalculateHash(t *testing.T) {
|
||||
// 读取样本数据
|
||||
data, err := os.ReadFile("../exmple/status.json")
|
||||
if err != nil {
|
||||
t.Fatalf("读取样本文件失败: %v", err)
|
||||
}
|
||||
|
||||
var status types.Status
|
||||
if err := json.Unmarshal(data, &status); err != nil {
|
||||
t.Fatalf("JSON解析失败: %v", err)
|
||||
}
|
||||
|
||||
collector := NewCollector("http://localhost:5000/status")
|
||||
hash, err := collector.CalculateHash(&status)
|
||||
if err != nil {
|
||||
t.Fatalf("计算Hash失败: %v", err)
|
||||
}
|
||||
|
||||
if hash == "" {
|
||||
t.Error("Hash值不能为空")
|
||||
}
|
||||
|
||||
t.Logf("计算的Hash: %s", hash)
|
||||
}
|
||||
|
||||
// TestHasChanged 测试变化检测
|
||||
func TestHasChanged(t *testing.T) {
|
||||
collector := NewCollector("http://localhost:5000/status")
|
||||
|
||||
// 第一次应该返回true
|
||||
if !collector.HasChanged("hash1") {
|
||||
t.Error("第一次检测应该返回true")
|
||||
}
|
||||
|
||||
// 更新hash
|
||||
collector.UpdateHash("hash1")
|
||||
|
||||
// 相同的hash应该返回false
|
||||
if collector.HasChanged("hash1") {
|
||||
t.Error("相同的hash应该返回false")
|
||||
}
|
||||
|
||||
// 不同的hash应该返回true
|
||||
if !collector.HasChanged("hash2") {
|
||||
t.Error("不同的hash应该返回true")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user