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

BeAssignableToTypeOf fails with confusing error when just one of actual or expected is nil #280

Closed
nwmahoney opened this issue May 10, 2018 · 2 comments

Comments

@nwmahoney
Copy link
Contributor

The relevant lines of code are here.

Our code under test:

func Configure() interface{} {
  return nil
}

Our test:

It("returns a govmomi client", func() {
  expectedClient := new(govmomi.Client)

  actualClient := packageundertest.Configure()
  Expect(actualClient).To(BeAssignableToTypeOf(expectedClient))
})

Test output:

    returns a govmomi client [It]
    /Users/pivotal/go/src/github.com/rowanjacobs/terraform-provider-vsphereovf/vsphereovf/provider_test.go:68

    Refusing to compare <nil> to <nil>.
    Be explicit and use BeNil() instead.  This is to avoid mistakes where both sides of an assertion are erroneously
 uninitialized.

This confuses us since expectedClient is not actually nil (printing it and its address confirms this).

@williammartin
Copy link
Sponsor Collaborator

I think this is a mistake in the BeAssignableToTypeOf matcher. We can see here:

if actual == nil || matcher.Expected == nil {
that we are doing an Or comparison but in the EqualTo matcher here:
if actual == nil && matcher.Expected == nil {
we are doing an And comparison.

I don't see why they would be different (but I haven't delved super deeply into the BeAssignableToTypeOf matcher).

Would you be ok opening a PR? Otherwise might get round to it tomorrow or monday.

@rowanjacobs
Copy link

Sure, we'll open a PR for it.

nwmahoney pushed a commit to nwmahoney/gomega that referenced this issue May 10, 2018
if exactly one of actual or expected is nil.

Fixes onsi#280.

Signed-off-by: Rowan Jacobs <rojacobs@pivotal.io>
@blgm blgm closed this as completed in #281 May 11, 2018
blgm pushed a commit that referenced this issue May 11, 2018
)

* AssignableToTypeOf returns false without error

if exactly one of actual or expected is nil.

Fixes #280.

Signed-off-by: Rowan Jacobs <rojacobs@pivotal.io>

* error when actual is not nil and expected is nil

Signed-off-by: Rowan Jacobs <rojacobs@pivotal.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants