mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 02:57:59 +00:00
postgres: connection_url fix
This commit is contained in:
@@ -16,11 +16,21 @@ import (
|
||||
func TestBackend_basic(t *testing.T) {
|
||||
b, _ := Factory(logical.TestBackendConfig())
|
||||
|
||||
d1 := map[string]interface{}{
|
||||
"connection_url": os.Getenv("PG_URL"),
|
||||
}
|
||||
d2 := map[string]interface{}{
|
||||
"value": os.Getenv("PG_URL"),
|
||||
}
|
||||
|
||||
logicaltest.Test(t, logicaltest.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Backend: b,
|
||||
Steps: []logicaltest.TestStep{
|
||||
testAccStepConfig(t),
|
||||
testAccStepConfig(t, d1, false),
|
||||
testAccStepRole(t),
|
||||
testAccStepReadCreds(t, b, "web"),
|
||||
testAccStepConfig(t, d2, false),
|
||||
testAccStepRole(t),
|
||||
testAccStepReadCreds(t, b, "web"),
|
||||
},
|
||||
@@ -30,12 +40,15 @@ func TestBackend_basic(t *testing.T) {
|
||||
|
||||
func TestBackend_roleCrud(t *testing.T) {
|
||||
b, _ := Factory(logical.TestBackendConfig())
|
||||
d := map[string]interface{}{
|
||||
"connection_url": os.Getenv("PG_URL"),
|
||||
}
|
||||
|
||||
logicaltest.Test(t, logicaltest.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Backend: b,
|
||||
Steps: []logicaltest.TestStep{
|
||||
testAccStepConfig(t),
|
||||
testAccStepConfig(t, d, false),
|
||||
testAccStepRole(t),
|
||||
testAccStepReadRole(t, "web", testRole),
|
||||
testAccStepDeleteRole(t, "web"),
|
||||
@@ -44,18 +57,63 @@ func TestBackend_roleCrud(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestBackend_configConnection(t *testing.T) {
|
||||
b := Backend()
|
||||
d1 := map[string]interface{}{
|
||||
"value": os.Getenv("PG_URL"),
|
||||
}
|
||||
d2 := map[string]interface{}{
|
||||
"connection_url": os.Getenv("PG_URL"),
|
||||
}
|
||||
d3 := map[string]interface{}{
|
||||
"value": os.Getenv("PG_URL"),
|
||||
"connection_url": os.Getenv("PG_URL"),
|
||||
}
|
||||
d4 := map[string]interface{}{}
|
||||
|
||||
logicaltest.Test(t, logicaltest.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Backend: b,
|
||||
Steps: []logicaltest.TestStep{
|
||||
testAccStepConfig(t, d1, false),
|
||||
testAccStepConfig(t, d2, false),
|
||||
testAccStepConfig(t, d3, false),
|
||||
testAccStepConfig(t, d4, true),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccPreCheck(t *testing.T) {
|
||||
if v := os.Getenv("PG_URL"); v == "" {
|
||||
t.Fatal("PG_URL must be set for acceptance tests")
|
||||
}
|
||||
}
|
||||
|
||||
func testAccStepConfig(t *testing.T) logicaltest.TestStep {
|
||||
func testAccStepConfig(t *testing.T, d map[string]interface{}, expectError bool) logicaltest.TestStep {
|
||||
return logicaltest.TestStep{
|
||||
Operation: logical.UpdateOperation,
|
||||
Path: "config/connection",
|
||||
Data: map[string]interface{}{
|
||||
"value": os.Getenv("PG_URL"),
|
||||
Data: d,
|
||||
ErrorOk: true,
|
||||
Check: func(resp *logical.Response) error {
|
||||
if expectError {
|
||||
if resp.Data == nil {
|
||||
return fmt.Errorf("data is nil")
|
||||
}
|
||||
var e struct {
|
||||
Error string `mapstructure:"error"`
|
||||
}
|
||||
if err := mapstructure.Decode(resp.Data, &e); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(e.Error) == 0 {
|
||||
return fmt.Errorf("expected error, but write succeeded.")
|
||||
}
|
||||
return nil
|
||||
} else if resp != nil {
|
||||
return fmt.Errorf("response should be nil")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user