diff options
author | Radek Simko <radek.simko@gmail.com> | 2017-08-14 16:10:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-14 16:10:17 +0200 |
commit | 00a66330be57dc8d7f987b4235d65d372f6b471f (patch) | |
tree | 864f925049d422033dd25a73bafce32b361c8827 /vendor/github.com/hashicorp/terraform/helper/resource/testing.go | |
parent | b6a7c48445fdb87dcae46906aa7e9349209d8bb5 (diff) | |
parent | c680a8e1622ed0f18751d9d167c836ee24f5e897 (diff) | |
download | terraform-provider-statuscake-00a66330be57dc8d7f987b4235d65d372f6b471f.tar.gz terraform-provider-statuscake-00a66330be57dc8d7f987b4235d65d372f6b471f.tar.zst terraform-provider-statuscake-00a66330be57dc8d7f987b4235d65d372f6b471f.zip |
Merge pull request #3 from terraform-providers/vendor-tf-0.10
vendor: github.com/hashicorp/terraform/...@v0.10.0
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/resource/testing.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/resource/testing.go | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/resource/testing.go b/vendor/github.com/hashicorp/terraform/helper/resource/testing.go index ebdbde2..d7de1a0 100644 --- a/vendor/github.com/hashicorp/terraform/helper/resource/testing.go +++ b/vendor/github.com/hashicorp/terraform/helper/resource/testing.go | |||
@@ -383,11 +383,11 @@ func Test(t TestT, c TestCase) { | |||
383 | c.PreCheck() | 383 | c.PreCheck() |
384 | } | 384 | } |
385 | 385 | ||
386 | ctxProviders, err := testProviderFactories(c) | 386 | providerResolver, err := testProviderResolver(c) |
387 | if err != nil { | 387 | if err != nil { |
388 | t.Fatal(err) | 388 | t.Fatal(err) |
389 | } | 389 | } |
390 | opts := terraform.ContextOpts{Providers: ctxProviders} | 390 | opts := terraform.ContextOpts{ProviderResolver: providerResolver} |
391 | 391 | ||
392 | // A single state variable to track the lifecycle, starting with no state | 392 | // A single state variable to track the lifecycle, starting with no state |
393 | var state *terraform.State | 393 | var state *terraform.State |
@@ -400,15 +400,22 @@ func Test(t TestT, c TestCase) { | |||
400 | var err error | 400 | var err error |
401 | log.Printf("[WARN] Test: Executing step %d", i) | 401 | log.Printf("[WARN] Test: Executing step %d", i) |
402 | 402 | ||
403 | // Determine the test mode to execute | 403 | if step.Config == "" && !step.ImportState { |
404 | if step.Config != "" { | ||
405 | state, err = testStepConfig(opts, state, step) | ||
406 | } else if step.ImportState { | ||
407 | state, err = testStepImportState(opts, state, step) | ||
408 | } else { | ||
409 | err = fmt.Errorf( | 404 | err = fmt.Errorf( |
410 | "unknown test mode for step. Please see TestStep docs\n\n%#v", | 405 | "unknown test mode for step. Please see TestStep docs\n\n%#v", |
411 | step) | 406 | step) |
407 | } else { | ||
408 | if step.ImportState { | ||
409 | if step.Config == "" { | ||
410 | step.Config = testProviderConfig(c) | ||
411 | } | ||
412 | |||
413 | // Can optionally set step.Config in addition to | ||
414 | // step.ImportState, to provide config for the import. | ||
415 | state, err = testStepImportState(opts, state, step) | ||
416 | } else { | ||
417 | state, err = testStepConfig(opts, state, step) | ||
418 | } | ||
412 | } | 419 | } |
413 | 420 | ||
414 | // If there was an error, exit | 421 | // If there was an error, exit |
@@ -496,16 +503,29 @@ func Test(t TestT, c TestCase) { | |||
496 | } | 503 | } |
497 | } | 504 | } |
498 | 505 | ||
499 | // testProviderFactories is a helper to build the ResourceProviderFactory map | 506 | // testProviderConfig takes the list of Providers in a TestCase and returns a |
507 | // config with only empty provider blocks. This is useful for Import, where no | ||
508 | // config is provided, but the providers must be defined. | ||
509 | func testProviderConfig(c TestCase) string { | ||
510 | var lines []string | ||
511 | for p := range c.Providers { | ||
512 | lines = append(lines, fmt.Sprintf("provider %q {}\n", p)) | ||
513 | } | ||
514 | |||
515 | return strings.Join(lines, "") | ||
516 | } | ||
517 | |||
518 | // testProviderResolver is a helper to build a ResourceProviderResolver | ||
500 | // with pre instantiated ResourceProviders, so that we can reset them for the | 519 | // with pre instantiated ResourceProviders, so that we can reset them for the |
501 | // test, while only calling the factory function once. | 520 | // test, while only calling the factory function once. |
502 | // Any errors are stored so that they can be returned by the factory in | 521 | // Any errors are stored so that they can be returned by the factory in |
503 | // terraform to match non-test behavior. | 522 | // terraform to match non-test behavior. |
504 | func testProviderFactories(c TestCase) (map[string]terraform.ResourceProviderFactory, error) { | 523 | func testProviderResolver(c TestCase) (terraform.ResourceProviderResolver, error) { |
505 | ctxProviders := c.ProviderFactories // make(map[string]terraform.ResourceProviderFactory) | 524 | ctxProviders := c.ProviderFactories |
506 | if ctxProviders == nil { | 525 | if ctxProviders == nil { |
507 | ctxProviders = make(map[string]terraform.ResourceProviderFactory) | 526 | ctxProviders = make(map[string]terraform.ResourceProviderFactory) |
508 | } | 527 | } |
528 | |||
509 | // add any fixed providers | 529 | // add any fixed providers |
510 | for k, p := range c.Providers { | 530 | for k, p := range c.Providers { |
511 | ctxProviders[k] = terraform.ResourceProviderFactoryFixed(p) | 531 | ctxProviders[k] = terraform.ResourceProviderFactoryFixed(p) |
@@ -527,7 +547,7 @@ func testProviderFactories(c TestCase) (map[string]terraform.ResourceProviderFac | |||
527 | } | 547 | } |
528 | } | 548 | } |
529 | 549 | ||
530 | return ctxProviders, nil | 550 | return terraform.ResourceProviderResolverFixed(ctxProviders), nil |
531 | } | 551 | } |
532 | 552 | ||
533 | // UnitTest is a helper to force the acceptance testing harness to run in the | 553 | // UnitTest is a helper to force the acceptance testing harness to run in the |