stacks: ensure an empty plan produces a planned status

This commit is contained in:
Daniel Schmidt 2026-01-09 11:44:26 +01:00
parent dce80d4465
commit c24699eab7
4 changed files with 95 additions and 0 deletions

View file

@ -983,6 +983,70 @@ func TestStackChangeProgress(t *testing.T) {
},
},
},
"no-op plan": {
mode: stacks.PlanMode_NORMAL,
source: "git::https://example.com/simple.git",
store: stacks_testing_provider.NewResourceStoreBuilder().
AddResource("resource", cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("resource"),
"value": cty.NullVal(cty.String),
})).
Build(),
state: []stackstate.AppliedChange{
&stackstate.AppliedChangeComponentInstance{
ComponentAddr: mustAbsComponent(t, "component.self"),
ComponentInstanceAddr: mustAbsComponentInstance(t, "component.self"),
},
&stackstate.AppliedChangeResourceInstanceObject{
ResourceInstanceObjectAddr: mustAbsResourceInstanceObject(t, "component.self.testing_resource.resource"),
NewStateSrc: &states.ResourceInstanceObjectSrc{
AttrsJSON: mustMarshalJSONAttrs(map[string]interface{}{
"id": "resource",
"value": nil,
}),
Status: states.ObjectReady,
},
ProviderConfigAddr: mustDefaultRootProvider("testing"),
Schema: stacks_testing_provider.TestingResourceSchema,
},
},
want: []*stacks.StackChangeProgress{
{
Event: &stacks.StackChangeProgress_ComponentInstanceStatus_{
ComponentInstanceStatus: &stacks.StackChangeProgress_ComponentInstanceStatus{
Addr: &stacks.ComponentInstanceInStackAddr{
ComponentAddr: "component.self",
ComponentInstanceAddr: "component.self",
},
Status: stacks.StackChangeProgress_ComponentInstanceStatus_PLANNED,
},
},
},
},
},
"empty plan": {
mode: stacks.PlanMode_NORMAL,
source: "git::https://example.com/empty.git",
state: []stackstate.AppliedChange{
&stackstate.AppliedChangeComponentInstance{
ComponentAddr: mustAbsComponent(t, "component.self"),
ComponentInstanceAddr: mustAbsComponentInstance(t, "component.self"),
},
},
want: []*stacks.StackChangeProgress{
{
Event: &stacks.StackChangeProgress_ComponentInstanceStatus_{
ComponentInstanceStatus: &stacks.StackChangeProgress_ComponentInstanceStatus{
Addr: &stacks.ComponentInstanceInStackAddr{
ComponentAddr: "component.self",
ComponentInstanceAddr: "component.self",
},
Status: stacks.StackChangeProgress_ComponentInstanceStatus_PLANNED,
},
},
},
},
},
}
for name, tc := range tcs {

View file

@ -0,0 +1,10 @@
terraform {
required_providers {
testing = {
source = "hashicorp/testing"
version = "0.1.0"
}
}
}
# Empty by design

View file

@ -0,0 +1,16 @@
required_providers {
testing = {
source = "hashicorp/testing"
version = "0.1.0"
}
}
provider "testing" "default" {}
component "self" {
source = "./"
providers = {
testing = provider.testing.default
}
}

View file

@ -40,6 +40,11 @@
"source": "git::https://example.com/simple.git",
"local": "simple",
"meta": {}
},
{
"source": "git::https://example.com/empty.git",
"local": "empty",
"meta": {}
}
]
}