refactor: 将 OpType 字段从枚举类型改为 string 类型
主要变更: - Operation.OpType: Type → string - NewFullOperation 参数: opType Type → opType string - IsValidOpType 参数: opType Type → opType string - operationMeta.OpType: *Type → *string - queryclient.ListRequest.OpType: model.Type → string 优点: - 更灵活,支持动态扩展操作类型 - 不再受限于预定义的枚举常量 - 简化类型转换逻辑 兼容性: - Type 常量定义保持不变 (OpTypeCreate, OpTypeUpdate 等) - 使用时需要 string() 转换: string(model.OpTypeCreate) - 所有单元测试已更新并通过 (100%) 测试结果: ✅ api/adapter - PASS ✅ api/highclient - PASS ✅ api/logger - PASS ✅ api/model - PASS ✅ api/persistence - PASS ✅ api/queryclient - PASS ✅ internal/* - PASS
This commit is contained in:
@@ -507,7 +507,7 @@ func createTestOperationWithID(t testing.TB, id string) *model.Operation {
|
|||||||
}
|
}
|
||||||
operation, err := model.NewFullOperation(
|
operation, err := model.NewFullOperation(
|
||||||
model.OpSourceDOIP,
|
model.OpSourceDOIP,
|
||||||
model.OpTypeRetrieve,
|
string(model.OpTypeRetrieve),
|
||||||
"test-prefix",
|
"test-prefix",
|
||||||
"test-repo",
|
"test-repo",
|
||||||
"test-prefix/test-repo/test-object",
|
"test-prefix/test-repo/test-object",
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func FromProtobuf(pbOp *pb.OperationData) (*Operation, error) {
|
|||||||
OpID: pbOp.GetOpId(),
|
OpID: pbOp.GetOpId(),
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
OpSource: Source(pbOp.GetOpSource()),
|
OpSource: Source(pbOp.GetOpSource()),
|
||||||
OpType: Type(pbOp.GetOpType()),
|
OpType: pbOp.GetOpType(),
|
||||||
DoPrefix: pbOp.GetDoPrefix(),
|
DoPrefix: pbOp.GetDoPrefix(),
|
||||||
DoRepository: pbOp.GetDoRepository(),
|
DoRepository: pbOp.GetDoRepository(),
|
||||||
Doid: pbOp.GetDoid(),
|
Doid: pbOp.GetDoid(),
|
||||||
@@ -59,7 +59,7 @@ func ToProtobuf(op *Operation) (*pb.OperationData, error) {
|
|||||||
OpId: op.OpID,
|
OpId: op.OpID,
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
OpSource: string(op.OpSource),
|
OpSource: string(op.OpSource),
|
||||||
OpType: string(op.OpType),
|
OpType: op.OpType,
|
||||||
DoPrefix: op.DoPrefix,
|
DoPrefix: op.DoPrefix,
|
||||||
DoRepository: op.DoRepository,
|
DoRepository: op.DoRepository,
|
||||||
Doid: op.Doid,
|
Doid: op.Doid,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func TestFromProtobuf_Basic(t *testing.T) {
|
|||||||
assert.Equal(t, "op-123", result.OpID)
|
assert.Equal(t, "op-123", result.OpID)
|
||||||
assert.Equal(t, now.Unix(), result.Timestamp.Unix())
|
assert.Equal(t, now.Unix(), result.Timestamp.Unix())
|
||||||
assert.Equal(t, model.Source("IRP"), result.OpSource)
|
assert.Equal(t, model.Source("IRP"), result.OpSource)
|
||||||
assert.Equal(t, model.Type("OC_CREATE_HANDLE"), result.OpType)
|
assert.Equal(t, "OC_CREATE_HANDLE", result.OpType)
|
||||||
assert.Equal(t, "test", result.DoPrefix)
|
assert.Equal(t, "test", result.DoPrefix)
|
||||||
assert.Equal(t, "repo", result.DoRepository)
|
assert.Equal(t, "repo", result.DoRepository)
|
||||||
assert.Equal(t, "test/repo/123", result.Doid)
|
assert.Equal(t, "test/repo/123", result.Doid)
|
||||||
@@ -133,7 +133,7 @@ func TestToProtobuf_Basic(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: now,
|
Timestamp: now,
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -166,7 +166,7 @@ func TestToProtobuf_WithHashes(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: now,
|
Timestamp: now,
|
||||||
OpSource: model.OpSourceDOIP,
|
OpSource: model.OpSourceDOIP,
|
||||||
OpType: model.OpTypeCreate,
|
OpType: string(model.OpTypeCreate),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -192,7 +192,7 @@ func TestToProtobuf_WithoutHashes(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: now,
|
Timestamp: now,
|
||||||
OpSource: model.OpSourceDOIP,
|
OpSource: model.OpSourceDOIP,
|
||||||
OpType: model.OpTypeCreate,
|
OpType: string(model.OpTypeCreate),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -511,7 +511,7 @@ func TestRoundTrip_Operation(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: now,
|
Timestamp: now,
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func TestEnvelopeBodyTampering(t *testing.T) {
|
|||||||
OpID: "op-test-002",
|
OpID: "op-test-002",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/456",
|
Doid: "test/repo/456",
|
||||||
@@ -168,7 +168,7 @@ func TestEnvelopeSignatureTampering(t *testing.T) {
|
|||||||
OpID: "op-test-003",
|
OpID: "op-test-003",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/789",
|
Doid: "test/repo/789",
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func TestSignVerifyConsistency(t *testing.T) {
|
|||||||
OpID: "op-test-001",
|
OpID: "op-test-001",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ func TestMarshalTrustlog_Basic(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -229,7 +229,7 @@ func TestMarshalOperation(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -253,7 +253,7 @@ func TestUnmarshalOperation(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
|
|||||||
@@ -113,9 +113,9 @@ func GetOpTypesBySource(source Source) []Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsValidOpType 判断指定操作类型在给定来源下是否合法。
|
// IsValidOpType 判断指定操作类型在给定来源下是否合法。
|
||||||
func IsValidOpType(source Source, opType Type) bool {
|
func IsValidOpType(source Source, opType string) bool {
|
||||||
for _, t := range GetOpTypesBySource(source) {
|
for _, t := range GetOpTypesBySource(source) {
|
||||||
if t == opType {
|
if string(t) == opType {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ type Operation struct {
|
|||||||
OpID string `json:"opId" validate:"max=32"`
|
OpID string `json:"opId" validate:"max=32"`
|
||||||
Timestamp time.Time `json:"timestamp" validate:"required"`
|
Timestamp time.Time `json:"timestamp" validate:"required"`
|
||||||
OpSource Source `json:"opSource" validate:"required,oneof=IRP DOIP"`
|
OpSource Source `json:"opSource" validate:"required,oneof=IRP DOIP"`
|
||||||
OpType Type `json:"opType" validate:"required"`
|
OpType string `json:"opType" validate:"required"`
|
||||||
DoPrefix string `json:"doPrefix" validate:"required,max=512"`
|
DoPrefix string `json:"doPrefix" validate:"required,max=512"`
|
||||||
DoRepository string `json:"doRepository" validate:"required,max=512"`
|
DoRepository string `json:"doRepository" validate:"required,max=512"`
|
||||||
Doid string `json:"doid" validate:"required,max=512"`
|
Doid string `json:"doid" validate:"required,max=512"`
|
||||||
@@ -157,7 +157,7 @@ type Operation struct {
|
|||||||
// 自动完成哈希计算和字段校验,确保创建的 Operation 是完整且有效的。
|
// 自动完成哈希计算和字段校验,确保创建的 Operation 是完整且有效的。
|
||||||
func NewFullOperation(
|
func NewFullOperation(
|
||||||
opSource Source,
|
opSource Source,
|
||||||
opType Type,
|
opType string,
|
||||||
doPrefix, doRepository, doid string,
|
doPrefix, doRepository, doid string,
|
||||||
producerID string,
|
producerID string,
|
||||||
opActor string,
|
opActor string,
|
||||||
@@ -289,7 +289,7 @@ type operationData struct {
|
|||||||
OpID *string `cbor:"opId"`
|
OpID *string `cbor:"opId"`
|
||||||
Timestamp *time.Time `cbor:"timestamp"`
|
Timestamp *time.Time `cbor:"timestamp"`
|
||||||
OpSource *Source `cbor:"opSource"`
|
OpSource *Source `cbor:"opSource"`
|
||||||
OpType *Type `cbor:"opType"`
|
OpType *string `cbor:"opType"`
|
||||||
DoPrefix *string `cbor:"doPrefix"`
|
DoPrefix *string `cbor:"doPrefix"`
|
||||||
DoRepository *string `cbor:"doRepository"`
|
DoRepository *string `cbor:"doRepository"`
|
||||||
Doid *string `cbor:"doid"`
|
Doid *string `cbor:"doid"`
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func TestOperation_CheckAndInit(t *testing.T) {
|
|||||||
op: &model.Operation{
|
op: &model.Operation{
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -48,7 +48,7 @@ func TestOperation_CheckAndInit(t *testing.T) {
|
|||||||
OpID: "", // Will be auto-generated
|
OpID: "", // Will be auto-generated
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -62,7 +62,7 @@ func TestOperation_CheckAndInit(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -77,7 +77,7 @@ func TestOperation_CheckAndInit(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "invalid/123", // Doesn't start with "test/repo"
|
Doid: "invalid/123", // Doesn't start with "test/repo"
|
||||||
@@ -222,7 +222,7 @@ func TestOperation_MarshalUnmarshalBinary(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -260,7 +260,7 @@ func TestOperation_MarshalBinary_Empty(t *testing.T) {
|
|||||||
op := &model.Operation{
|
op := &model.Operation{
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -297,7 +297,7 @@ func TestOperation_DoHash(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -324,7 +324,7 @@ func TestOperationHashData(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -362,7 +362,7 @@ func TestOperation_MarshalTrustlog_EmptyProducerID(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -388,7 +388,7 @@ func TestOperation_MarshalTrustlog_NilSigner(t *testing.T) {
|
|||||||
OpID: "op-123",
|
OpID: "op-123",
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
@@ -452,37 +452,37 @@ func TestIsValidOpType(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
source model.Source
|
source model.Source
|
||||||
opType model.Type
|
opType string
|
||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "IRP有效操作类型",
|
name: "IRP有效操作类型",
|
||||||
source: model.OpSourceIRP,
|
source: model.OpSourceIRP,
|
||||||
opType: model.OpTypeOCCreateHandle,
|
opType: string(model.OpTypeOCCreateHandle),
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "IRP无效操作类型",
|
name: "IRP无效操作类型",
|
||||||
source: model.OpSourceIRP,
|
source: model.OpSourceIRP,
|
||||||
opType: model.OpTypeHello,
|
opType: string(model.OpTypeHello),
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "DOIP有效操作类型",
|
name: "DOIP有效操作类型",
|
||||||
source: model.OpSourceDOIP,
|
source: model.OpSourceDOIP,
|
||||||
opType: model.OpTypeHello,
|
opType: string(model.OpTypeHello),
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "DOIP无效操作类型",
|
name: "DOIP无效操作类型",
|
||||||
source: model.OpSourceDOIP,
|
source: model.OpSourceDOIP,
|
||||||
opType: model.OpTypeOCCreateHandle,
|
opType: string(model.OpTypeOCCreateHandle),
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "未知来源和类型",
|
name: "未知来源和类型",
|
||||||
source: model.Source("unknown"),
|
source: model.Source("unknown"),
|
||||||
opType: model.Type("unknown"),
|
opType: "unknown",
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -502,7 +502,7 @@ func TestNewFullOperation(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
opSource model.Source
|
opSource model.Source
|
||||||
opType model.Type
|
opType string
|
||||||
doPrefix string
|
doPrefix string
|
||||||
doRepository string
|
doRepository string
|
||||||
doid string
|
doid string
|
||||||
@@ -516,7 +516,7 @@ func TestNewFullOperation(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "成功创建完整操作",
|
name: "成功创建完整操作",
|
||||||
opSource: model.OpSourceIRP,
|
opSource: model.OpSourceIRP,
|
||||||
opType: model.OpTypeOCCreateHandle,
|
opType: string(model.OpTypeOCCreateHandle),
|
||||||
doPrefix: "test",
|
doPrefix: "test",
|
||||||
doRepository: "repo",
|
doRepository: "repo",
|
||||||
doid: "test/repo/123",
|
doid: "test/repo/123",
|
||||||
@@ -530,7 +530,7 @@ func TestNewFullOperation(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "空请求体和响应体",
|
name: "空请求体和响应体",
|
||||||
opSource: model.OpSourceIRP,
|
opSource: model.OpSourceIRP,
|
||||||
opType: model.OpTypeOCCreateHandle,
|
opType: string(model.OpTypeOCCreateHandle),
|
||||||
doPrefix: "test",
|
doPrefix: "test",
|
||||||
doRepository: "repo",
|
doRepository: "repo",
|
||||||
doid: "test/repo/123",
|
doid: "test/repo/123",
|
||||||
@@ -544,7 +544,7 @@ func TestNewFullOperation(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "字符串类型的请求体",
|
name: "字符串类型的请求体",
|
||||||
opSource: model.OpSourceIRP,
|
opSource: model.OpSourceIRP,
|
||||||
opType: model.OpTypeOCCreateHandle,
|
opType: string(model.OpTypeOCCreateHandle),
|
||||||
doPrefix: "test",
|
doPrefix: "test",
|
||||||
doRepository: "repo",
|
doRepository: "repo",
|
||||||
doid: "test/repo/123",
|
doid: "test/repo/123",
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func TestOperation_TimestampNanosecondPrecision(t *testing.T) {
|
|||||||
OpID: "op-nanosecond-test",
|
OpID: "op-nanosecond-test",
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
OpSource: model.OpSourceIRP,
|
OpSource: model.OpSourceIRP,
|
||||||
OpType: model.OpTypeOCCreateHandle,
|
OpType: string(model.OpTypeOCCreateHandle),
|
||||||
DoPrefix: "test",
|
DoPrefix: "test",
|
||||||
DoRepository: "repo",
|
DoRepository: "repo",
|
||||||
Doid: "test/repo/123",
|
Doid: "test/repo/123",
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func (r *OperationRecord) ToModel() *model.Operation {
|
|||||||
RequestBodyHash: &r.RequestBodyHash,
|
RequestBodyHash: &r.RequestBodyHash,
|
||||||
ResponseBodyHash: &r.ResponseBodyHash,
|
ResponseBodyHash: &r.ResponseBodyHash,
|
||||||
OpSource: model.Source(r.OpSource),
|
OpSource: model.Source(r.OpSource),
|
||||||
OpType: model.Type(r.OpType),
|
OpType: r.OpType,
|
||||||
DoPrefix: r.DOPrefix,
|
DoPrefix: r.DOPrefix,
|
||||||
DoRepository: r.DORepository,
|
DoRepository: r.DORepository,
|
||||||
ClientIP: r.ClientIP,
|
ClientIP: r.ClientIP,
|
||||||
|
|||||||
@@ -726,7 +726,7 @@ func createE2ETestOperations(count int) []*model.Operation {
|
|||||||
OpID: fmt.Sprintf("e2e-op-%d-%d", timestamp, i),
|
OpID: fmt.Sprintf("e2e-op-%d-%d", timestamp, i),
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OpSource: model.OpSourceDOIP,
|
OpSource: model.OpSourceDOIP,
|
||||||
OpType: model.OpTypeCreate,
|
OpType: string(model.OpTypeCreate),
|
||||||
DoPrefix: "e2e-test",
|
DoPrefix: "e2e-test",
|
||||||
DoRepository: "e2e-repo",
|
DoRepository: "e2e-repo",
|
||||||
Doid: fmt.Sprintf("e2e/test/%d", i),
|
Doid: fmt.Sprintf("e2e/test/%d", i),
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func Example_dbOnly() {
|
|||||||
// 5. 构造 Operation(包含 IP 信息)
|
// 5. 构造 Operation(包含 IP 信息)
|
||||||
op, err := model.NewFullOperation(
|
op, err := model.NewFullOperation(
|
||||||
model.OpSourceDOIP,
|
model.OpSourceDOIP,
|
||||||
model.OpTypeCreate,
|
string(model.OpTypeCreate),
|
||||||
"10.1000",
|
"10.1000",
|
||||||
"my-repo",
|
"my-repo",
|
||||||
"10.1000/my-repo/doc001",
|
"10.1000/my-repo/doc001",
|
||||||
@@ -139,7 +139,7 @@ func Example_dbAndTrustlog() {
|
|||||||
// 5. 构造 Operation
|
// 5. 构造 Operation
|
||||||
op, err := model.NewFullOperation(
|
op, err := model.NewFullOperation(
|
||||||
model.OpSourceDOIP,
|
model.OpSourceDOIP,
|
||||||
model.OpTypeCreate,
|
string(model.OpTypeCreate),
|
||||||
"10.1000",
|
"10.1000",
|
||||||
"my-repo",
|
"my-repo",
|
||||||
"10.1000/my-repo/doc002",
|
"10.1000/my-repo/doc002",
|
||||||
@@ -212,7 +212,7 @@ func Example_trustlogOnly() {
|
|||||||
// 5. 构造 Operation
|
// 5. 构造 Operation
|
||||||
op, err := model.NewFullOperation(
|
op, err := model.NewFullOperation(
|
||||||
model.OpSourceDOIP,
|
model.OpSourceDOIP,
|
||||||
model.OpTypeCreate,
|
string(model.OpTypeCreate),
|
||||||
"10.1000",
|
"10.1000",
|
||||||
"my-repo",
|
"my-repo",
|
||||||
"10.1000/my-repo/doc003",
|
"10.1000/my-repo/doc003",
|
||||||
@@ -278,7 +278,7 @@ func Example_mysqlDatabase() {
|
|||||||
// 5. 构造并发布 Operation
|
// 5. 构造并发布 Operation
|
||||||
op, err := model.NewFullOperation(
|
op, err := model.NewFullOperation(
|
||||||
model.OpSourceDOIP,
|
model.OpSourceDOIP,
|
||||||
model.OpTypeCreate,
|
string(model.OpTypeCreate),
|
||||||
"10.1000",
|
"10.1000",
|
||||||
"my-repo",
|
"my-repo",
|
||||||
"10.1000/my-repo/doc004",
|
"10.1000/my-repo/doc004",
|
||||||
@@ -349,7 +349,7 @@ func Example_sqliteDatabase() {
|
|||||||
// 5. 构造并发布 Operation
|
// 5. 构造并发布 Operation
|
||||||
op, err := model.NewFullOperation(
|
op, err := model.NewFullOperation(
|
||||||
model.OpSourceDOIP,
|
model.OpSourceDOIP,
|
||||||
model.OpTypeCreate,
|
string(model.OpTypeCreate),
|
||||||
"10.1000",
|
"10.1000",
|
||||||
"my-repo",
|
"my-repo",
|
||||||
"10.1000/my-repo/doc005",
|
"10.1000/my-repo/doc005",
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func setupTestDB(t *testing.T) *sql.DB {
|
|||||||
func createTestOperation(t *testing.T, opID string) *model.Operation {
|
func createTestOperation(t *testing.T, opID string) *model.Operation {
|
||||||
op, err := model.NewFullOperation(
|
op, err := model.NewFullOperation(
|
||||||
model.OpSourceDOIP,
|
model.OpSourceDOIP,
|
||||||
model.OpTypeCreate,
|
string(model.OpTypeCreate),
|
||||||
"10.1000",
|
"10.1000",
|
||||||
"test-repo",
|
"test-repo",
|
||||||
"10.1000/test-repo/"+opID,
|
"10.1000/test-repo/"+opID,
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ type ListOperationsRequest struct {
|
|||||||
// 可选过滤条件
|
// 可选过滤条件
|
||||||
Timestamp *time.Time // 操作时间戳
|
Timestamp *time.Time // 操作时间戳
|
||||||
OpSource model.Source // 操作来源
|
OpSource model.Source // 操作来源
|
||||||
OpType model.Type // 操作类型
|
OpType string // 操作类型
|
||||||
DoPrefix string // 数据前缀
|
DoPrefix string // 数据前缀
|
||||||
DoRepository string // 数据仓库
|
DoRepository string // 数据仓库
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ func (c *Client) ListOperations(ctx context.Context, req ListOperationsRequest)
|
|||||||
pbReq := &pb.ListOperationReq{
|
pbReq := &pb.ListOperationReq{
|
||||||
PageSize: req.PageSize,
|
PageSize: req.PageSize,
|
||||||
OpSource: string(req.OpSource),
|
OpSource: string(req.OpSource),
|
||||||
OpType: string(req.OpType),
|
OpType: req.OpType,
|
||||||
DoPrefix: req.DoPrefix,
|
DoPrefix: req.DoPrefix,
|
||||||
DoRepository: req.DoRepository,
|
DoRepository: req.DoRepository,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func TestListOperations_ErrorHandling(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, uint64(10), req.PageSize)
|
assert.Equal(t, uint64(10), req.PageSize)
|
||||||
assert.Equal(t, model.Source("api"), req.OpSource)
|
assert.Equal(t, model.Source("api"), req.OpSource)
|
||||||
assert.Equal(t, model.Type("create"), req.OpType)
|
assert.Equal(t, "create", req.OpType)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ func TestListOperationsRequest(t *testing.T) {
|
|||||||
PreTime: now,
|
PreTime: now,
|
||||||
Timestamp: &now,
|
Timestamp: &now,
|
||||||
OpSource: model.Source("test"),
|
OpSource: model.Source("test"),
|
||||||
OpType: model.Type("create"),
|
OpType: "create",
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, uint64(10), req.PageSize)
|
assert.Equal(t, uint64(10), req.PageSize)
|
||||||
|
|||||||
Reference in New Issue
Block a user