mirror of
https://github.com/opentofu/opentofu.git
synced 2026-06-11 09:31:23 -04:00
Some checks are pending
build / Build for freebsd_386 (push) Waiting to run
build / Build for linux_386 (push) Waiting to run
build / Build for openbsd_386 (push) Waiting to run
build / Build for windows_386 (push) Waiting to run
build / Build for freebsd_amd64 (push) Waiting to run
build / Build for linux_amd64 (push) Waiting to run
build / Build for openbsd_amd64 (push) Waiting to run
build / Build for solaris_amd64 (push) Waiting to run
build / Build for windows_amd64 (push) Waiting to run
build / Build for freebsd_arm (push) Waiting to run
build / Build for linux_arm (push) Waiting to run
build / Build for linux_arm64 (push) Waiting to run
build / Build for darwin_amd64 (push) Waiting to run
build / Build for darwin_arm64 (push) Waiting to run
build / End-to-end Tests for linux_386 (push) Waiting to run
build / End-to-end Tests for windows_386 (push) Waiting to run
build / End-to-end Tests for darwin_amd64 (push) Waiting to run
build / End-to-end Tests for linux_amd64 (push) Waiting to run
build / End-to-end Tests for windows_amd64 (push) Waiting to run
Quick Checks / List files changed for pull request (push) Waiting to run
Quick Checks / Unit tests for linux_386 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_amd64 (push) Blocked by required conditions
Quick Checks / Unit tests for windows_amd64 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_arm (push) Blocked by required conditions
Quick Checks / Unit tests for darwin_arm64 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_arm64 (push) Blocked by required conditions
Quick Checks / Race Tests (push) Blocked by required conditions
Quick Checks / End-to-end Tests (push) Blocked by required conditions
Quick Checks / Code Consistency Checks (push) Blocked by required conditions
Quick Checks / License Checks (push) Waiting to run
Website checks / List files changed for pull request (push) Waiting to run
Website checks / Build (push) Blocked by required conditions
Website checks / Test Installation Instructions (push) Blocked by required conditions
Signed-off-by: James Humphries <james@james-humphries.co.uk> Signed-off-by: Martin Atkins <mart@degeneration.co.uk> Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
164 lines
3.6 KiB
Go
164 lines
3.6 KiB
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package plans
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/opentofu/opentofu/internal/addrs"
|
|
"github.com/opentofu/opentofu/internal/lang/marks"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
func TestChangesEmpty(t *testing.T) {
|
|
testCases := map[string]struct {
|
|
changes *Changes
|
|
want bool
|
|
}{
|
|
"no changes": {
|
|
&Changes{},
|
|
true,
|
|
},
|
|
"resource change": {
|
|
&Changes{
|
|
Resources: []*ResourceInstanceChangeSrc{
|
|
{
|
|
Addr: addrs.Resource{
|
|
Mode: addrs.ManagedResourceMode,
|
|
Type: "test_thing",
|
|
Name: "woot",
|
|
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
|
PrevRunAddr: addrs.Resource{
|
|
Mode: addrs.ManagedResourceMode,
|
|
Type: "test_thing",
|
|
Name: "woot",
|
|
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
|
ChangeSrc: ChangeSrc{
|
|
Action: Update,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
false,
|
|
},
|
|
"resource change with no-op action": {
|
|
&Changes{
|
|
Resources: []*ResourceInstanceChangeSrc{
|
|
{
|
|
Addr: addrs.Resource{
|
|
Mode: addrs.ManagedResourceMode,
|
|
Type: "test_thing",
|
|
Name: "woot",
|
|
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
|
PrevRunAddr: addrs.Resource{
|
|
Mode: addrs.ManagedResourceMode,
|
|
Type: "test_thing",
|
|
Name: "woot",
|
|
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
|
ChangeSrc: ChangeSrc{
|
|
Action: NoOp,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
true,
|
|
},
|
|
"resource moved with no-op change": {
|
|
&Changes{
|
|
Resources: []*ResourceInstanceChangeSrc{
|
|
{
|
|
Addr: addrs.Resource{
|
|
Mode: addrs.ManagedResourceMode,
|
|
Type: "test_thing",
|
|
Name: "woot",
|
|
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
|
PrevRunAddr: addrs.Resource{
|
|
Mode: addrs.ManagedResourceMode,
|
|
Type: "test_thing",
|
|
Name: "toot",
|
|
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
|
ChangeSrc: ChangeSrc{
|
|
Action: NoOp,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
false,
|
|
},
|
|
"output change": {
|
|
&Changes{
|
|
Outputs: []*OutputChangeSrc{
|
|
{
|
|
Addr: addrs.OutputValue{
|
|
Name: "result",
|
|
}.Absolute(addrs.RootModuleInstance),
|
|
ChangeSrc: ChangeSrc{
|
|
Action: Update,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
false,
|
|
},
|
|
"output change no-op": {
|
|
&Changes{
|
|
Outputs: []*OutputChangeSrc{
|
|
{
|
|
Addr: addrs.OutputValue{
|
|
Name: "result",
|
|
}.Absolute(addrs.RootModuleInstance),
|
|
ChangeSrc: ChangeSrc{
|
|
Action: NoOp,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
true,
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
if got, want := tc.changes.Empty(), tc.want; got != want {
|
|
t.Fatalf("unexpected result: got %v, want %v", got, want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestChangeEncodeSensitive(t *testing.T) {
|
|
testVals := []cty.Value{
|
|
cty.ObjectVal(map[string]cty.Value{
|
|
"ding": cty.StringVal("dong").Mark(marks.Sensitive),
|
|
}),
|
|
cty.StringVal("bleep").Mark("bloop"),
|
|
cty.ListVal([]cty.Value{cty.UnknownVal(cty.String).Mark("sup?")}),
|
|
}
|
|
|
|
for _, v := range testVals {
|
|
t.Run(fmt.Sprintf("%#v", v), func(t *testing.T) {
|
|
change := Change{
|
|
Before: cty.NullVal(v.Type()),
|
|
After: v,
|
|
}
|
|
|
|
encoded, err := change.Encode(nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
decoded, err := encoded.Decode(nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !v.RawEquals(decoded.After) {
|
|
t.Fatalf("%#v != %#v\n", decoded.After, v)
|
|
}
|
|
})
|
|
}
|
|
}
|