source: project/release/4/estraier-client/tests/run.scm @ 15820

Last change on this file since 15820 was 15820, checked in by sjamaan, 10 years ago

Add more tests, simplify node-info by returning an alist (thanks to Mario for advice on that)

File size: 3.5 KB
1(load "../estraier-client.scm")
3(use test posix)
5(import estraier-client)
7;; This will start the server, we hope
8(system "rm -rf masterdir")              ; Just in case
9(system "estmaster init masterdir")
10(printf "Waiting for estmaster to startup...")
11(system "estmaster start -bg masterdir > /dev/null 2>&1")
12(sleep 2)
14(define master-uri "http://admin:admin@localhost:1978/master")
15(define node-uri "http://admin:admin@localhost:1978/node/testnode")
17(test-group "node master API"
18  (test "Empty node list on init" '() (master-nodes master-uri))
19  (test-error "Cannot connect with invalid credentials"
20              (master-nodes "http://admin:invalid@localhost:1978/master"))
21  (let ((nodes (begin (master-add-node master-uri "testnode")
22                      (master-add-node master-uri "testnode2" "testlabel")
23                      (master-nodes master-uri))))
24    (test "After adding two nodes, they show up"
25          '("testnode" "testnode2")
26          (map car nodes))
27    (test "Node label is accepted"
28          '("testnode" "testlabel")
29          (map cadr nodes)))
30  (test "After deleting a node, it is gone"
31        '("testnode")
32        (begin (master-delete-node master-uri "testnode2")
33               (map car (master-nodes master-uri))))
34  (let ((users (begin (master-add-user master-uri "testuser" "password"
35                                       fullname: "Joe testuser"
36                                       description: "This is just a test")
37                      (master-users master-uri))))
38    (test "After adding a user, it shows up"
39          '("admin" "testuser")
40          (map car users)))
41  (test "After deleting a user, it is gone"
42        '("admin")
43        (begin (master-delete-user master-uri "testuser")
44               (map car (master-users master-uri)))))
46;; TODO: more in-depth tests of result values
48(test-group "node API"
49  (let ((info (node-info node-uri)))
50    (test "Node-info reports zero documents at first"
51          0 (alist-ref 'document-count info))
52    (test "Node-info reports zero words at first"
53          0 (alist-ref 'word-count info))
54    (test "Node-info reports no guests at first"
55          '() (alist-ref 'guests info))
56    (test "Node-info reports no admins at first"
57          '() (alist-ref 'admins info)))
58  (test "Cache usage starts out empty"
59        0.0 (node-cache-usage node-uri))
60  (test "Document list starts out empty"
61        '() (list-documents node-uri))
62  (test-error "Putting document without URI is an error"
63              (put-document node-uri "This is just a test" '()))
64  (test-assert "Putting documents with URIs succeed"
65               (begin
66                 (put-document node-uri "Just a test" '((@uri . "/test1")))
67                 (put-document node-uri "Another test" '((@uri . "/test2")))
68                 #t))
69  (test "Nodes are listed"
70        '("/test1" "/test2")
71        (map (lambda (l) (alist-ref '@uri l)) (list-documents node-uri)))
72  (test "Skipping a node works"
73        '("/test2")
74        (map (lambda (l) (alist-ref '@uri l))
75             (list-documents node-uri prev: "/test1")))
76  (test "Maximum result length is used"
77        '("/test1")
78        (map (lambda (l) (alist-ref '@uri l))
79             (list-documents node-uri max: 1)))
81  (test "Clearing node results in empty document list"
82        '()
83        (begin (master-clear-node master-uri "testnode")
84               (list-documents node-uri))))
86(test-group "cleanup"
87 (test-assert "Clean shutdown" (begin (master-shutdown master-uri) #t))
88 (test-error "After shutdown, server is unreachable" (master-nodes master-uri)))
89(system "rm -rf masterdir")
Note: See TracBrowser for help on using the repository browser.