terraform/internal/backend/remote-state/pg/client_test.go

77 lines
1.9 KiB
Go
Raw Normal View History

2018-10-10 23:42:57 +02:00
package pg
2019-02-27 01:46:06 +01:00
// Create the test database: createdb terraform_backend_pg_test
// TF_ACC=1 GO111MODULE=on go test -v -mod=vendor -timeout=2m -parallel=4 github.com/hashicorp/terraform/backend/remote-state/pg
2018-10-10 23:42:57 +02:00
import (
"database/sql"
"fmt"
"testing"
"github.com/hashicorp/terraform/internal/backend"
"github.com/hashicorp/terraform/internal/states/remote"
2018-10-10 23:42:57 +02:00
)
func TestRemoteClient_impl(t *testing.T) {
var _ remote.Client = new(RemoteClient)
var _ remote.ClientLocker = new(RemoteClient)
}
func TestRemoteClient(t *testing.T) {
2019-02-27 01:46:06 +01:00
testACC(t)
2018-10-10 23:42:57 +02:00
connStr := getDatabaseUrl()
schemaName := fmt.Sprintf("terraform_%s", t.Name())
dbCleaner, err := sql.Open("postgres", connStr)
if err != nil {
t.Fatal(err)
}
defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName))
2018-11-14 02:09:43 +01:00
config := backend.TestWrapConfig(map[string]interface{}{
2018-10-10 23:42:57 +02:00
"conn_str": connStr,
"schema_name": schemaName,
2018-11-14 02:09:43 +01:00
})
2018-10-10 23:42:57 +02:00
b := backend.TestBackendConfig(t, New(), config).(*Backend)
if b == nil {
t.Fatal("Backend could not be configured")
}
2018-11-14 02:09:43 +01:00
s, err := b.StateMgr(backend.DefaultStateName)
2018-10-10 23:42:57 +02:00
if err != nil {
t.Fatal(err)
}
remote.TestClient(t, s.(*remote.State).Client)
}
func TestRemoteLocks(t *testing.T) {
2019-02-27 01:46:06 +01:00
testACC(t)
2018-10-10 23:42:57 +02:00
connStr := getDatabaseUrl()
schemaName := fmt.Sprintf("terraform_%s", t.Name())
dbCleaner, err := sql.Open("postgres", connStr)
if err != nil {
t.Fatal(err)
}
defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName))
2018-11-14 02:09:43 +01:00
config := backend.TestWrapConfig(map[string]interface{}{
2018-10-10 23:42:57 +02:00
"conn_str": connStr,
"schema_name": schemaName,
2018-11-14 02:09:43 +01:00
})
2018-10-10 23:42:57 +02:00
b1 := backend.TestBackendConfig(t, New(), config).(*Backend)
s1, err := b1.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatal(err)
}
b2 := backend.TestBackendConfig(t, New(), config).(*Backend)
s2, err := b2.StateMgr(backend.DefaultStateName)
2018-10-10 23:42:57 +02:00
if err != nil {
t.Fatal(err)
}
remote.TestRemoteLocks(t, s1.(*remote.State).Client, s2.(*remote.State).Client)
2018-10-10 23:42:57 +02:00
}