mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
f40800b3a4
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
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(NotDeposed) // 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(NotDeposed)
|
|
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)
|
|
}
|
|
})
|
|
}
|