export Reset()
This package is used for testing, so there needs to be an easy method for reinitializing the stored data between tests.
This commit is contained in:
parent
ac60ddcd40
commit
5deef9621d
|
@ -17,12 +17,26 @@ import (
|
||||||
// we keep the states and locks in package-level variables, so that they can be
|
// we keep the states and locks in package-level variables, so that they can be
|
||||||
// accessed from multiple instances of the backend. This better emulates
|
// accessed from multiple instances of the backend. This better emulates
|
||||||
// backend instances accessing a single remote data store.
|
// backend instances accessing a single remote data store.
|
||||||
var states = stateMap{
|
var (
|
||||||
m: map[string]*remote.State{},
|
states stateMap
|
||||||
|
locks lockMap
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
var locks = lockMap{
|
// Reset clears out all existing state and lock data.
|
||||||
|
// This is used to initialize the package during init, as well as between
|
||||||
|
// tests.
|
||||||
|
func Reset() {
|
||||||
|
states = stateMap{
|
||||||
|
m: map[string]*remote.State{},
|
||||||
|
}
|
||||||
|
|
||||||
|
locks = lockMap{
|
||||||
m: map[string]*state.LockInfo{},
|
m: map[string]*state.LockInfo{},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new backend for Inmem remote state.
|
// New creates a new backend for Inmem remote state.
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/backend"
|
"github.com/hashicorp/terraform/backend"
|
||||||
"github.com/hashicorp/terraform/state"
|
|
||||||
"github.com/hashicorp/terraform/state/remote"
|
"github.com/hashicorp/terraform/state/remote"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,19 +11,8 @@ func TestBackend_impl(t *testing.T) {
|
||||||
var _ backend.Backend = new(Backend)
|
var _ backend.Backend = new(Backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset the states and locks between tests
|
|
||||||
func reset() {
|
|
||||||
states = stateMap{
|
|
||||||
m: map[string]*remote.State{},
|
|
||||||
}
|
|
||||||
|
|
||||||
locks = lockMap{
|
|
||||||
m: map[string]*state.LockInfo{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBackendConfig(t *testing.T) {
|
func TestBackendConfig(t *testing.T) {
|
||||||
defer reset()
|
defer Reset()
|
||||||
testID := "test_lock_id"
|
testID := "test_lock_id"
|
||||||
|
|
||||||
config := map[string]interface{}{
|
config := map[string]interface{}{
|
||||||
|
@ -49,13 +37,13 @@ func TestBackendConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBackend(t *testing.T) {
|
func TestBackend(t *testing.T) {
|
||||||
defer reset()
|
defer Reset()
|
||||||
b := backend.TestBackendConfig(t, New(), nil).(*Backend)
|
b := backend.TestBackendConfig(t, New(), nil).(*Backend)
|
||||||
backend.TestBackend(t, b, nil)
|
backend.TestBackend(t, b, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBackendLocked(t *testing.T) {
|
func TestBackendLocked(t *testing.T) {
|
||||||
defer reset()
|
defer Reset()
|
||||||
b1 := backend.TestBackendConfig(t, New(), nil).(*Backend)
|
b1 := backend.TestBackendConfig(t, New(), nil).(*Backend)
|
||||||
b2 := backend.TestBackendConfig(t, New(), nil).(*Backend)
|
b2 := backend.TestBackendConfig(t, New(), nil).(*Backend)
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ func TestRemoteClient_impl(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRemoteClient(t *testing.T) {
|
func TestRemoteClient(t *testing.T) {
|
||||||
defer reset()
|
defer Reset()
|
||||||
b := backend.TestBackendConfig(t, New(), nil)
|
b := backend.TestBackendConfig(t, New(), nil)
|
||||||
|
|
||||||
s, err := b.State(backend.DefaultStateName)
|
s, err := b.State(backend.DefaultStateName)
|
||||||
|
@ -25,7 +25,7 @@ func TestRemoteClient(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInmemLocks(t *testing.T) {
|
func TestInmemLocks(t *testing.T) {
|
||||||
defer reset()
|
defer Reset()
|
||||||
s, err := backend.TestBackendConfig(t, New(), nil).State(backend.DefaultStateName)
|
s, err := backend.TestBackendConfig(t, New(), nil).State(backend.DefaultStateName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
Loading…
Reference in New Issue