我正在使用两个 AWS 服务,Glue 和 DynamoDB,并且这两个服务具有相同的方法名称,CreateTable因此在模拟这些服务时,我收到CreateTable is ambiguous错误。胶水:CreateTable https://docs.aws.amazon.com/sdk-for-go/api/service/glue/#Glue.CreateTableDynamoDB:CreateTable https://docs.aws.amazon.com/sdk-for-go/api/service/dynamodb/#DynamoDB.CreateTable有什么办法可以解决这个问题吗?代码:type UpdateWorkflow struct { glueIface glueiface.GlueAPI dbIface dynamodbiface.DynamoDBAPI tableName string}func NewUpdateWorkflow(tableName string) *UpdateWorkflow { sess := sessions.NewSession() return &UpdateWorkflow{ dbIface: dynamodb.New(sess), glueIface: glue.New(sess), tableName: tableName, }}单元测试:// MockUpdateWorkflow is a mock implementation of gluetestutils and dynamodb servicetype MockUpdateWorkflow struct { glueiface.GlueAPI dynamodbiface.DynamoDBAPI mock.Mock}func setup() (*UpdateWorkflow, *MockUpdateWorkflow) { mockClient := new(MockUpdateWorkflow) mockServices := &UpdateWorkflow{ glueIface: mockClient, dbIface: mockClient, tableName: mockTableName, } return mockServices, mockClient}
1 回答
慕标琳琳
TA贡献1830条经验 获得超9个赞
如果函数名称冲突,则无法嵌入接口,必须使用命名字段:
type MockUpdateWorkflow struct {
g glueiface.GlueAPI
d dynamodbiface.DynamoDBAPI
mock.Mock
}
func setup() (*UpdateWorkflow, *MockUpdateWorkflow) {
mockClient := new(MockUpdateWorkflow)
mockServices := &UpdateWorkflow{
glueIface: mockClient.g,
dbIface: mockClient.d,
tableName: mockTableName,
}
return mockServices, mockClient
}
- 1 回答
- 0 关注
- 120 浏览
添加回答
举报
0/150
提交
取消