diff --git a/tests/functional/nix-collect-garbage-d.sh b/tests/functional/nix-collect-garbage-d.sh index 01643e03a..f94c94e7a 100755 --- a/tests/functional/nix-collect-garbage-d.sh +++ b/tests/functional/nix-collect-garbage-d.sh @@ -43,6 +43,10 @@ testCollectGarbageCheckGenerations () { [[ "${actual%" "}" == "${expected}" ]] } +####################### +# nix-collect-garbage # +####################### + # Basic test that should leave 1 generation testCollectGarbageSetup nix-collect-garbage -d @@ -55,6 +59,19 @@ testCollectGarbageSetup nix-collect-garbage -d testCollectGarbageCheckGenerations "6" +# Basic test that should leave 1 generation +rm ~/.nix-profile +testCollectGarbageSetup +nix-collect-garbage --delete-older-than old +testCollectGarbageCheckGenerations "6" + +# Basic test that deletes all but the active +# This will delete future generations! +testCollectGarbageSetup +nix-env --switch-generation 4 +nix-collect-garbage --delete-older-than old +testCollectGarbageCheckGenerations "4" + # Run the same test, but forcing the profiles at their legacy location under # /nix/var/nix. # @@ -73,6 +90,13 @@ testCollectGarbageSetup nix-collect-garbage --delete-older-than "+4" testCollectGarbageCheckGenerations "3 4 5 6" +# Delete all except latest 2 generations +# This will keep future generations +testCollectGarbageSetup +nix-env --switch-generation 5 +nix-collect-garbage --delete-older-than "+2" +testCollectGarbageCheckGenerations "4 5 6" + # Delete everything older than 5 days # All profiles are younger than 5 days testCollectGarbageSetup @@ -107,3 +131,87 @@ testCollectGarbageSetup testCollectGarbageMockTimestamps nix-collect-garbage --delete-older-than "1d" testCollectGarbageCheckGenerations "6" + +# Delete everything older than 2 days +# Profile 4 was active at 2 days ago so it will be kept +# Profile 2 is currently active so it will be kept +# This will delete future generations that are older than the parameter! +testCollectGarbageSetup +testCollectGarbageMockTimestamps +nix-env --switch-generation 2 +nix-collect-garbage --delete-older-than "2d" +testCollectGarbageCheckGenerations "2 4 5 6" + + +################################ +# nix-env --delete-generations # +################################ + +# Basic test that should leave 1 generation +testCollectGarbageSetup +nix-env --delete-generations old +testCollectGarbageCheckGenerations "6" + +# Basic test that deletes all but the active +# This includes future generations! +testCollectGarbageSetup +nix-env --switch-generation 4 +nix-env --delete-generations old +testCollectGarbageCheckGenerations "4" + +# Delete all except latest 4 generations +testCollectGarbageSetup +nix-env --delete-generations "+4" +testCollectGarbageCheckGenerations "3 4 5 6" + +# Delete all except latest 2 generations +# This will keep future generations +testCollectGarbageSetup +nix-env --switch-generation 5 +nix-env --delete-generations "+2" +testCollectGarbageCheckGenerations "4 5 6" + +# Delete everything older than 5 days +# All profiles are younger than 5 days +testCollectGarbageSetup +testCollectGarbageMockTimestamps +nix-env --delete-generations "5d" +testCollectGarbageCheckGenerations "1 2 3 4 5 6" + +# Delete everything older than 4 days +# Profile 1 was active at 4 days ago so it will be kept +testCollectGarbageSetup +testCollectGarbageMockTimestamps +nix-env --delete-generations "4d" +testCollectGarbageCheckGenerations "1 2 3 4 5 6" + +# Delete everything older than 3 days +# Profile 2 was active at 3 days ago so it will be kept +testCollectGarbageSetup +testCollectGarbageMockTimestamps +nix-env --delete-generations "3d" +testCollectGarbageCheckGenerations "2 3 4 5 6" + +# Delete everything older than 2 days +# Profile 4 was active at 2 days ago so it will be kept +testCollectGarbageSetup +testCollectGarbageMockTimestamps +nix-env --delete-generations "2d" +testCollectGarbageCheckGenerations "4 5 6" + +# Delete everything older than 1 day +# Profile 6 is current and was active at 1 day ago so it will be kept +testCollectGarbageSetup +testCollectGarbageMockTimestamps +nix-env --delete-generations "1d" +testCollectGarbageCheckGenerations "6" + +# Delete everything older than 2 days +# Profile 4 was active at 2 days ago so it will be kept +# Profile 2 is currently active so it will be kept +# This will delete future generations that are older than the parameter! +testCollectGarbageSetup +testCollectGarbageMockTimestamps +nix-env --switch-generation 2 +nix-env --delete-generations "2d" +testCollectGarbageCheckGenerations "2 4 5 6" diff --git a/tests/functional/nix-profile.sh b/tests/functional/nix-profile.sh index 12c13e69f..80d95f7cb 100755 --- a/tests/functional/nix-profile.sh +++ b/tests/functional/nix-profile.sh @@ -284,11 +284,30 @@ testProfileWipeHistoryCheckGenerations () { [[ "${actual%" "}" == "${expected}" ]] } +# Basic test that should leave 1 generation +testProfileWipeHistorySetup +nix profile wipe-history --older-than "old" +testProfileWipeHistoryCheckGenerations "6" + +# Basic test that deletes all but the active +# This will delete future generations! +testProfileWipeHistorySetup +nix profile rollback --to 4 +nix profile wipe-history --older-than "old" +testProfileWipeHistoryCheckGenerations "4" + # Delete all except latest 4 generations testProfileWipeHistorySetup nix profile wipe-history --older-than "+4" testProfileWipeHistoryCheckGenerations "3 4 5 6" +# Delete all except latest 2 generations +# This will keep future generations +testProfileWipeHistorySetup +nix profile rollback --to 5 +nix profile wipe-history --older-than "+2" +testProfileWipeHistoryCheckGenerations "4 5 6" + # Delete everything older than 5 days # All profiles are younger than 5 days testProfileWipeHistorySetup @@ -323,3 +342,13 @@ testProfileWipeHistorySetup testProfileWipeHistoryMockTimestamps nix profile wipe-history --older-than "1d" testProfileWipeHistoryCheckGenerations "6" + +# Delete everything older than 2 days +# Profile 4 was active at 2 days ago so it will be kept +# Profile 2 is currently active so it will be kept +# This will delete future generations that are older than the parameter! +testProfileWipeHistorySetup +testProfileWipeHistoryMockTimestamps +nix profile rollback --to 2 +nix profile wipe-history --older-than "2d" +testProfileWipeHistoryCheckGenerations "2 4 5 6"