lol

nixos/tests/snipe-it: init (#180772)

authored by

Yaya and committed by
GitHub
5effdaaa 1d71d2e8

+105
+1
nixos/tests/all-tests.nix
··· 634 634 smokeping = handleTest ./smokeping.nix {}; 635 635 snapcast = handleTest ./snapcast.nix {}; 636 636 snapper = handleTest ./snapper.nix {}; 637 + snipe-it = runTest ./web-apps/snipe-it.nix; 637 638 soapui = handleTest ./soapui.nix {}; 638 639 sogo = handleTest ./sogo.nix {}; 639 640 solanum = handleTest ./solanum.nix {};
+101
nixos/tests/web-apps/snipe-it.nix
··· 1 + /* 2 + Snipe-IT NixOS test 3 + 4 + It covers the following scenario: 5 + - Installation 6 + - Backup and restore 7 + 8 + Scenarios NOT covered by this test (but perhaps in the future): 9 + - Sending and receiving emails 10 + */ 11 + { pkgs, ... }: let 12 + siteName = "NixOS Snipe-IT Test Instance"; 13 + in { 14 + name = "snipe-it"; 15 + 16 + meta.maintainers = with pkgs.lib.maintainers; [ yayayayaka ]; 17 + 18 + nodes = { 19 + snipeit = { ... }: { 20 + services.snipe-it = { 21 + enable = true; 22 + appKeyFile = toString (pkgs.writeText "snipe-it-app-key" "uTqGUN5GUmUrh/zSAYmhyzRk62pnpXICyXv9eeITI8k="); 23 + hostName = "localhost"; 24 + database.createLocally = true; 25 + mail = { 26 + driver = "smtp"; 27 + encryption = "tls"; 28 + host = "localhost"; 29 + port = 1025; 30 + from.name = "Snipe-IT NixOS test"; 31 + from.address = "snipe-it@localhost"; 32 + replyTo.address = "snipe-it@localhost"; 33 + user = "snipe-it@localhost"; 34 + passwordFile = toString (pkgs.writeText "snipe-it-mail-pass" "a-secure-mail-password"); 35 + }; 36 + }; 37 + }; 38 + }; 39 + 40 + testScript = { nodes }: let 41 + backupPath = "${nodes.snipeit.services.snipe-it.dataDir}/storage/app/backups"; 42 + 43 + # Snipe-IT has been installed successfully if the site name shows up on the login page 44 + checkLoginPage = { shouldSucceed ? true }: '' 45 + snipeit.${if shouldSucceed then "succeed" else "fail"}("""curl http://localhost/login | grep '${siteName}'""") 46 + ''; 47 + in '' 48 + start_all() 49 + 50 + snipeit.wait_for_unit("nginx.service") 51 + snipeit.wait_for_unit("snipe-it-setup.service") 52 + 53 + # Create an admin user 54 + snipeit.succeed( 55 + """ 56 + snipe-it snipeit:create-admin \ 57 + --username="admin" \ 58 + --email="janedoe@localhost" \ 59 + --password="extremesecurepassword" \ 60 + --first_name="Jane" \ 61 + --last_name="Doe" 62 + """ 63 + ) 64 + 65 + with subtest("Circumvent the pre-flight setup by just writing some settings into the database ourself"): 66 + snipeit.succeed( 67 + """ 68 + mysql -D ${nodes.snipeit.services.snipe-it.database.name} -e "INSERT INTO settings (id, user_id, site_name) VALUES ('1', '1', '${siteName}');" 69 + """ 70 + ) 71 + 72 + # Usually these are generated during the pre-flight setup 73 + snipeit.succeed("snipe-it passport:keys") 74 + 75 + 76 + # Login page should now contain the configured site name 77 + ${checkLoginPage {}} 78 + 79 + with subtest("Test Backup and restore"): 80 + snipeit.succeed("snipe-it snipeit:backup") 81 + 82 + # One zip file should have been created 83 + snipeit.succeed("""[ "$(ls -1 "${backupPath}" | wc -l)" -eq 1 ]""") 84 + 85 + # Purge the state 86 + snipeit.succeed("snipe-it migrate:fresh --force") 87 + 88 + # Login page should disappear 89 + ${checkLoginPage { shouldSucceed = false; }} 90 + 91 + # Restore the state 92 + snipeit.succeed( 93 + """ 94 + snipe-it snipeit:restore --force $(find "${backupPath}/" -type f -name "*.zip") 95 + """ 96 + ) 97 + 98 + # Login page should be back again 99 + ${checkLoginPage {}} 100 + ''; 101 + }
+3
pkgs/servers/web-apps/snipe-it/default.nix
··· 4 4 , fetchFromGitHub 5 5 , dataDir ? "/var/lib/snipe-it" 6 6 , mariadb 7 + , nixosTests 7 8 }: 8 9 9 10 let ··· 41 42 rev = "v${version}"; 42 43 sha256 = "0c8cjywhyiywfav2syjkah777qj5f1jrckgri70ypqyxbwgb4rpm"; 43 44 }; 45 + 46 + passthru.tests = nixosTests.snipe-it; 44 47 45 48 meta = with lib; { 46 49 description = "A free open source IT asset/license management system";