2017-01-19 05:47:18 +01:00
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
2017-03-02 07:58:51 +01:00
|
|
|
"reflect"
|
|
|
|
"sort"
|
2017-01-19 05:47:18 +01:00
|
|
|
"testing"
|
|
|
|
|
2018-02-21 02:32:07 +01:00
|
|
|
uuid "github.com/hashicorp/go-uuid"
|
2019-09-10 00:58:44 +02:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
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/addrs"
|
|
|
|
"github.com/hashicorp/terraform/configs"
|
2019-08-07 01:58:58 +02:00
|
|
|
"github.com/hashicorp/terraform/configs/hcl2shim"
|
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"
|
|
|
|
"github.com/hashicorp/terraform/states/statemgr"
|
|
|
|
"github.com/hashicorp/terraform/tfdiags"
|
2017-01-19 05:47:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestBackendConfig validates and configures the backend with the
|
|
|
|
// given configuration.
|
2018-03-21 02:43:02 +01:00
|
|
|
func TestBackendConfig(t *testing.T, b Backend, c hcl.Body) Backend {
|
2017-08-26 01:23:47 +02:00
|
|
|
t.Helper()
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
t.Logf("TestBackendConfig on %T with %#v", b, c)
|
2017-01-19 05:47:18 +01:00
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
var diags tfdiags.Diagnostics
|
|
|
|
|
2018-10-03 00:12:06 +02:00
|
|
|
// To make things easier for test authors, we'll allow a nil body here
|
|
|
|
// (even though that's not normally valid) and just treat it as an empty
|
|
|
|
// body.
|
|
|
|
if c == nil {
|
|
|
|
c = hcl.EmptyBody()
|
|
|
|
}
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
schema := b.ConfigSchema()
|
|
|
|
spec := schema.DecoderSpec()
|
|
|
|
obj, decDiags := hcldec.Decode(c, spec, nil)
|
|
|
|
diags = diags.Append(decDiags)
|
|
|
|
|
2019-02-26 00:37:20 +01:00
|
|
|
newObj, valDiags := b.PrepareConfig(obj)
|
2021-04-02 23:11:20 +02:00
|
|
|
diags = diags.Append(valDiags.InConfigBody(c, ""))
|
2018-03-21 02:43:02 +01:00
|
|
|
|
|
|
|
if len(diags) != 0 {
|
2018-10-31 16:45:03 +01:00
|
|
|
t.Fatal(diags.ErrWithWarnings())
|
2017-01-19 05:47:18 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 00:37:20 +01:00
|
|
|
obj = newObj
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
confDiags := b.Configure(obj)
|
|
|
|
if len(confDiags) != 0 {
|
2021-04-02 23:11:20 +02:00
|
|
|
confDiags = confDiags.InConfigBody(c, "")
|
2018-10-31 16:45:03 +01:00
|
|
|
t.Fatal(confDiags.ErrWithWarnings())
|
2017-01-19 05:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return b
|
|
|
|
}
|
2017-03-02 07:58:51 +01:00
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
// TestWrapConfig takes a raw data structure and converts it into a
|
|
|
|
// synthetic hcl.Body to use for testing.
|
|
|
|
//
|
|
|
|
// The given structure should only include values that can be accepted by
|
|
|
|
// hcl2shim.HCL2ValueFromConfigValue. If incompatible values are given,
|
|
|
|
// this function will panic.
|
|
|
|
func TestWrapConfig(raw map[string]interface{}) hcl.Body {
|
|
|
|
obj := hcl2shim.HCL2ValueFromConfigValue(raw)
|
|
|
|
return configs.SynthBody("<TestWrapConfig>", obj.AsValueMap())
|
|
|
|
}
|
|
|
|
|
2017-03-02 07:58:51 +01:00
|
|
|
// TestBackend will test the functionality of a Backend. The backend is
|
|
|
|
// assumed to already be configured. This will test state functionality.
|
|
|
|
// If the backend reports it doesn't support multi-state by returning the
|
2018-10-31 16:45:03 +01:00
|
|
|
// error ErrWorkspacesNotSupported, then it will not test that.
|
2018-02-21 02:32:07 +01:00
|
|
|
func TestBackendStates(t *testing.T, b Backend) {
|
2017-08-26 01:23:47 +02:00
|
|
|
t.Helper()
|
|
|
|
|
2018-10-31 16:45:03 +01:00
|
|
|
noDefault := false
|
|
|
|
if _, err := b.StateMgr(DefaultStateName); err != nil {
|
|
|
|
if err == ErrDefaultWorkspaceNotSupported {
|
|
|
|
noDefault = true
|
|
|
|
} else {
|
|
|
|
t.Fatalf("error: %v", 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
|
|
|
workspaces, err := b.Workspaces()
|
2018-10-31 16:45:03 +01:00
|
|
|
if err != nil {
|
|
|
|
if err == ErrWorkspacesNotSupported {
|
|
|
|
t.Logf("TestBackend: workspaces not supported in %T, skipping", b)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Fatalf("error: %v", err)
|
2017-03-02 07:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test it starts with only the default
|
2018-10-31 16:45:03 +01:00
|
|
|
if !noDefault && (len(workspaces) != 1 || workspaces[0] != DefaultStateName) {
|
2020-09-29 23:18:34 +02:00
|
|
|
t.Fatalf("should only have the default workspace to start: %#v", workspaces)
|
2017-03-02 07:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a couple 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
|
|
|
foo, err := b.StateMgr("foo")
|
2017-03-02 07:58:51 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %s", err)
|
|
|
|
}
|
2017-03-23 14:47:36 +01:00
|
|
|
if err := foo.RefreshState(); err != nil {
|
2017-03-02 07:58:51 +01:00
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
2017-03-23 14:47:36 +01:00
|
|
|
if v := foo.State(); v.HasResources() {
|
2017-03-02 07:58:51 +01:00
|
|
|
t.Fatalf("should be empty: %s", v)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
bar, err := b.StateMgr("bar")
|
2017-03-02 07:58:51 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %s", err)
|
|
|
|
}
|
2017-03-23 14:47:36 +01:00
|
|
|
if err := bar.RefreshState(); err != nil {
|
2017-03-02 07:58:51 +01:00
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
2017-03-23 14:47:36 +01:00
|
|
|
if v := bar.State(); v.HasResources() {
|
2017-03-02 07:58:51 +01:00
|
|
|
t.Fatalf("should be empty: %s", v)
|
|
|
|
}
|
|
|
|
|
2017-03-23 14:47:36 +01:00
|
|
|
// Verify they are distinct states that can be read back from storage
|
2017-03-02 07:58:51 +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
|
|
|
// We'll use two distinct states here and verify that changing one
|
|
|
|
// does not also change the other.
|
|
|
|
fooState := states.NewState()
|
2018-10-31 16:45:03 +01:00
|
|
|
barState := states.NewState()
|
2017-03-23 14:47:36 +01:00
|
|
|
|
|
|
|
// write a known state to foo
|
|
|
|
if err := foo.WriteState(fooState); err != nil {
|
|
|
|
t.Fatal("error writing foo state:", err)
|
|
|
|
}
|
|
|
|
if err := foo.PersistState(); err != nil {
|
|
|
|
t.Fatal("error persisting foo state:", err)
|
2017-03-09 11:47:21 +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
|
|
|
// We'll make "bar" different by adding a fake resource state to it.
|
|
|
|
barState.SyncWrapper().SetResourceInstanceCurrent(
|
|
|
|
addrs.ResourceInstance{
|
|
|
|
Resource: addrs.Resource{
|
|
|
|
Mode: addrs.ManagedResourceMode,
|
|
|
|
Type: "test_thing",
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
}.Absolute(addrs.RootModuleInstance),
|
|
|
|
&states.ResourceInstanceObjectSrc{
|
|
|
|
AttrsJSON: []byte("{}"),
|
|
|
|
Status: states.ObjectReady,
|
|
|
|
SchemaVersion: 0,
|
|
|
|
},
|
2020-02-13 21:32:58 +01:00
|
|
|
addrs.AbsProviderConfig{
|
2020-10-05 14:33:49 +02:00
|
|
|
Provider: addrs.NewDefaultProvider("test"),
|
2020-03-11 19:19:52 +01:00
|
|
|
Module: addrs.RootModule,
|
2020-02-13 21:32:58 +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
|
|
|
)
|
|
|
|
|
2017-03-23 14:47:36 +01:00
|
|
|
// write a distinct known state to bar
|
|
|
|
if err := bar.WriteState(barState); err != nil {
|
2017-03-02 07:58:51 +01:00
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
2017-03-23 14:47:36 +01:00
|
|
|
if err := bar.PersistState(); err != nil {
|
2017-03-02 07:58:51 +01:00
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
|
|
|
|
2017-03-23 14:47:36 +01:00
|
|
|
// verify that foo is unchanged with the existing state manager
|
|
|
|
if err := foo.RefreshState(); err != nil {
|
|
|
|
t.Fatal("error refreshing foo:", err)
|
|
|
|
}
|
|
|
|
fooState = foo.State()
|
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 fooState.HasResources() {
|
|
|
|
t.Fatal("after writing a resource to bar, foo now has resources too")
|
2017-03-23 14:47:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// fetch foo again from the backend
|
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
|
|
|
foo, err = b.StateMgr("foo")
|
2017-03-23 14:47:36 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("error re-fetching state:", err)
|
|
|
|
}
|
|
|
|
if err := foo.RefreshState(); err != nil {
|
|
|
|
t.Fatal("error refreshing foo:", err)
|
2017-03-02 07:58:51 +01:00
|
|
|
}
|
2017-03-23 14:47:36 +01:00
|
|
|
fooState = foo.State()
|
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 fooState.HasResources() {
|
|
|
|
t.Fatal("after writing a resource to bar and re-reading foo, foo now has resources too")
|
2017-03-23 14:47:36 +01:00
|
|
|
}
|
|
|
|
|
2018-10-31 16:45:03 +01:00
|
|
|
// fetch the bar again from the backend
|
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
|
|
|
bar, err = b.StateMgr("bar")
|
2017-03-23 14:47:36 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("error re-fetching state:", err)
|
|
|
|
}
|
|
|
|
if err := bar.RefreshState(); err != nil {
|
|
|
|
t.Fatal("error refreshing bar:", err)
|
|
|
|
}
|
|
|
|
barState = bar.State()
|
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 !barState.HasResources() {
|
|
|
|
t.Fatal("after writing a resource instance object to bar and re-reading it, the object has vanished")
|
2017-03-02 07:58:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify we can now list them
|
|
|
|
{
|
2017-03-23 14:47:36 +01:00
|
|
|
// we determined that named stated are supported earlier
|
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
|
|
|
workspaces, err := b.Workspaces()
|
2017-03-23 14:47:36 +01:00
|
|
|
if err != nil {
|
2018-10-31 16:45:03 +01:00
|
|
|
t.Fatalf("err: %s", err)
|
2017-03-02 07:58:51 +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
|
|
|
sort.Strings(workspaces)
|
2017-03-02 07:58:51 +01:00
|
|
|
expected := []string{"bar", "default", "foo"}
|
2018-10-31 16:45:03 +01:00
|
|
|
if noDefault {
|
|
|
|
expected = []string{"bar", "foo"}
|
|
|
|
}
|
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 !reflect.DeepEqual(workspaces, expected) {
|
|
|
|
t.Fatalf("wrong workspaces list\ngot: %#v\nwant: %#v", workspaces, expected)
|
2017-03-02 07:58:51 +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
|
|
|
// Delete some workspaces
|
|
|
|
if err := b.DeleteWorkspace("foo"); err != nil {
|
2017-03-02 07:58:51 +01:00
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify the default state can't be deleted
|
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(DefaultStateName); err == nil {
|
2017-03-02 07:58:51 +01:00
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Create and delete the foo workspace again.
|
2017-06-23 16:13:03 +02:00
|
|
|
// Make sure that there are no leftover artifacts from a deleted state
|
|
|
|
// preventing re-creation.
|
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
|
|
|
foo, err = b.StateMgr("foo")
|
2017-06-23 16:13:03 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %s", err)
|
|
|
|
}
|
|
|
|
if err := foo.RefreshState(); err != nil {
|
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
|
|
|
if v := foo.State(); v.HasResources() {
|
|
|
|
t.Fatalf("should be empty: %s", v)
|
|
|
|
}
|
|
|
|
// and delete it again
|
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("foo"); err != nil {
|
2017-06-23 16:13:03 +02:00
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2017-03-02 07:58:51 +01:00
|
|
|
// Verify deletion
|
|
|
|
{
|
2018-10-31 16:45:03 +01:00
|
|
|
workspaces, err := b.Workspaces()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2017-03-02 07:58:51 +01:00
|
|
|
}
|
|
|
|
|
2018-10-31 16:45:03 +01:00
|
|
|
sort.Strings(workspaces)
|
2017-03-02 07:58:51 +01:00
|
|
|
expected := []string{"bar", "default"}
|
2018-10-31 16:45:03 +01:00
|
|
|
if noDefault {
|
|
|
|
expected = []string{"bar"}
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(workspaces, expected) {
|
|
|
|
t.Fatalf("wrong workspaces list\ngot: %#v\nwant: %#v", workspaces, expected)
|
2017-03-02 07:58:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-15 01:28:42 +01:00
|
|
|
|
2018-02-21 02:32:07 +01:00
|
|
|
// TestBackendStateLocks will test the locking functionality of the remote
|
|
|
|
// state backend.
|
|
|
|
func TestBackendStateLocks(t *testing.T, b1, b2 Backend) {
|
|
|
|
t.Helper()
|
|
|
|
testLocks(t, b1, b2, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestBackendStateForceUnlock verifies that the lock error is the expected
|
|
|
|
// type, and the lock can be unlocked using the ID reported in the error.
|
|
|
|
// Remote state backends that support -force-unlock should call this in at
|
|
|
|
// least one of the acceptance tests.
|
|
|
|
func TestBackendStateForceUnlock(t *testing.T, b1, b2 Backend) {
|
|
|
|
t.Helper()
|
|
|
|
testLocks(t, b1, b2, true)
|
|
|
|
}
|
|
|
|
|
2020-10-13 17:18:54 +02:00
|
|
|
// TestBackendStateLocksInWS will test the locking functionality of the remote
|
|
|
|
// state backend.
|
|
|
|
func TestBackendStateLocksInWS(t *testing.T, b1, b2 Backend, ws string) {
|
|
|
|
t.Helper()
|
|
|
|
testLocksInWorkspace(t, b1, b2, false, ws)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestBackendStateForceUnlockInWS verifies that the lock error is the expected
|
|
|
|
// type, and the lock can be unlocked using the ID reported in the error.
|
|
|
|
// Remote state backends that support -force-unlock should call this in at
|
|
|
|
// least one of the acceptance tests.
|
|
|
|
func TestBackendStateForceUnlockInWS(t *testing.T, b1, b2 Backend, ws string) {
|
|
|
|
t.Helper()
|
|
|
|
testLocksInWorkspace(t, b1, b2, true, ws)
|
|
|
|
}
|
|
|
|
|
2018-02-21 02:32:07 +01:00
|
|
|
func testLocks(t *testing.T, b1, b2 Backend, testForceUnlock bool) {
|
2020-10-13 17:18:54 +02:00
|
|
|
testLocksInWorkspace(t, b1, b2, testForceUnlock, DefaultStateName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testLocksInWorkspace(t *testing.T, b1, b2 Backend, testForceUnlock bool, workspace string) {
|
2017-08-26 01:23:47 +02:00
|
|
|
t.Helper()
|
|
|
|
|
2017-03-15 01:28:42 +01:00
|
|
|
// Get the default state for each
|
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
|
|
|
b1StateMgr, err := b1.StateMgr(DefaultStateName)
|
2017-03-15 01:28:42 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %s", err)
|
|
|
|
}
|
|
|
|
if err := b1StateMgr.RefreshState(); err != nil {
|
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fast exit if this doesn't support locking at all
|
2020-08-11 17:43:01 +02:00
|
|
|
if _, ok := b1StateMgr.(statemgr.Locker); !ok {
|
2017-03-15 01:28:42 +01:00
|
|
|
t.Logf("TestBackend: backend %T doesn't support state locking, not testing", b1)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("TestBackend: testing state locking for %T", b1)
|
|
|
|
|
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
|
|
|
b2StateMgr, err := b2.StateMgr(DefaultStateName)
|
2017-03-15 01:28:42 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error: %s", err)
|
|
|
|
}
|
|
|
|
if err := b2StateMgr.RefreshState(); err != nil {
|
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reassign so its obvious whats happening
|
2020-08-11 17:43:01 +02:00
|
|
|
lockerA := b1StateMgr.(statemgr.Locker)
|
|
|
|
lockerB := b2StateMgr.(statemgr.Locker)
|
2017-03-15 01:28:42 +01:00
|
|
|
|
2020-08-11 17:43:01 +02:00
|
|
|
infoA := statemgr.NewLockInfo()
|
2017-03-15 01:28:42 +01:00
|
|
|
infoA.Operation = "test"
|
|
|
|
infoA.Who = "clientA"
|
|
|
|
|
2020-08-11 17:43:01 +02:00
|
|
|
infoB := statemgr.NewLockInfo()
|
2017-03-15 01:28:42 +01:00
|
|
|
infoB.Operation = "test"
|
|
|
|
infoB.Who = "clientB"
|
|
|
|
|
|
|
|
lockIDA, err := lockerA.Lock(infoA)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("unable to get initial lock:", err)
|
|
|
|
}
|
|
|
|
|
2020-08-11 17:43:01 +02:00
|
|
|
// Make sure we can still get the statemgr.Full from another instance even
|
2017-12-06 23:15:23 +01:00
|
|
|
// when locked. This should only happen when a state is loaded via the
|
|
|
|
// backend, and as a remote state.
|
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
|
|
|
_, err = b2.StateMgr(DefaultStateName)
|
2017-12-06 23:15:23 +01:00
|
|
|
if err != nil {
|
2018-02-21 02:32:07 +01:00
|
|
|
t.Errorf("failed to read locked state from another backend instance: %s", err)
|
2017-12-06 23:15:23 +01:00
|
|
|
}
|
|
|
|
|
2017-03-15 01:28:42 +01:00
|
|
|
// If the lock ID is blank, assume locking is disabled
|
|
|
|
if lockIDA == "" {
|
|
|
|
t.Logf("TestBackend: %T: empty string returned for lock, assuming disabled", b1)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = lockerB.Lock(infoB)
|
|
|
|
if err == nil {
|
|
|
|
lockerA.Unlock(lockIDA)
|
|
|
|
t.Fatal("client B obtained lock while held by client A")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := lockerA.Unlock(lockIDA); err != nil {
|
|
|
|
t.Fatal("error unlocking client A", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
lockIDB, err := lockerB.Lock(infoB)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("unable to obtain lock from client B")
|
|
|
|
}
|
|
|
|
|
|
|
|
if lockIDB == lockIDA {
|
2018-02-21 02:32:07 +01:00
|
|
|
t.Errorf("duplicate lock IDs: %q", lockIDB)
|
2017-03-15 01:28:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err = lockerB.Unlock(lockIDB); err != nil {
|
|
|
|
t.Fatal("error unlocking client B:", err)
|
|
|
|
}
|
|
|
|
|
2018-02-21 02:32:07 +01:00
|
|
|
// test the equivalent of -force-unlock, by using the id from the error
|
|
|
|
// output.
|
|
|
|
if !testForceUnlock {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// get a new ID
|
|
|
|
infoA.ID, err = uuid.GenerateUUID()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
lockIDA, err = lockerA.Lock(infoA)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("unable to get re lock A:", err)
|
|
|
|
}
|
|
|
|
unlock := func() {
|
|
|
|
err := lockerA.Unlock(lockIDA)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = lockerB.Lock(infoB)
|
|
|
|
if err == nil {
|
|
|
|
unlock()
|
|
|
|
t.Fatal("client B obtained lock while held by client 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
|
|
|
infoErr, ok := err.(*statemgr.LockError)
|
2018-02-21 02:32:07 +01:00
|
|
|
if !ok {
|
|
|
|
unlock()
|
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
|
|
|
t.Fatalf("expected type *statemgr.LockError, got : %#v", err)
|
2018-02-21 02:32:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// try to unlock with the second unlocker, using the ID from the error
|
|
|
|
if err := lockerB.Unlock(infoErr.Info.ID); err != nil {
|
|
|
|
unlock()
|
|
|
|
t.Fatalf("could not unlock with the reported ID %q: %s", infoErr.Info.ID, err)
|
|
|
|
}
|
2017-03-15 01:28:42 +01:00
|
|
|
}
|