Unexpected Method Call

Open
#586 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
go
Domain
testing

Research direction

Start with the reported mockDynamo.PutItem implementation and its ExpectPutItem helper, then reproduce the failure in TestInvokeEvents using the shown dynamodb.PutItemInput. Compare the expected and actual values, especially the proto.Marshal bytes in the B field, and verify the result against testify's argument-matching behavior. Done means explaining why equivalent-looking calls differ and identifying a reliable matching behavior.

Written by the indexing model from the issue text.

Description

I'm trying to mock PutItem(*dynamodb.PutItemInput) from AWS Dynamo Package GoDoc here

However, I'm running into a bunch of problems that look something like this:

--- FAIL: TestInvokeEvents (0.00s)
panic:

mock: Unexpected Method Call
-----------------------------

PutItem(*dynamodb.PutItemInput)
		0: {
  Item: {
    account#user: {
      S: "2#b396abf06c7264027a0a2d037d5ccc25"
    },
    time#name#id: {
      S: "1642501880#pageView#9c7e33a0-9a2f-4372-b5bf-ef20a9995d29"
    },
    proto_message: {
      B: <binary> len 348
    }
  },
  TableName: "test_table"
}

The closest call I have is:

PutItem(*dynamodb.PutItemInput)
		0: {
  Item: {
    account#user: {
      S: "2#b396abf06c7264027a0a2d037d5ccc25"
    },
    time#name#id: {
      S: "1642501880#pageView#9c7e33a0-9a2f-4372-b5bf-ef20a9995d29"
    },
    proto_message: {
      B: <binary> len 348
    }
  },
  TableName: "test_table"
}


 [recovered]
	panic:

I've tried a couple of things:

  • Check for types:
func (md *mockDynamo) PutItem(input *dynamodb.PutItemInput) (*dynamodb.PutItemOutput, error) {
	args := md.Called(input)
	return args.Get(0).(*dynamodb.PutItemOutput), args.Error(1)
}

func (db *mockDynamo) ExpectPutItem(putItemInput *dynamodb.PutItemInput, putItemOutput *dynamodb.PutItemOutput, withErr error) {
	db.On("PutItem", putItemInput).Return(putItemOutput, withErr).Once()
}
  • Removed the .Once() to make sure it's not being called multiple times..

What I've found after debugging this for about 5-6 hours is that the issue seemed to be near the B: <binary> len 348, which is the bytes result coming from proto.Marshal, removing the bytes from being included in the object resulted in the type passing.
Currently I've been able to workaround the issue by using mock.Anything, however it would be great to know as to why this is even happening!

Much appreciated and looking forward to chasing this down!
-- Robin

Dominant language
Go
Stars
26.2k
Forks
1.9k
Avg merge
2d 4h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stretchr/testify

All issues in stretchr/testify

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.