2017-10-09 13:46:54 +02:00
|
|
|
package manta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2021-05-17 17:42:17 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/backend"
|
2021-05-17 21:43:35 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/states/remote"
|
2017-10-09 13:46:54 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRemoteClient_impl(t *testing.T) {
|
|
|
|
var _ remote.Client = new(RemoteClient)
|
|
|
|
var _ remote.ClientLocker = new(RemoteClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoteClient(t *testing.T) {
|
|
|
|
testACC(t)
|
|
|
|
directory := fmt.Sprintf("terraform-remote-manta-test-%x", time.Now().Unix())
|
|
|
|
keyName := "testState"
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
b := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
|
2018-10-31 16:45:03 +01:00
|
|
|
"path": directory,
|
|
|
|
"object_name": keyName,
|
2018-03-21 02:43:02 +01:00
|
|
|
})).(*Backend)
|
2017-10-09 13:46:54 +02:00
|
|
|
|
|
|
|
createMantaFolder(t, b.storageClient, directory)
|
|
|
|
defer deleteMantaFolder(t, b.storageClient, directory)
|
|
|
|
|
2018-10-01 23:35:23 +02:00
|
|
|
state, err := b.StateMgr(backend.DefaultStateName)
|
2017-10-09 13:46:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
remote.TestClient(t, state.(*remote.State).Client)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoteClientLocks(t *testing.T) {
|
|
|
|
testACC(t)
|
|
|
|
directory := fmt.Sprintf("terraform-remote-manta-test-%x", time.Now().Unix())
|
|
|
|
keyName := "testState"
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
b1 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
|
2018-10-31 16:45:03 +01:00
|
|
|
"path": directory,
|
|
|
|
"object_name": keyName,
|
2018-03-21 02:43:02 +01:00
|
|
|
})).(*Backend)
|
2017-10-09 13:46:54 +02:00
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
b2 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
|
2018-10-31 16:45:03 +01:00
|
|
|
"path": directory,
|
|
|
|
"object_name": keyName,
|
2018-03-21 02:43:02 +01:00
|
|
|
})).(*Backend)
|
2017-10-09 13:46:54 +02:00
|
|
|
|
|
|
|
createMantaFolder(t, b1.storageClient, directory)
|
|
|
|
defer deleteMantaFolder(t, b1.storageClient, directory)
|
|
|
|
|
2018-10-01 23:35:23 +02:00
|
|
|
s1, err := b1.StateMgr(backend.DefaultStateName)
|
2017-10-09 13:46:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-10-01 23:35:23 +02:00
|
|
|
s2, err := b2.StateMgr(backend.DefaultStateName)
|
2017-10-09 13:46:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
remote.TestRemoteLocks(t, s1.(*remote.State).Client, s2.(*remote.State).Client)
|
|
|
|
}
|