Fossil SCM
Refactoring in the json tests. Add coverage of /json/wiki. Note discrepency between documentation and execution of /json/wiki/diff.
Commit
cb611ffc9b2f107eb734986872de37cf15b2358b
Parent
2ada5ec76e630c8…
1 file changed
+98
-20
+98
-20
| --- test/json.test | ||
| +++ test/json.test | ||
| @@ -24,11 +24,14 @@ | ||
| 24 | 24 | # teacup install json |
| 25 | 25 | # teacup install json::write |
| 26 | 26 | package require json |
| 27 | 27 | |
| 28 | 28 | # Make sure we have a build with the json command at all and that it |
| 29 | -# is not stubbed out | |
| 29 | +# is not stubbed out. This assumes the current (as of 2016-01-27) | |
| 30 | +# practice of eliminating all trace of the fossil json command when | |
| 31 | +# not configured. If that changes, these conditions might not prevent | |
| 32 | +# the rest of this file from running. | |
| 30 | 33 | fossil help -a |
| 31 | 34 | if {[string first json $RESULT] eq ""} { |
| 32 | 35 | puts "Fossil was not compiled with JSON support."; return |
| 33 | 36 | } |
| 34 | 37 | fossil json -expectError |
| @@ -67,24 +70,28 @@ | ||
| 67 | 70 | set JR [::json::json2dict $body] |
| 68 | 71 | } |
| 69 | 72 | return $status |
| 70 | 73 | } |
| 71 | 74 | |
| 72 | -# Inspect the envelope part of a returned JSON structure to confirm | |
| 73 | -# that it has specific fields and that it lacks specific fields. | |
| 74 | -proc test_json_envelope {testname okfields badfields} { | |
| 75 | - global JR | |
| 75 | +# Inspect a dict for keys it must have and keys it must not have | |
| 76 | +proc test_dict_keys {testname D okfields badfields} { | |
| 76 | 77 | set i 1 |
| 77 | 78 | foreach f $okfields { |
| 78 | - test "$testname-$i" {[dict exists $JR $f]} | |
| 79 | + test "$testname-$i" {[dict exists $D $f]} | |
| 79 | 80 | incr i |
| 80 | 81 | } |
| 81 | 82 | foreach f $badfields { |
| 82 | - test "$testname-$i" {![dict exists $JR $f]} | |
| 83 | + test "$testname-$i" {![dict exists $D $f]} | |
| 83 | 84 | incr i |
| 84 | 85 | } |
| 85 | 86 | } |
| 87 | + | |
| 88 | +# Inspect the envelope part of a returned JSON structure to confirm | |
| 89 | +# that it has specific fields and that it lacks specific fields. | |
| 90 | +proc test_json_envelope {testname okfields badfields} { | |
| 91 | + test_dict_keys $testname $::JR $okfields $badfields | |
| 92 | +} | |
| 86 | 93 | |
| 87 | 94 | # Inspect the envelope of a normal successful result |
| 88 | 95 | proc test_json_envelope_ok {testname} { |
| 89 | 96 | test_json_envelope $testname [concat fossil timestamp command procTimeUs \ |
| 90 | 97 | procTimeMs payload] [concat resultCode resultText] |
| @@ -91,20 +98,11 @@ | ||
| 91 | 98 | } |
| 92 | 99 | |
| 93 | 100 | # Inspect the payload of a successful result to confirm that it has |
| 94 | 101 | # specific fields and that it lacks specific fields. |
| 95 | 102 | proc test_json_payload {testname okfields badfields} { |
| 96 | - global JR | |
| 97 | - set i 1 | |
| 98 | - foreach f $okfields { | |
| 99 | - test "$testname-P-$i" {[dict exists $JR payload $f]} | |
| 100 | - incr i | |
| 101 | - } | |
| 102 | - foreach f $badfields { | |
| 103 | - test "$testname-P-$i" {![dict exists $JR payload $f]} | |
| 104 | - incr i | |
| 105 | - } | |
| 103 | + test_dict_keys $testname [dict get $::JR payload] $okfields $badfields | |
| 106 | 104 | } |
| 107 | 105 | |
| 108 | 106 | #### VERSION AKA HAI |
| 109 | 107 | |
| 110 | 108 | # The JSON API generally assumes we have a respository, so let it have one. |
| @@ -149,23 +147,34 @@ | ||
| 149 | 147 | fossil add empty |
| 150 | 148 | fossil ci -m "empty file" |
| 151 | 149 | |
| 152 | 150 | # json artifact (checkin) |
| 153 | 151 | fossil_json [concat artifact tip] |
| 154 | -test_json_envelope_ok json-artifact | |
| 152 | +test_json_envelope_ok json-artifact-checkin-env | |
| 155 | 153 | test json-artifact-checkin {[dict get $JR payload type] eq "checkin"} |
| 156 | 154 | test_json_payload json-artifact \ |
| 157 | 155 | [concat type uuid isLeaf timestamp user comment parents tags files] {} |
| 158 | 156 | |
| 159 | 157 | # json artifact (file) |
| 160 | 158 | fossil_json [concat artifact $UUID_empty] |
| 161 | -test_json_envelope_ok json-artifact | |
| 159 | +test_json_envelope_ok json-artifact-file-env | |
| 162 | 160 | test json-artifact-file {[dict get $JR payload type] eq "file"} |
| 163 | 161 | test_json_payload json-artifact [concat type uuid size checkins] {} |
| 164 | 162 | |
| 165 | 163 | # json artifact (wiki) |
| 166 | -# name, uuid, parent, user, timestamp, size, content? | |
| 164 | +fossil wiki create Empty <<"" | |
| 165 | +fossil_json wiki get Empty | |
| 166 | +test json-wiki-get {[dict get $JR payload name] eq "Empty"} | |
| 167 | +set uuid [dict get $JR payload uuid] | |
| 168 | +fossil_json artifact $uuid | |
| 169 | +test_json_envelope_ok json-artifact-wiki-env | |
| 170 | +test json-artifact-wiki {[dict get $JR payload type] eq "wiki"} | |
| 171 | +test_json_payload json-artifact-wiki [list type uuid artifact] {} | |
| 172 | +set artifact [dict get $JR payload artifact] | |
| 173 | +test_dict_keys json-artifact-wiki-artifact $artifact \ | |
| 174 | + [list name uuid user timestamp size] {} | |
| 175 | +# name, uuid, parent?, user, timestamp, size?, content? | |
| 167 | 176 | |
| 168 | 177 | |
| 169 | 178 | #### AUTHENTICATION |
| 170 | 179 | #### BRANCHES |
| 171 | 180 | #### CONFIG |
| @@ -178,9 +187,78 @@ | ||
| 178 | 187 | #### TAGS |
| 179 | 188 | #### TICKETS |
| 180 | 189 | #### TICKET REPORTS |
| 181 | 190 | #### TIMELINE |
| 182 | 191 | #### USER MANAGEMENT |
| 192 | + | |
| 183 | 193 | #### WIKI |
| 194 | + | |
| 195 | +# wiki list | |
| 196 | +fossil_json wiki list | |
| 197 | +test_json_envelope_ok json-wiki-list-env | |
| 198 | +set pages [dict get $JR payload] | |
| 199 | +test json-wiki-1 {[llength $pages] == 1} | |
| 200 | +test json-wiki-2 {[lindex $pages 0] eq "Empty"} | |
| 201 | +fossil_json wiki list --verbose | |
| 202 | +set pages [dict get $JR payload] | |
| 203 | +test json-wiki-verbose-1 {[llength $pages] == 1} | |
| 204 | +test_dict_keys json-wiki-verbose-pages [lindex $pages 0] [list name uuid user timestamp size] {} | |
| 205 | + | |
| 206 | +# wiki get | |
| 207 | +fossil_json wiki get Empty | |
| 208 | +test_json_envelope_ok json-wiki-get-env | |
| 209 | +# this page has only one version, so no parent should be listed | |
| 210 | +test_json_payload json-wiki-get [list name uuid user timestamp size content] [list parent] | |
| 211 | + | |
| 212 | + | |
| 213 | +# wiki create | |
| 214 | +# requires an authToken? Not from CLI. | |
| 215 | + | |
| 216 | +write_file req.json { | |
| 217 | + { | |
| 218 | + "command":"wiki/create", | |
| 219 | + "payload":{ | |
| 220 | + "name":"Page2", | |
| 221 | + "content":"Lorem ipsum dolor sic amet." | |
| 222 | + } | |
| 223 | + } | |
| 224 | +} | |
| 225 | +fossil_json --json-input req.json | |
| 226 | +test_json_envelope_ok json-wiki-create-env | |
| 227 | +fossil_json wiki get Page2 | |
| 228 | +test_json_envelope_ok json-wiki-create-get-env | |
| 229 | +test_json_payload json-wiki-save-get [list name uuid user timestamp size content] {parent} | |
| 230 | +set uuid1 [dict get $JR payload uuid] | |
| 231 | + | |
| 232 | +# wiki save | |
| 233 | + | |
| 234 | +write_file req2.json { | |
| 235 | + { | |
| 236 | + "command":"wiki/save", | |
| 237 | + "payload":{ | |
| 238 | + "name":"Page2", | |
| 239 | + "content":"Lorem ipsum dolor sic amet.\nconsectetur adipisicing elit." | |
| 240 | + } | |
| 241 | + } | |
| 242 | +} | |
| 243 | +fossil_json --json-input req2.json | |
| 244 | +test_json_envelope_ok json-wiki-save-env | |
| 245 | +fossil_json wiki get Page2 | |
| 246 | +test_json_envelope_ok json-wiki-save-get-env | |
| 247 | +test_json_payload json-wiki-save-get [list name uuid user timestamp size parent content] {} | |
| 248 | +set uuid2 [dict get $JR payload uuid] | |
| 249 | +test json-wiki-save-parent {[dict get $JR payload parent] eq $uuid1} | |
| 250 | + | |
| 251 | +# wiki diff | |
| 252 | + | |
| 253 | +fossil_json wiki diff $uuid1 $uuid2 | |
| 254 | +test_json_envelope_ok json-wiki-diff-env | |
| 255 | +test_json_payload json-wiki-diff [list v1 v2 diff] {} | |
| 256 | +test json-wiki-diff-v1 {[dict get $JR payload v1] eq $uuid1} | |
| 257 | +test json-wiki-diff-v1 {[dict get $JR payload v2] eq $uuid2} | |
| 258 | +set diff [dict get $JR payload diff] | |
| 259 | +test json-wiki-diff-diff {[string first "+consectetur adipisicing elit" $diff] >= 0} ;#knownBug | |
| 260 | +#puts [dict get $JR payload diff] | |
| 261 | + | |
| 184 | 262 | #### UNAVOIDABLE MISC |
| 185 | 263 | |
| 186 | 264 | |
| 187 | 265 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -24,11 +24,14 @@ | |
| 24 | # teacup install json |
| 25 | # teacup install json::write |
| 26 | package require json |
| 27 | |
| 28 | # Make sure we have a build with the json command at all and that it |
| 29 | # is not stubbed out |
| 30 | fossil help -a |
| 31 | if {[string first json $RESULT] eq ""} { |
| 32 | puts "Fossil was not compiled with JSON support."; return |
| 33 | } |
| 34 | fossil json -expectError |
| @@ -67,24 +70,28 @@ | |
| 67 | set JR [::json::json2dict $body] |
| 68 | } |
| 69 | return $status |
| 70 | } |
| 71 | |
| 72 | # Inspect the envelope part of a returned JSON structure to confirm |
| 73 | # that it has specific fields and that it lacks specific fields. |
| 74 | proc test_json_envelope {testname okfields badfields} { |
| 75 | global JR |
| 76 | set i 1 |
| 77 | foreach f $okfields { |
| 78 | test "$testname-$i" {[dict exists $JR $f]} |
| 79 | incr i |
| 80 | } |
| 81 | foreach f $badfields { |
| 82 | test "$testname-$i" {![dict exists $JR $f]} |
| 83 | incr i |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | # Inspect the envelope of a normal successful result |
| 88 | proc test_json_envelope_ok {testname} { |
| 89 | test_json_envelope $testname [concat fossil timestamp command procTimeUs \ |
| 90 | procTimeMs payload] [concat resultCode resultText] |
| @@ -91,20 +98,11 @@ | |
| 91 | } |
| 92 | |
| 93 | # Inspect the payload of a successful result to confirm that it has |
| 94 | # specific fields and that it lacks specific fields. |
| 95 | proc test_json_payload {testname okfields badfields} { |
| 96 | global JR |
| 97 | set i 1 |
| 98 | foreach f $okfields { |
| 99 | test "$testname-P-$i" {[dict exists $JR payload $f]} |
| 100 | incr i |
| 101 | } |
| 102 | foreach f $badfields { |
| 103 | test "$testname-P-$i" {![dict exists $JR payload $f]} |
| 104 | incr i |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | #### VERSION AKA HAI |
| 109 | |
| 110 | # The JSON API generally assumes we have a respository, so let it have one. |
| @@ -149,23 +147,34 @@ | |
| 149 | fossil add empty |
| 150 | fossil ci -m "empty file" |
| 151 | |
| 152 | # json artifact (checkin) |
| 153 | fossil_json [concat artifact tip] |
| 154 | test_json_envelope_ok json-artifact |
| 155 | test json-artifact-checkin {[dict get $JR payload type] eq "checkin"} |
| 156 | test_json_payload json-artifact \ |
| 157 | [concat type uuid isLeaf timestamp user comment parents tags files] {} |
| 158 | |
| 159 | # json artifact (file) |
| 160 | fossil_json [concat artifact $UUID_empty] |
| 161 | test_json_envelope_ok json-artifact |
| 162 | test json-artifact-file {[dict get $JR payload type] eq "file"} |
| 163 | test_json_payload json-artifact [concat type uuid size checkins] {} |
| 164 | |
| 165 | # json artifact (wiki) |
| 166 | # name, uuid, parent, user, timestamp, size, content? |
| 167 | |
| 168 | |
| 169 | #### AUTHENTICATION |
| 170 | #### BRANCHES |
| 171 | #### CONFIG |
| @@ -178,9 +187,78 @@ | |
| 178 | #### TAGS |
| 179 | #### TICKETS |
| 180 | #### TICKET REPORTS |
| 181 | #### TIMELINE |
| 182 | #### USER MANAGEMENT |
| 183 | #### WIKI |
| 184 | #### UNAVOIDABLE MISC |
| 185 | |
| 186 | |
| 187 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -24,11 +24,14 @@ | |
| 24 | # teacup install json |
| 25 | # teacup install json::write |
| 26 | package require json |
| 27 | |
| 28 | # Make sure we have a build with the json command at all and that it |
| 29 | # is not stubbed out. This assumes the current (as of 2016-01-27) |
| 30 | # practice of eliminating all trace of the fossil json command when |
| 31 | # not configured. If that changes, these conditions might not prevent |
| 32 | # the rest of this file from running. |
| 33 | fossil help -a |
| 34 | if {[string first json $RESULT] eq ""} { |
| 35 | puts "Fossil was not compiled with JSON support."; return |
| 36 | } |
| 37 | fossil json -expectError |
| @@ -67,24 +70,28 @@ | |
| 70 | set JR [::json::json2dict $body] |
| 71 | } |
| 72 | return $status |
| 73 | } |
| 74 | |
| 75 | # Inspect a dict for keys it must have and keys it must not have |
| 76 | proc test_dict_keys {testname D okfields badfields} { |
| 77 | set i 1 |
| 78 | foreach f $okfields { |
| 79 | test "$testname-$i" {[dict exists $D $f]} |
| 80 | incr i |
| 81 | } |
| 82 | foreach f $badfields { |
| 83 | test "$testname-$i" {![dict exists $D $f]} |
| 84 | incr i |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | # Inspect the envelope part of a returned JSON structure to confirm |
| 89 | # that it has specific fields and that it lacks specific fields. |
| 90 | proc test_json_envelope {testname okfields badfields} { |
| 91 | test_dict_keys $testname $::JR $okfields $badfields |
| 92 | } |
| 93 | |
| 94 | # Inspect the envelope of a normal successful result |
| 95 | proc test_json_envelope_ok {testname} { |
| 96 | test_json_envelope $testname [concat fossil timestamp command procTimeUs \ |
| 97 | procTimeMs payload] [concat resultCode resultText] |
| @@ -91,20 +98,11 @@ | |
| 98 | } |
| 99 | |
| 100 | # Inspect the payload of a successful result to confirm that it has |
| 101 | # specific fields and that it lacks specific fields. |
| 102 | proc test_json_payload {testname okfields badfields} { |
| 103 | test_dict_keys $testname [dict get $::JR payload] $okfields $badfields |
| 104 | } |
| 105 | |
| 106 | #### VERSION AKA HAI |
| 107 | |
| 108 | # The JSON API generally assumes we have a respository, so let it have one. |
| @@ -149,23 +147,34 @@ | |
| 147 | fossil add empty |
| 148 | fossil ci -m "empty file" |
| 149 | |
| 150 | # json artifact (checkin) |
| 151 | fossil_json [concat artifact tip] |
| 152 | test_json_envelope_ok json-artifact-checkin-env |
| 153 | test json-artifact-checkin {[dict get $JR payload type] eq "checkin"} |
| 154 | test_json_payload json-artifact \ |
| 155 | [concat type uuid isLeaf timestamp user comment parents tags files] {} |
| 156 | |
| 157 | # json artifact (file) |
| 158 | fossil_json [concat artifact $UUID_empty] |
| 159 | test_json_envelope_ok json-artifact-file-env |
| 160 | test json-artifact-file {[dict get $JR payload type] eq "file"} |
| 161 | test_json_payload json-artifact [concat type uuid size checkins] {} |
| 162 | |
| 163 | # json artifact (wiki) |
| 164 | fossil wiki create Empty <<"" |
| 165 | fossil_json wiki get Empty |
| 166 | test json-wiki-get {[dict get $JR payload name] eq "Empty"} |
| 167 | set uuid [dict get $JR payload uuid] |
| 168 | fossil_json artifact $uuid |
| 169 | test_json_envelope_ok json-artifact-wiki-env |
| 170 | test json-artifact-wiki {[dict get $JR payload type] eq "wiki"} |
| 171 | test_json_payload json-artifact-wiki [list type uuid artifact] {} |
| 172 | set artifact [dict get $JR payload artifact] |
| 173 | test_dict_keys json-artifact-wiki-artifact $artifact \ |
| 174 | [list name uuid user timestamp size] {} |
| 175 | # name, uuid, parent?, user, timestamp, size?, content? |
| 176 | |
| 177 | |
| 178 | #### AUTHENTICATION |
| 179 | #### BRANCHES |
| 180 | #### CONFIG |
| @@ -178,9 +187,78 @@ | |
| 187 | #### TAGS |
| 188 | #### TICKETS |
| 189 | #### TICKET REPORTS |
| 190 | #### TIMELINE |
| 191 | #### USER MANAGEMENT |
| 192 | |
| 193 | #### WIKI |
| 194 | |
| 195 | # wiki list |
| 196 | fossil_json wiki list |
| 197 | test_json_envelope_ok json-wiki-list-env |
| 198 | set pages [dict get $JR payload] |
| 199 | test json-wiki-1 {[llength $pages] == 1} |
| 200 | test json-wiki-2 {[lindex $pages 0] eq "Empty"} |
| 201 | fossil_json wiki list --verbose |
| 202 | set pages [dict get $JR payload] |
| 203 | test json-wiki-verbose-1 {[llength $pages] == 1} |
| 204 | test_dict_keys json-wiki-verbose-pages [lindex $pages 0] [list name uuid user timestamp size] {} |
| 205 | |
| 206 | # wiki get |
| 207 | fossil_json wiki get Empty |
| 208 | test_json_envelope_ok json-wiki-get-env |
| 209 | # this page has only one version, so no parent should be listed |
| 210 | test_json_payload json-wiki-get [list name uuid user timestamp size content] [list parent] |
| 211 | |
| 212 | |
| 213 | # wiki create |
| 214 | # requires an authToken? Not from CLI. |
| 215 | |
| 216 | write_file req.json { |
| 217 | { |
| 218 | "command":"wiki/create", |
| 219 | "payload":{ |
| 220 | "name":"Page2", |
| 221 | "content":"Lorem ipsum dolor sic amet." |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | fossil_json --json-input req.json |
| 226 | test_json_envelope_ok json-wiki-create-env |
| 227 | fossil_json wiki get Page2 |
| 228 | test_json_envelope_ok json-wiki-create-get-env |
| 229 | test_json_payload json-wiki-save-get [list name uuid user timestamp size content] {parent} |
| 230 | set uuid1 [dict get $JR payload uuid] |
| 231 | |
| 232 | # wiki save |
| 233 | |
| 234 | write_file req2.json { |
| 235 | { |
| 236 | "command":"wiki/save", |
| 237 | "payload":{ |
| 238 | "name":"Page2", |
| 239 | "content":"Lorem ipsum dolor sic amet.\nconsectetur adipisicing elit." |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | fossil_json --json-input req2.json |
| 244 | test_json_envelope_ok json-wiki-save-env |
| 245 | fossil_json wiki get Page2 |
| 246 | test_json_envelope_ok json-wiki-save-get-env |
| 247 | test_json_payload json-wiki-save-get [list name uuid user timestamp size parent content] {} |
| 248 | set uuid2 [dict get $JR payload uuid] |
| 249 | test json-wiki-save-parent {[dict get $JR payload parent] eq $uuid1} |
| 250 | |
| 251 | # wiki diff |
| 252 | |
| 253 | fossil_json wiki diff $uuid1 $uuid2 |
| 254 | test_json_envelope_ok json-wiki-diff-env |
| 255 | test_json_payload json-wiki-diff [list v1 v2 diff] {} |
| 256 | test json-wiki-diff-v1 {[dict get $JR payload v1] eq $uuid1} |
| 257 | test json-wiki-diff-v1 {[dict get $JR payload v2] eq $uuid2} |
| 258 | set diff [dict get $JR payload diff] |
| 259 | test json-wiki-diff-diff {[string first "+consectetur adipisicing elit" $diff] >= 0} ;#knownBug |
| 260 | #puts [dict get $JR payload diff] |
| 261 | |
| 262 | #### UNAVOIDABLE MISC |
| 263 | |
| 264 | |
| 265 |