summaryrefslogtreecommitdiff
path: root/clab.yarn
blob: 745eb09b0306e05b31c5ad1ddeee7d0774dfeafe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
Black box tests for clab
========================

Clab is a command line address book application.
It has no interactive features, so black box testing it
is fairly easy.

Let's start with an empty database.

    SCENARIO empty database
    GIVEN an empty database

    WHEN listing all records
    THEN nothing is listed

    WHEN searching for Alice
    THEN output is empty

    WHEN mutt-querying for Alice
    THEN no matches

Next, let's add records for Alice and Bob, and make
sure searches find only the right records.

    SCENARIO database with records
    GIVEN an empty database
    AND a record for "Alice Atherton" with e-mail alice@example.com
    AND a record for "Bob Bobbington" with e-mail bob@example.com

    WHEN listing all records
    THEN Alice is found
    AND Bob is found

    WHEN searching for Alice
    THEN Alice is found
    AND Bob is not found

    WHEN mutt-querying for Alice
    THEN Alice is found
    AND alice@example.com is found
    AND Bob is not found
    AND bob@example.com is not found

Put several records in one file.

    SCENARIO files with multiple records
    GIVEN an empty database
    AND records for Alice (alice@example.com) and Bob (bob@example.com)
    WHEN listing all records
    THEN Alice is found
    AND Bob is found

    WHEN searching for Alice
    THEN Alice is found
    AND Bob is not found

    WHEN mutt-querying for Alice
    THEN Alice is found
    AND alice@example.com is found
    AND Bob is not found
    AND bob@example.com is not found

Sometimes the same person is in the database multiple times
(e.g., different records for home and work personas, where the
work persona is automatically generated from LDAP or something).
In this case, only find each person once.

    GIVEN another record for Alice (alice@example.com)
    WHEN mutt-querying for example
    THEN Alice is found only once

Implementation
--------------

These implement the various steps.

    IMPLEMENTS GIVEN an empty database
    mkdir "$DATADIR/db"

    IMPLEMENTS GIVEN a record for "([^"]+)" with e-mail (.*)
    cat << EOF > "$DATADIR/db/$MATCH_1.yaml"
    name: $MATCH_1
    email: $MATCH_2
    EOF

    IMPLEMENTS GIVEN records for (\S+) \((\S+)\) and (\S+) \((\S+)\)
    cat << EOF > "$DATADIR/db/foo.yaml"
    - name: $MATCH_1
      email: $MATCH_2
    - name: $MATCH_3
      email: $MATCH_4
    EOF

    IMPLEMENTS GIVEN another record for (\S+) \((\S+)\)
    cat << EOF >> "$DATADIR/db/foo.yaml"
    - name: $MATCH_1
      email: $MATCH_2
    EOF

    IMPLEMENTS WHEN listing all records
    ./clab --no-default-config --db "$DATADIR/db" list > "$DATADIR/output"

    IMPLEMENTS WHEN searching for (.*)
    ./clab --no-default-config --db "$DATADIR/db" find "$MATCH_1" > "$DATADIR/output"

    IMPLEMENTS WHEN mutt-querying for (.*)
    ./clab --no-default-config --db "$DATADIR/db" mutt-query "$MATCH_1" > "$DATADIR/output" || true

    IMPLEMENTS THEN nothing is listed
    stat -c %s "$DATADIR/output" | grep -x 0

    IMPLEMENTS THEN output is empty
    stat -c %s "$DATADIR/output" | grep -x 0

    IMPLEMENTS THEN no matches
    diff -u "$DATADIR/output" - << EOF
    No matches
    EOF

    IMPLEMENTS THEN (.*) is found
    set -x
    grep -F "$MATCH_1" "$DATADIR/output"

    IMPLEMENTS THEN (.*) is found only once
    n=$(grep -cF "$MATCH_1" "$DATADIR/output")
    if [ "$n" != 1 ]
    then
	echo "$MATCH_1 was found $n times, expected 1" 1>&2
	exit 1
    fi

    IMPLEMENTS THEN (.*) is not found
    ! grep -F "$MATCH_1" "$DATADIR/output"