Skip to content

Commit 62cb10d

Browse files
add missing assertion
1 parent 0b35407 commit 62cb10d

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

internal/terraform/context_plan_actions_test.go

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,16 @@ resource "test_object" "a" {
893893
t.Fatalf("expected action addresses to be 'action.test_action.hello[\"a\"]' and 'action.test_action.hello[\"b\"]', got %v", actionAddrs)
894894
}
895895

896-
// TODO: Test that action the triggering resource address is set correctly
896+
for _, ai := range p.Changes.ActionInvocations {
897+
at, ok := ai.ActionTrigger.(*plans.LifecycleActionTrigger)
898+
if !ok {
899+
t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", ai.ActionTrigger)
900+
}
901+
902+
if !at.TriggeringResourceAddr.Equal(mustResourceInstanceAddr("test_object.a")) {
903+
t.Fatalf("expected action to have triggering resource address 'test_object.a', but it is %s", at.TriggeringResourceAddr)
904+
}
905+
}
897906
},
898907
},
899908

@@ -938,7 +947,16 @@ resource "test_object" "a" {
938947
t.Fatalf("expected action addresses to be 'action.test_action.hello[0]' and 'action.test_action.hello[1]', got %v", actionAddrs)
939948
}
940949

941-
// TODO: Test that action the triggering resource address is set correctly
950+
for _, ai := range p.Changes.ActionInvocations {
951+
at, ok := ai.ActionTrigger.(*plans.LifecycleActionTrigger)
952+
if !ok {
953+
t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", ai.ActionTrigger)
954+
}
955+
956+
if !at.TriggeringResourceAddr.Equal(mustResourceInstanceAddr("test_object.a")) {
957+
t.Fatalf("expected action to have triggering resource address 'test_object.a', but it is %s", at.TriggeringResourceAddr)
958+
}
959+
}
942960
},
943961
},
944962

@@ -1048,7 +1066,23 @@ resource "test_object" "a" {
10481066
t.Fatalf("expected action addresses to be 'action.test_action.hello' and 'action.test_action.hello', got %v", actionAddrs)
10491067
}
10501068

1051-
// TODO: Test that action the triggering resource address is set correctly
1069+
actionTriggers := []plans.LifecycleActionTrigger{}
1070+
for _, ai := range p.Changes.ActionInvocations {
1071+
at, ok := ai.ActionTrigger.(*plans.LifecycleActionTrigger)
1072+
if !ok {
1073+
t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", ai.ActionTrigger)
1074+
}
1075+
1076+
actionTriggers = append(actionTriggers, *at)
1077+
}
1078+
1079+
if !actionTriggers[0].TriggeringResourceAddr.Resource.Resource.Equal(actionTriggers[1].TriggeringResourceAddr.Resource.Resource) {
1080+
t.Fatalf("expected both actions to have the same triggering resource address, but got %s and %s", actionTriggers[0].TriggeringResourceAddr, actionTriggers[1].TriggeringResourceAddr)
1081+
}
1082+
1083+
if actionTriggers[0].TriggeringResourceAddr.Resource.Key == actionTriggers[1].TriggeringResourceAddr.Resource.Key {
1084+
t.Fatalf("expected both actions to have different triggering resource instance keys, but got the same %s", actionTriggers[0].TriggeringResourceAddr.Resource.Key)
1085+
}
10521086
},
10531087
},
10541088
"expanded resource - expanded action": {
@@ -1093,7 +1127,23 @@ resource "test_object" "a" {
10931127
t.Fatalf("expected action addresses to be 'action.test_action.hello[0]' and 'action.test_action.hello[1]', got %v", actionAddrs)
10941128
}
10951129

1096-
// TODO: Test that action the triggering resource address is set correctly
1130+
actionTriggers := []plans.LifecycleActionTrigger{}
1131+
for _, ai := range p.Changes.ActionInvocations {
1132+
at, ok := ai.ActionTrigger.(*plans.LifecycleActionTrigger)
1133+
if !ok {
1134+
t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", ai.ActionTrigger)
1135+
}
1136+
1137+
actionTriggers = append(actionTriggers, *at)
1138+
}
1139+
1140+
if !actionTriggers[0].TriggeringResourceAddr.Resource.Resource.Equal(actionTriggers[1].TriggeringResourceAddr.Resource.Resource) {
1141+
t.Fatalf("expected both actions to have the same triggering resource address, but got %s and %s", actionTriggers[0].TriggeringResourceAddr, actionTriggers[1].TriggeringResourceAddr)
1142+
}
1143+
1144+
if actionTriggers[0].TriggeringResourceAddr.Resource.Key == actionTriggers[1].TriggeringResourceAddr.Resource.Key {
1145+
t.Fatalf("expected both actions to have different triggering resource instance keys, but got the same %s", actionTriggers[0].TriggeringResourceAddr.Resource.Key)
1146+
}
10971147
},
10981148
},
10991149

0 commit comments

Comments
 (0)