@@ -4,81 +4,83 @@ import (
44 "fmt"
55 "testing"
66
7- r "github.com/hashicorp/terraform/helper/resource"
7+ "github.com/hashicorp/terraform/helper/acctest"
8+ "github.com/hashicorp/terraform/helper/resource"
89 "github.com/hashicorp/terraform/terraform"
910
1011 "github.com/hashicorp/vault/api"
1112)
1213
1314func TestResourceGenericSecret (t * testing.T ) {
14- r .Test (t , r.TestCase {
15+ path := acctest .RandomWithPrefix ("secret/test" )
16+ resource .Test (t , resource.TestCase {
1517 Providers : testProviders ,
1618 PreCheck : func () { testAccPreCheck (t ) },
17- Steps : []r .TestStep {
18- r .TestStep {
19- Config : testResourceGenericSecret_initialConfig ,
20- Check : testResourceGenericSecret_initialCheck ,
19+ Steps : []resource .TestStep {
20+ resource .TestStep {
21+ Config : testResourceGenericSecret_initialConfig ( path ) ,
22+ Check : testResourceGenericSecret_initialCheck ( path ) ,
2123 },
22- r .TestStep {
24+ resource .TestStep {
2325 Config : testResourceGenericSecret_updateConfig ,
2426 Check : testResourceGenericSecret_updateCheck ,
2527 },
2628 },
2729 })
2830}
2931
30- var testResourceGenericSecret_initialConfig = `
31-
32+ func testResourceGenericSecret_initialConfig ( path string ) string {
33+ return fmt . Sprintf ( `
3234resource "vault_generic_secret" "test" {
33- path = "secret/foo"
34- allow_read = true
35+ path = "%s"
3536 data_json = <<EOT
3637{
3738 "zip": "zap"
3839}
3940EOT
41+ }` , path )
4042}
4143
42- `
43-
44- func testResourceGenericSecret_initialCheck (s * terraform.State ) error {
45- resourceState := s .Modules [0 ].Resources ["vault_generic_secret.test" ]
46- if resourceState == nil {
47- return fmt .Errorf ("resource not found in state" )
48- }
49-
50- instanceState := resourceState .Primary
51- if instanceState == nil {
52- return fmt .Errorf ("resource has no primary instance" )
53- }
54-
55- path := instanceState .ID
56-
57- if path != instanceState .Attributes ["path" ] {
58- return fmt .Errorf ("id doesn't match path" )
44+ func testResourceGenericSecret_initialCheck (expectedPath string ) resource.TestCheckFunc {
45+ return func (s * terraform.State ) error {
46+ resourceState := s .Modules [0 ].Resources ["vault_generic_secret.test" ]
47+ if resourceState == nil {
48+ return fmt .Errorf ("resource not found in state" )
49+ }
50+
51+ instanceState := resourceState .Primary
52+ if instanceState == nil {
53+ return fmt .Errorf ("resource has no primary instance" )
54+ }
55+
56+ path := instanceState .ID
57+
58+ if path != instanceState .Attributes ["path" ] {
59+ return fmt .Errorf ("id doesn't match path" )
60+ }
61+ if path != expectedPath {
62+ return fmt .Errorf ("unexpected secret path" )
63+ }
64+
65+ client := testProvider .Meta ().(* api.Client )
66+ secret , err := client .Logical ().Read (path )
67+ if err != nil {
68+ return fmt .Errorf ("error reading back secret: %s" , err )
69+ }
70+
71+ if got , want := secret .Data ["zip" ], "zap" ; got != want {
72+ return fmt .Errorf ("'zip' data is %q; want %q" , got , want )
73+ }
74+
75+ return nil
5976 }
60- if path != "secret/foo" {
61- return fmt .Errorf ("unexpected secret path" )
62- }
63-
64- client := testProvider .Meta ().(* api.Client )
65- secret , err := client .Logical ().Read (path )
66- if err != nil {
67- return fmt .Errorf ("error reading back secret: %s" , err )
68- }
69-
70- if got , want := secret .Data ["zip" ], "zap" ; got != want {
71- return fmt .Errorf ("'zip' data is %q; want %q" , got , want )
72- }
73-
74- return nil
7577}
7678
7779var testResourceGenericSecret_updateConfig = `
7880
7981resource "vault_generic_secret" "test" {
8082 path = "secret/foo"
81- allow_read = true
83+ disable_read = false
8284 data_json = <<EOT
8385{
8486 "zip": "zoop"
0 commit comments