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

Populate a mock table with test data #31

Open
NickLarsenNZ opened this issue Sep 20, 2020 · 0 comments
Open

Populate a mock table with test data #31

NickLarsenNZ opened this issue Sep 20, 2020 · 0 comments

Comments

@NickLarsenNZ
Copy link

Hi,

I've seen the example for setting up the mock client, but I'd like to reuse the client for other tests. I wondered if a mock table could be populated with some test data.

So far I have tried iterating through test data:

func init() {
	mock_dynamodb, mock = dynamock.New()
	test_table = "example"

	test_data = map[string]struct {
		etag        string
		lastversion string
	}{
		"aws": {etag: "33a64df551425fcc55e4d42a148795d9f25f89d4", lastversion: "v1.6.5"},
		"gcp": {etag: "51425fcc55e4d42a148795d9f4df5f89d42533a6", lastversion: "v2.3.1"},
	}

	m := mock.ExpectGetItem().ToTable(test_table)
	for key, value := range test_data {
		m.WithKeys(map[string]*dynamodb.AttributeValue{
			"Cloud": {
				S: aws.String(key),
			},
		}).WillReturns(dynamodb.GetItemOutput{
			Item: map[string]*dynamodb.AttributeValue{
				"Cloud": {S: aws.String(key)},
				"ETag":     {S: aws.String(value.etag)},
				"Version":  {S: aws.String(value.lastversion)},
			},
		})
	}
}

But I receive the following error in one of my tests (expecting to lookup the second test record, but the responses contain the first):

Expect key map[Provider:{
  S: "gcp"
}] but found key map[Provider:{
  S: "aws"
}]
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