Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatchedBy doesn't seem to work? #432

Closed
decibel opened this issue Apr 18, 2017 · 1 comment
Closed

MatchedBy doesn't seem to work? #432

decibel opened this issue Apr 18, 2017 · 1 comment

Comments

@decibel
Copy link

decibel commented Apr 18, 2017

... or maybe I'm just doing it wrong...

    m.On("DescribeDBInstances",
            //mock.Anything,
            //mock.AnythingOfType("*rds.DescribeDBInstancesInput"),
            /* TODO: Not sure how to make this work...
            */
            // Only run mock if input is a test UUID
            mock.MatchedBy(
                func(input *rds.DescribeDBInstancesInput) bool {
                    return input.DBInstanceIdentifier == aws.String("db-test UUID")
                },
            ),
        ).Return(mockResultFn, nil).Once()

is producing this:


mock: Unexpected Method Call
-----------------------------
DescribeDBInstances(*rds.DescribeDBInstancesInput)
                                0: {
  DBInstanceIdentifier: "db-test UUID"
}

The closest call I have is:

DescribeDBInstances(mock.argumentMatcher)
                                0: mock.argumentMatcher{fn:reflect.Value{typ:(*reflect.rtype)(0x1498920), ptr:(unsafe.Pointer)(0x156dca0), flag:0x13}}

The S3 example at https://github.com/vektra/mockery leads me to believe that this should work, no?

@Willyham
Copy link

Willyham commented May 26, 2017

You're comparing pointers when you want to be comparing values. Try:

 return *input.DBInstanceIdentifier == "db-test UUID"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants