github.com/nevins-b/terraform@v0.3.8-0.20170215184714-bbae22007d5a/backend/testing.go (about) 1 package backend 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/terraform/config" 7 "github.com/hashicorp/terraform/terraform" 8 ) 9 10 // TestBackendConfig validates and configures the backend with the 11 // given configuration. 12 func TestBackendConfig(t *testing.T, b Backend, c map[string]interface{}) Backend { 13 // Get the proper config structure 14 rc, err := config.NewRawConfig(c) 15 if err != nil { 16 t.Fatalf("bad: %s", err) 17 } 18 conf := terraform.NewResourceConfig(rc) 19 20 // Validate 21 warns, errs := b.Validate(conf) 22 if len(warns) > 0 { 23 t.Fatalf("warnings: %s", warns) 24 } 25 if len(errs) > 0 { 26 t.Fatalf("errors: %s", errs) 27 } 28 29 // Configure 30 if err := b.Configure(conf); err != nil { 31 t.Fatalf("err: %s", err) 32 } 33 34 return b 35 }