2017-01-19 05:47:56 +01:00
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
2017-02-27 22:43:31 +01:00
|
|
|
"errors"
|
2017-02-22 01:07:27 +01:00
|
|
|
"io/ioutil"
|
2017-01-19 05:47:56 +01:00
|
|
|
"os"
|
2017-03-01 01:18:16 +01:00
|
|
|
"path/filepath"
|
2017-02-22 01:07:27 +01:00
|
|
|
"reflect"
|
2017-01-19 05:47:56 +01:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/backend"
|
2018-09-28 23:04:57 +02:00
|
|
|
"github.com/hashicorp/terraform/states/statefile"
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
"github.com/hashicorp/terraform/states/statemgr"
|
2017-01-19 05:47:56 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLocal_impl(t *testing.T) {
|
2018-10-31 16:45:03 +01:00
|
|
|
var _ backend.Enhanced = New()
|
|
|
|
var _ backend.Local = New()
|
|
|
|
var _ backend.CLI = New()
|
2017-01-19 05:47:56 +01:00
|
|
|
}
|
|
|
|
|
2017-03-09 11:47:21 +01:00
|
|
|
func TestLocal_backend(t *testing.T) {
|
2017-03-23 16:14:13 +01:00
|
|
|
defer testTmpDir(t)()
|
2018-10-31 16:45:03 +01:00
|
|
|
b := New()
|
2018-02-21 04:09:54 +01:00
|
|
|
backend.TestBackendStates(t, b)
|
|
|
|
backend.TestBackendStateLocks(t, b, b)
|
2017-03-09 11:47:21 +01:00
|
|
|
}
|
|
|
|
|
2017-01-19 05:47:56 +01:00
|
|
|
func checkState(t *testing.T, path, expected string) {
|
2017-11-08 03:23:08 +01:00
|
|
|
t.Helper()
|
2017-01-19 05:47:56 +01:00
|
|
|
// Read the state
|
|
|
|
f, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-09-28 23:04:57 +02:00
|
|
|
state, err := statefile.Read(f)
|
2017-01-19 05:47:56 +01:00
|
|
|
f.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-09-28 23:04:57 +02:00
|
|
|
actual := state.State.String()
|
2017-01-19 05:47:56 +01:00
|
|
|
expected = strings.TrimSpace(expected)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("state does not match! actual:\n%s\n\nexpected:\n%s", actual, expected)
|
|
|
|
}
|
|
|
|
}
|
2017-02-22 01:07:27 +01:00
|
|
|
|
2017-03-01 01:18:16 +01:00
|
|
|
func TestLocal_StatePaths(t *testing.T) {
|
2018-10-31 16:45:03 +01:00
|
|
|
b := New()
|
2017-03-01 01:18:16 +01:00
|
|
|
|
|
|
|
// Test the defaults
|
|
|
|
path, out, back := b.StatePaths("")
|
|
|
|
|
|
|
|
if path != DefaultStateFilename {
|
|
|
|
t.Fatalf("expected %q, got %q", DefaultStateFilename, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
if out != DefaultStateFilename {
|
|
|
|
t.Fatalf("expected %q, got %q", DefaultStateFilename, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
dfltBackup := DefaultStateFilename + DefaultBackupExtension
|
|
|
|
if back != dfltBackup {
|
|
|
|
t.Fatalf("expected %q, got %q", dfltBackup, back)
|
|
|
|
}
|
|
|
|
|
|
|
|
// check with env
|
|
|
|
testEnv := "test_env"
|
|
|
|
path, out, back = b.StatePaths(testEnv)
|
|
|
|
|
2017-05-31 02:13:43 +02:00
|
|
|
expectedPath := filepath.Join(DefaultWorkspaceDir, testEnv, DefaultStateFilename)
|
2017-03-01 01:18:16 +01:00
|
|
|
expectedOut := expectedPath
|
|
|
|
expectedBackup := expectedPath + DefaultBackupExtension
|
|
|
|
|
|
|
|
if path != expectedPath {
|
|
|
|
t.Fatalf("expected %q, got %q", expectedPath, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
if out != expectedOut {
|
|
|
|
t.Fatalf("expected %q, got %q", expectedOut, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
if back != expectedBackup {
|
|
|
|
t.Fatalf("expected %q, got %q", expectedBackup, back)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-22 01:07:27 +01:00
|
|
|
func TestLocal_addAndRemoveStates(t *testing.T) {
|
|
|
|
defer testTmpDir(t)()
|
|
|
|
dflt := backend.DefaultStateName
|
|
|
|
expectedStates := []string{dflt}
|
|
|
|
|
2018-10-31 16:45:03 +01:00
|
|
|
b := New()
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
states, err := b.Workspaces()
|
2017-02-22 01:07:27 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(states, expectedStates) {
|
2017-02-22 20:53:43 +01:00
|
|
|
t.Fatalf("expected []string{%q}, got %q", dflt, states)
|
2017-02-22 01:07:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedA := "test_A"
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
if _, err := b.StateMgr(expectedA); err != nil {
|
2017-02-22 01:07:27 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
states, err = b.Workspaces()
|
2017-02-22 20:53:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-02-22 01:07:27 +01:00
|
|
|
|
|
|
|
expectedStates = append(expectedStates, expectedA)
|
|
|
|
if !reflect.DeepEqual(states, expectedStates) {
|
|
|
|
t.Fatalf("expected %q, got %q", expectedStates, states)
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedB := "test_B"
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
if _, err := b.StateMgr(expectedB); err != nil {
|
2017-02-22 01:07:27 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
states, err = b.Workspaces()
|
2017-02-22 20:53:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-02-22 01:07:27 +01:00
|
|
|
|
|
|
|
expectedStates = append(expectedStates, expectedB)
|
|
|
|
if !reflect.DeepEqual(states, expectedStates) {
|
|
|
|
t.Fatalf("expected %q, got %q", expectedStates, states)
|
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
if err := b.DeleteWorkspace(expectedA); err != nil {
|
2017-02-22 01:07:27 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
states, err = b.Workspaces()
|
2017-02-22 20:53:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-02-22 01:07:27 +01:00
|
|
|
|
|
|
|
expectedStates = []string{dflt, expectedB}
|
|
|
|
if !reflect.DeepEqual(states, expectedStates) {
|
|
|
|
t.Fatalf("expected %q, got %q", expectedStates, states)
|
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
if err := b.DeleteWorkspace(expectedB); err != nil {
|
2017-02-22 01:07:27 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
states, err = b.Workspaces()
|
2017-02-22 20:53:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-02-22 01:07:27 +01:00
|
|
|
|
|
|
|
expectedStates = []string{dflt}
|
|
|
|
if !reflect.DeepEqual(states, expectedStates) {
|
|
|
|
t.Fatalf("expected %q, got %q", expectedStates, states)
|
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
if err := b.DeleteWorkspace(dflt); err == nil {
|
2017-02-22 01:07:27 +01:00
|
|
|
t.Fatal("expected error deleting default state")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-01 01:18:16 +01:00
|
|
|
// a local backend which returns sentinel errors for NamedState methods to
|
2017-02-27 22:43:31 +01:00
|
|
|
// verify it's being called.
|
|
|
|
type testDelegateBackend struct {
|
|
|
|
*Local
|
2017-04-22 00:57:39 +02:00
|
|
|
|
|
|
|
// return a sentinel error on these calls
|
|
|
|
stateErr bool
|
|
|
|
statesErr bool
|
|
|
|
deleteErr bool
|
2017-02-27 22:43:31 +01:00
|
|
|
}
|
2017-02-22 20:53:43 +01:00
|
|
|
|
2017-02-27 22:43:31 +01:00
|
|
|
var errTestDelegateState = errors.New("State called")
|
|
|
|
var errTestDelegateStates = errors.New("States called")
|
|
|
|
var errTestDelegateDeleteState = errors.New("Delete called")
|
2017-02-22 20:53:43 +01:00
|
|
|
|
2018-09-27 00:33:02 +02:00
|
|
|
func (b *testDelegateBackend) StateMgr(name string) (statemgr.Full, error) {
|
2017-04-22 00:57:39 +02:00
|
|
|
if b.stateErr {
|
|
|
|
return nil, errTestDelegateState
|
|
|
|
}
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
s := statemgr.NewFilesystem("terraform.tfstate")
|
2017-04-22 00:57:39 +02:00
|
|
|
return s, nil
|
2017-02-27 22:43:31 +01:00
|
|
|
}
|
2017-02-22 20:53:43 +01:00
|
|
|
|
2018-09-27 00:33:02 +02:00
|
|
|
func (b *testDelegateBackend) Workspaces() ([]string, error) {
|
2017-04-22 00:57:39 +02:00
|
|
|
if b.statesErr {
|
|
|
|
return nil, errTestDelegateStates
|
|
|
|
}
|
|
|
|
return []string{"default"}, nil
|
2017-02-27 22:43:31 +01:00
|
|
|
}
|
2017-02-22 20:53:43 +01:00
|
|
|
|
2018-09-27 00:33:02 +02:00
|
|
|
func (b *testDelegateBackend) DeleteWorkspace(name string) error {
|
2017-04-22 00:57:39 +02:00
|
|
|
if b.deleteErr {
|
|
|
|
return errTestDelegateDeleteState
|
|
|
|
}
|
|
|
|
return nil
|
2017-02-22 20:53:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// verify that the MultiState methods are dispatched to the correct Backend.
|
|
|
|
func TestLocal_multiStateBackend(t *testing.T) {
|
2017-02-27 22:43:31 +01:00
|
|
|
// assign a separate backend where we can read the state
|
2018-10-31 16:45:03 +01:00
|
|
|
b := NewWithBackend(&testDelegateBackend{
|
|
|
|
stateErr: true,
|
|
|
|
statesErr: true,
|
|
|
|
deleteErr: true,
|
|
|
|
})
|
2017-02-22 20:53:43 +01:00
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
if _, err := b.StateMgr("test"); err != errTestDelegateState {
|
2017-02-27 22:43:31 +01:00
|
|
|
t.Fatal("expected errTestDelegateState, got:", err)
|
2017-02-22 20:53:43 +01:00
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
if _, err := b.Workspaces(); err != errTestDelegateStates {
|
2017-02-27 22:43:31 +01:00
|
|
|
t.Fatal("expected errTestDelegateStates, got:", err)
|
2017-02-22 20:53:43 +01:00
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
if err := b.DeleteWorkspace("test"); err != errTestDelegateDeleteState {
|
2017-02-27 22:43:31 +01:00
|
|
|
t.Fatal("expected errTestDelegateDeleteState, got:", err)
|
2017-02-22 20:53:43 +01:00
|
|
|
}
|
2017-04-22 00:57:39 +02:00
|
|
|
}
|
|
|
|
|
2017-02-22 01:07:27 +01:00
|
|
|
// change into a tmp dir and return a deferable func to change back and cleanup
|
|
|
|
func testTmpDir(t *testing.T) func() {
|
|
|
|
tmp, err := ioutil.TempDir("", "tf")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
old, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.Chdir(tmp); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return func() {
|
|
|
|
// ignore errors and try to clean up
|
|
|
|
os.Chdir(old)
|
|
|
|
os.RemoveAll(tmp)
|
|
|
|
}
|
|
|
|
}
|