|
338 | 338 | "Outputs are correct") |
339 | 339 | (ds/signal sys :salmon/delete)))) |
340 | 340 |
|
| 341 | +(deftest test-termination-protection |
| 342 | + (let [{:keys [regions]} (test/get-config) |
| 343 | + stack-name (test/rand-stack-name)] |
| 344 | + (doseq [region regions |
| 345 | + :let [stack-tp (stack-a :lint? true |
| 346 | + :name stack-name |
| 347 | + :region region |
| 348 | + :template template-a |
| 349 | + :termination-protection? true) |
| 350 | + stack-no-tp (stack-a :lint? true |
| 351 | + :name stack-name |
| 352 | + :region region |
| 353 | + :template template-a |
| 354 | + :termination-protection? false) |
| 355 | + stack-tp-unset (stack-a :lint? true |
| 356 | + :name stack-name |
| 357 | + :region region |
| 358 | + :template template-a |
| 359 | + :termination-protection? nil) |
| 360 | + system-def (system-a stack-tp)]] |
| 361 | + (test/with-system-delete [system system-def] |
| 362 | + (testing "termination-protection? prevents deletion" |
| 363 | + (is (thrown-with-msg? |
| 364 | + ExceptionInfo |
| 365 | + #"TerminationProtection is enabled" |
| 366 | + (cause (ds/signal @system :salmon/delete))))) |
| 367 | + (testing "nil termination-protection? leaves existing setting" |
| 368 | + (reset! system (ds/start (system-a stack-tp-unset))) |
| 369 | + (is (thrown-with-msg? |
| 370 | + ExceptionInfo |
| 371 | + #"TerminationProtection is enabled" |
| 372 | + (cause (ds/signal @system :salmon/delete))))) |
| 373 | + (testing "delete works after disabling termination-protection?" |
| 374 | + (reset! system (ds/start (system-a stack-no-tp))) |
| 375 | + (let [stack-id (-> @system ::ds/instances :services :stack-a :stack-id)] |
| 376 | + (reset! system (ds/signal @system :salmon/delete)) |
| 377 | + (is (= {:name stack-name :stack-id stack-id} |
| 378 | + (-> @system ::ds/instances :services :stack-a))))) |
| 379 | + ; Re-create stack with no termination protection |
| 380 | + (reset! system (ds/start (system-a stack-no-tp))) |
| 381 | + (testing "termination-protection? can be enabled for pre-existing stacks" |
| 382 | + (reset! system (ds/start (system-a stack-tp))) |
| 383 | + (is (thrown-with-msg? |
| 384 | + ExceptionInfo |
| 385 | + #"TerminationProtection is enabled" |
| 386 | + (cause (ds/signal @system :salmon/delete))))) |
| 387 | + (testing "termination-protection? can be disabled and enabled again" |
| 388 | + (reset! system (ds/start (system-a stack-no-tp))) |
| 389 | + (reset! system (ds/start (system-a stack-tp))) |
| 390 | + (is (thrown-with-msg? |
| 391 | + ExceptionInfo |
| 392 | + #"TerminationProtection is enabled" |
| 393 | + (cause (ds/signal @system :salmon/delete))))) |
| 394 | + (testing "delete works after disabling termination-protection?" |
| 395 | + (reset! system (ds/start (system-a stack-no-tp))) |
| 396 | + (testing "nil termination-protection? leaves existing setting" |
| 397 | + (reset! system (ds/start (system-a stack-tp-unset))) |
| 398 | + (let [stack-id (-> @system ::ds/instances :services :stack-a :stack-id)] |
| 399 | + (reset! system (ds/signal @system :salmon/delete)) |
| 400 | + (is (= {:name stack-name :stack-id stack-id} |
| 401 | + (-> @system ::ds/instances :services :stack-a)))))))))) |
| 402 | + |
341 | 403 | (deftest test-describe-stack-raw |
342 | 404 | (let [stack-name (test/rand-stack-name) |
343 | 405 | sys (ds/start (system-a (stack-a :capabilities #{"CAPABILITY_NAMED_IAM"} :name stack-name :template template-a)))] |
|
0 commit comments