at master 2.9 kB view raw
1{ pkgs, lib, ... }: 2 3{ 4 name = "shiori"; 5 meta.maintainers = with lib.maintainers; [ minijackson ]; 6 7 nodes.machine = 8 { ... }: 9 { 10 services.shiori.enable = true; 11 }; 12 13 testScript = 14 let 15 authJSON = pkgs.writeText "auth.json" ( 16 builtins.toJSON { 17 username = "shiori"; 18 password = "gopher"; 19 owner = true; 20 } 21 ); 22 23 insertBookmark = { 24 url = "http://example.org"; 25 title = "Example Bookmark"; 26 }; 27 28 insertBookmarkJSON = pkgs.writeText "insertBookmark.json" (builtins.toJSON insertBookmark); 29 in 30 '' 31 #import json 32 33 machine.wait_for_unit("shiori.service") 34 machine.wait_for_open_port(8080) 35 machine.succeed("curl --fail http://localhost:8080/") 36 machine.succeed("curl --fail --location http://localhost:8080/ | grep -i shiori") 37 38 # The test code below no longer works because the API authentication has changed. 39 40 #with subtest("login"): 41 # auth_json = machine.succeed( 42 # "curl --fail --location http://localhost:8080/api/login " 43 # "-X POST -H 'Content-Type:application/json' -d @${authJSON}" 44 # ) 45 # auth_ret = json.loads(auth_json) 46 # session_id = auth_ret["session"] 47 48 #with subtest("bookmarks"): 49 # with subtest("first use no bookmarks"): 50 # bookmarks_json = machine.succeed( 51 # ( 52 # "curl --fail --location http://localhost:8080/api/bookmarks " 53 # "-H 'X-Session-Id:{}'" 54 # ).format(session_id) 55 # ) 56 57 # if json.loads(bookmarks_json)["bookmarks"] != []: 58 # raise Exception("Shiori have a bookmark on first use") 59 60 # with subtest("insert bookmark"): 61 # machine.succeed( 62 # ( 63 # "curl --fail --location http://localhost:8080/api/bookmarks " 64 # "-X POST -H 'X-Session-Id:{}' " 65 # "-H 'Content-Type:application/json' -d @${insertBookmarkJSON}" 66 # ).format(session_id) 67 # ) 68 69 # with subtest("get inserted bookmark"): 70 # bookmarks_json = machine.succeed( 71 # ( 72 # "curl --fail --location http://localhost:8080/api/bookmarks " 73 # "-H 'X-Session-Id:{}'" 74 # ).format(session_id) 75 # ) 76 77 # bookmarks = json.loads(bookmarks_json)["bookmarks"] 78 # if len(bookmarks) != 1: 79 # raise Exception("Shiori didn't save the bookmark") 80 81 # bookmark = bookmarks[0] 82 # if ( 83 # bookmark["url"] != "${insertBookmark.url}" 84 # or bookmark["title"] != "${insertBookmark.title}" 85 # ): 86 # raise Exception("Inserted bookmark doesn't have same URL or title") 87 ''; 88}