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

CompareToSlice panics when actual slice has fewer elements than the table #13

Open
rdumont opened this issue Dec 22, 2020 · 0 comments
Open

Comments

@rdumont
Copy link
Owner

rdumont commented Dec 22, 2020

For instance, given the following step definition:

func (s *Steps) ThenTheReturnedErrorsShouldBe(errorsTbl *godog.Table) error {
	actualResponse := []*struct {
		Code        int
		Description string
	}{
		{Code: 123, Description: "Only one error"}, // <-- Only one element here
	}

	if err := assitdog.NewDefault().CompareToSlice(actualResponse, errorsTbl); err != nil {
		return fmt.Errorf("return errors are different from expected: %v", err)
	}

	return nil
}

And the following step in a scenario:

  Then the returned errors should be
    | Code | Description  |
    | 123  | First error  |
    | 456  | Second error |

I would expect to see an error stating that the number of elements is different. However, I got a panic like the following:

panic: reflect: slice index out of range

goroutine 100 [running]:
testing.tRunner.func1.1(0x15b0220, 0x1727ba0)
	/usr/local/Cellar/go/1.15.5/libexec/src/testing/testing.go:1072 +0x30d
testing.tRunner.func1(0xc000316a80)
	/usr/local/Cellar/go/1.15.5/libexec/src/testing/testing.go:1075 +0x41a
panic(0x15b0220, 0x1727ba0)
	/usr/local/Cellar/go/1.15.5/libexec/src/runtime/panic.go:969 +0x1b9
reflect.Value.Index(0x15a4da0, 0xc000153e00, 0x97, 0x1, 0x1a8bfe0, 0x0, 0x0)
	/usr/local/Cellar/go/1.15.5/libexec/src/reflect/value.go:962 +0x1f2
github.com/rdumont/assistdog.(*Assist).CompareToSlice(0xc0003054a0, 0x15a4da0, 0xc000153e00, 0xc00031c7a0, 0x0, 0x0)
	/Users/rodrigodumont/go/pkg/mod/github.com/rdumont/[email protected]/assist.go:212 +0x197
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

1 participant