fix: 修复测试文件格式问题
- 修正测试文件中的换行符和格式 - 确保所有测试文件的一致性
This commit is contained in:
@@ -97,17 +97,17 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
op, err := model.NewFullOperation(
|
||||
model.Source(testOp.opSource),
|
||||
testOp.opType,
|
||||
testOp.prefix, // doPrefix
|
||||
testOp.repo, // doRepository
|
||||
testOp.doid, // doid
|
||||
testOp.producer, // producerID
|
||||
testOp.actor, // opActor
|
||||
nil, // requestBody
|
||||
nil, // responseBody
|
||||
testOp.time, // timestamp
|
||||
testOp.prefix, // doPrefix
|
||||
testOp.repo, // doRepository
|
||||
testOp.doid, // doid
|
||||
testOp.producer, // producerID
|
||||
testOp.actor, // opActor
|
||||
nil, // requestBody
|
||||
nil, // responseBody
|
||||
testOp.time, // timestamp
|
||||
)
|
||||
require.NoError(t, err, "Failed to create operation %s", testOp.opID)
|
||||
|
||||
|
||||
op.OpID = testOp.opID
|
||||
op.ClientIP = testOp.clientIP
|
||||
op.ServerIP = testOp.serverIP
|
||||
@@ -144,7 +144,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
result, err := repo.Query(ctx, req)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, result.Total, int64(7)) // 7条DOIP记录
|
||||
|
||||
|
||||
for _, op := range result.Operations {
|
||||
assert.Equal(t, "DOIP", string(op.OpSource))
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
result, err := repo.Query(ctx, req)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, result.Total, int64(2)) // 2条Create记录
|
||||
|
||||
|
||||
for _, op := range result.Operations {
|
||||
assert.Equal(t, "Create", op.OpType)
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
result, err := repo.Query(ctx, req)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, result.Total, int64(5)) // 5条已存证记录
|
||||
|
||||
|
||||
for _, s := range result.Statuses {
|
||||
assert.Equal(t, persistence.StatusTrustlogged, s)
|
||||
}
|
||||
@@ -201,7 +201,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
result, err := repo.Query(ctx, req)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, result.Total, int64(3)) // 3条test-001的记录
|
||||
|
||||
|
||||
for _, op := range result.Operations {
|
||||
assert.Contains(t, op.Doid, "test-001")
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
result, err := repo.Query(ctx, req)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, result.Total, int64(3)) // 3条user-1的记录
|
||||
|
||||
|
||||
for _, op := range result.Operations {
|
||||
assert.Equal(t, "user-1", op.OpActor)
|
||||
}
|
||||
@@ -239,7 +239,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
result, err := repo.Query(ctx, req)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, result.Total, int64(3)) // 3条producer-1的记录
|
||||
|
||||
|
||||
for _, op := range result.Operations {
|
||||
assert.Equal(t, "producer-1", op.ProducerID)
|
||||
}
|
||||
@@ -258,7 +258,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
result, err := repo.Query(ctx, req)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, result.Total, int64(2)) // 2条192.168.1.10的记录
|
||||
|
||||
|
||||
for _, op := range result.Operations {
|
||||
assert.NotNil(t, op.ClientIP)
|
||||
assert.Equal(t, "192.168.1.10", *op.ClientIP)
|
||||
@@ -278,7 +278,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
result, err := repo.Query(ctx, req)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, result.Total, int64(3)) // 3条10.0.0.1的记录
|
||||
|
||||
|
||||
for _, op := range result.Operations {
|
||||
assert.NotNil(t, op.ServerIP)
|
||||
assert.Equal(t, "10.0.0.1", *op.ServerIP)
|
||||
@@ -301,12 +301,12 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, result.Total, int64(3)) // 应该至少有3条记录在这个时间范围
|
||||
t.Logf("✅ Time range records: %d", result.Total)
|
||||
|
||||
|
||||
// 验证返回的记录在时间范围内
|
||||
for i, op := range result.Operations {
|
||||
if !((op.Timestamp.After(timeFrom) || op.Timestamp.Equal(timeFrom)) &&
|
||||
(op.Timestamp.Before(timeTo) || op.Timestamp.Equal(timeTo))) {
|
||||
t.Logf("⚠️ Record %d out of range: timestamp=%v, from=%v, to=%v",
|
||||
t.Logf("⚠️ Record %d out of range: timestamp=%v, from=%v, to=%v",
|
||||
i, op.Timestamp, timeFrom, timeTo)
|
||||
}
|
||||
}
|
||||
@@ -326,7 +326,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
result, err := repo.Query(ctx, req)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, result.Total, int64(3)) // 3条已存证的DOIP记录
|
||||
|
||||
|
||||
for i, op := range result.Operations {
|
||||
assert.Equal(t, "DOIP", string(op.OpSource))
|
||||
assert.Equal(t, persistence.StatusTrustlogged, result.Statuses[i])
|
||||
@@ -354,12 +354,12 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
result, err = repo.Query(ctx, req)
|
||||
require.NoError(t, err)
|
||||
assert.LessOrEqual(t, len(result.Operations), 5)
|
||||
|
||||
|
||||
// 确保第1页和第2页的数据不重复
|
||||
if len(result.Operations) > 0 {
|
||||
assert.NotEqual(t, firstPageFirst, result.Operations[0].OpID)
|
||||
}
|
||||
|
||||
|
||||
t.Logf("✅ Pagination works correctly, total pages: %d", result.TotalPages)
|
||||
})
|
||||
|
||||
@@ -376,7 +376,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
resultAsc, err := repo.Query(ctx, reqAsc)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, len(resultAsc.Operations), 10)
|
||||
|
||||
|
||||
// 验证升序
|
||||
for i := 1; i < len(resultAsc.Operations); i++ {
|
||||
assert.True(t, resultAsc.Operations[i].Timestamp.After(resultAsc.Operations[i-1].Timestamp) ||
|
||||
@@ -394,7 +394,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
resultDesc, err := repo.Query(ctx, reqDesc)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, len(resultDesc.Operations), 10)
|
||||
|
||||
|
||||
// 验证降序
|
||||
for i := 1; i < len(resultDesc.Operations); i++ {
|
||||
assert.True(t, resultDesc.Operations[i].Timestamp.Before(resultDesc.Operations[i-1].Timestamp) ||
|
||||
@@ -457,7 +457,7 @@ func TestPG_Query_Integration(t *testing.T) {
|
||||
result, err := repo.Query(ctx, req)
|
||||
require.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, result.Total, int64(1))
|
||||
|
||||
|
||||
for i, op := range result.Operations {
|
||||
assert.Equal(t, "DOIP", string(op.OpSource))
|
||||
assert.Equal(t, "Update", op.OpType)
|
||||
@@ -530,19 +530,19 @@ func TestPG_PersistenceClient_Query_Integration(t *testing.T) {
|
||||
// 创建测试数据(通过manager的repository)
|
||||
manager := client.GetManager()
|
||||
repo := manager.GetOperationRepo()
|
||||
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
op, err := model.NewFullOperation(
|
||||
model.OpSourceDOIP,
|
||||
string(model.OpTypeCreate),
|
||||
"10.10000", // doPrefix
|
||||
"client-repo", // doRepository
|
||||
"10.10000", // doPrefix
|
||||
"client-repo", // doRepository
|
||||
fmt.Sprintf("10.10000/client-repo/test-%d", i), // doid
|
||||
fmt.Sprintf("client-producer-%d", i), // producerID
|
||||
fmt.Sprintf("client-actor-%d", i), // opActor
|
||||
nil, // requestBody
|
||||
nil, // responseBody
|
||||
time.Now(), // timestamp
|
||||
fmt.Sprintf("client-producer-%d", i), // producerID
|
||||
fmt.Sprintf("client-actor-%d", i), // opActor
|
||||
nil, // requestBody
|
||||
nil, // responseBody
|
||||
time.Now(), // timestamp
|
||||
)
|
||||
require.NoError(t, err)
|
||||
op.OpID = fmt.Sprintf("pg-client-query-%03d", i)
|
||||
@@ -613,4 +613,3 @@ func TestPG_PersistenceClient_Query_Integration(t *testing.T) {
|
||||
func strPtr(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user