Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Add helpers for basic acceptance test #20

Merged
merged 20 commits into from
May 25, 2020
Merged

Add helpers for basic acceptance test #20

merged 20 commits into from
May 25, 2020

Conversation

jrhouston
Copy link
Contributor

@jrhouston jrhouston commented May 5, 2020

Description

Closes #7

This PR adds a very basic acceptance test and brings in the terraform-plugin-test helper to drive the tests using the terraform binary.

I have left the test deliberately indirect at the moment to open discussion. We are likely to re-invent parts of the existing test framework because we can't drop them in here. Something to consider is making it easy for ourselves to refactor to the new SDK when it becomes available, without inconveniencing ourselves too much while we develop this in the meantime.

For convenience I have introduced functions for:

  • Creating and destroying namespaces
  • Asserting that resources exist / do not exist
  • Picking out the object attribute and asserting that fields have a particular value

Run the tests using make testacc as usual.

References

https://github.com/hashicorp/terraform-plugin-test

Unblocks #15

provider = kubernetes-alpha

manifest = {
"apiVersion" = "v1"
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 was the very simplest test I could think of.

@jrhouston jrhouston requested review from alexsomesan, aareet and dak1n1 May 5, 2020 22:56
@jrhouston jrhouston marked this pull request as ready for review May 5, 2020 22:59
Copy link
Member

@alexsomesan alexsomesan left a comment

Choose a reason for hiding this comment

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

Sweet! I tried it out quickly and works nicely.
Dropped some conversation starters here and there and I'll play more with it in the meantime.

provider/provider_test.go Outdated Show resolved Hide resolved
provider/server.go Show resolved Hide resolved
provider/provider_test.go Outdated Show resolved Hide resolved
@jrhouston
Copy link
Contributor Author

jrhouston commented May 8, 2020

I've tidied the helper functions into a couple of helper packages, one for kubernetes and another for making assertions against the tfstate so it's easy to write statements like:

tfstate.AssertAttributeEqual(t, "kubernetes_manifest.test.object.data.foo", "bar")

I don't really want to take it any further than this as the test is pretty legible, and this is pretty much all we need for the moment. We can add in more things as we go and this rough format will be easy to port over to the SDK style of tests when the time comes to do that.

@jrhouston jrhouston requested a review from alexsomesan May 8, 2020 22:45
@jrhouston
Copy link
Contributor Author

Something else I've done here is put the terraform configs for the tests into their own files in the testdata directory.

It always bothered me that the configs in other providers were full of go formatting directives. You couldn't just grab a test config and run it by hand with terraform without editing out the formatting directives.

As an alternative, I'm using terraform's own variable syntax here and setting them when we load the config file.

@alexsomesan
Copy link
Member

alexsomesan commented May 9, 2020 via email

return ""
}

// FIXME HACK this is something we could probably add to the binary test helper
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a PR open to address this here hashicorp/terraform-plugin-test#24

@jrhouston
Copy link
Contributor Author

Have added a -server-side-plan flag so we can run the suite twice with it enabled and disabled, rather than having multiple explicit tests.

Copy link
Member

@alexsomesan alexsomesan left a comment

Choose a reason for hiding this comment

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

LGTM. Cool stuff, @jrhouston !

// FIXME HACK this is something we could probably add to the binary test helper
// and it can supply the -var flag instead of doing this
vars := ""
for name, value := range tfvars {
Copy link
Member

Choose a reason for hiding this comment

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

For when this might grow more complex, we should keep in mind that Golang has a dedicated text templating mechanism that nicely separates the "model" from the "view", to make an old-fashioned analogy :)
It's detailed here: https://golang.org/pkg/text/template

Just food for thought, no need to change in this now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true - but if we use template then we're back to having edit out go template directives before we can run the acceptance test fixtures by hand. I'm hoping we can do everything just by supplying input variables and make use of HCL's var, and for_each and so on.

@jrhouston jrhouston merged commit 0e91640 into dev May 25, 2020
@jrhouston jrhouston deleted the acc-tests branch May 25, 2020 18:20
@alexsomesan
Copy link
Member

alexsomesan commented May 25, 2020 via email

@ghost
Copy link

ghost commented Jun 26, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add testing framework
2 participants