mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-02 12:17:39 -06:00
a3403f2766
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.
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package states
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestResourceInstanceDeposeCurrentObject(t *testing.T) {
|
|
obj := &ResourceInstanceObjectSrc{
|
|
// Empty for the sake of this test, because we're just going to
|
|
// compare by pointer below anyway.
|
|
}
|
|
|
|
is := NewResourceInstance()
|
|
is.Current = obj
|
|
var dk DeposedKey
|
|
|
|
t.Run("first depose", func(t *testing.T) {
|
|
dk = is.deposeCurrentObject() // dk is randomly-generated but should be eight characters long
|
|
t.Logf("deposedKey is %q", dk)
|
|
|
|
if got := is.Current; got != nil {
|
|
t.Errorf("current is %#v; want nil", got)
|
|
}
|
|
if got, want := is.Deposed[dk], obj; got != want {
|
|
t.Errorf("deposed object pointer is %#v; want %#v", got, want)
|
|
}
|
|
if got, want := len(is.Deposed), 1; got != want {
|
|
t.Errorf("wrong len(is.Deposed) %d; want %d", got, want)
|
|
}
|
|
if got, want := len(dk), 8; got != want {
|
|
t.Errorf("wrong len(deposedkey) %d; want %d", got, want)
|
|
}
|
|
})
|
|
|
|
t.Run("second depose", func(t *testing.T) {
|
|
notDK := is.deposeCurrentObject()
|
|
if notDK != NotDeposed {
|
|
t.Errorf("got deposedKey %q; want NotDeposed", notDK)
|
|
}
|
|
|
|
// Make sure we really did abort early, and haven't corrupted the
|
|
// state somehow.
|
|
if got := is.Current; got != nil {
|
|
t.Errorf("current is %#v; want nil", got)
|
|
}
|
|
if got, want := is.Deposed[dk], obj; got != want {
|
|
t.Errorf("deposed object pointer is %#v; want %#v", got, want)
|
|
}
|
|
if got, want := len(is.Deposed), 1; got != want {
|
|
t.Errorf("wrong len(is.Deposed) %d; want %d", got, want)
|
|
}
|
|
if got, want := len(dk), 8; got != want {
|
|
t.Errorf("wrong len(deposedkey) %d; want %d", got, want)
|
|
}
|
|
})
|
|
}
|