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

chore: add tests for sshkey (resource + data) #94

Merged
merged 11 commits into from
Jun 2, 2021

Conversation

razbensimon
Copy link
Contributor

Issue & Steps to Reproduce / Feature Request

Solution

  • added tests for sshkey
  • fix quotes bug in helper tests

@razbensimon razbensimon changed the title chore: add tests for sshkey resource chore: add tests for sshkey (resource + data) Jun 2, 2021
@razbensimon razbensimon requested a review from a team June 2, 2021 13:57
Copy link
Contributor

@yaronya yaronya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 👍
Left you some comments ✍️

Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceFullName, "id", sshKey.Id),
resource.TestCheckResourceAttr(resourceFullName, "name", sshKey.Name),
resource.TestCheckResourceAttr(resourceFullName, "value", sshKey.Value),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@razbensimon So the decrypted ssh key exists on the returned object? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the resource, not the data tests

Copy link
Contributor

@yaronya yaronya Jun 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but still, I get that it should be a part of the SshKeyCreatePayload but I'm not sure it should be a part of the ssh key schema because nobody uses it and it's a secret value. WDYT? (shouldn't be on this PR btw)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put sensitive for now, and lets talk with the team

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"testing"
)

func TestUnitSshKeyDataSourceById(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really feels like we can DRY those two test functions. I think it's worth an effort 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) {
mock.EXPECT().SshKeys().AnyTimes().Return([]client.SshKey{sshKey}, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we try to be more specific with .Times(1)?
This is also relevant for all other tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20f7ef7
worked only for resource tests file. data must have AnyTimes from some reason

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell maybe how many times it runs? (you can check out using debugger).
I'm asking because it's important to understand this tho.If it's only two - we can add a setting that prevents the second time from running so we'd be able to assert the number of calls easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do you see it on the debugger? what line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤙

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env0/resource_sshkey_test.go Outdated Show resolved Hide resolved
}

runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) {
mock.EXPECT().SshKeyCreate(client.SshKeyCreatePayload{Name: sshKey.Name, Value: sshKey.Value}).Times(1).Return(sshKey, nil).Return(sshKey, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@razbensimon You got a redundant Return() call here 🙊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@razbensimon razbensimon merged commit 4be2889 into main Jun 2, 2021
@razbensimon razbensimon deleted the chore-sskey-resource-test branch June 2, 2021 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants