Fossil SCM
Update copyright date to this year since the JSON tests are new this year. Fix indentation of Tcl to match established convention. Add test of JSON API version to reflect earliest I expect to pass these tests. Document block of Version and HAI, and add version for consistency.
Commit
c4f8d88fd91a8925f832e1b58228cdf7f8aff3c1
Parent
2ff6ceb9853b6d1…
1 file changed
+53
-42
+53
-42
| --- test/json.test | ||
| +++ test/json.test | ||
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | # |
| 2 | -# Copyright (c) 2011 D. Richard Hipp | |
| 2 | +# Copyright (c) 2016 D. Richard Hipp | |
| 3 | 3 | # |
| 4 | 4 | # This program is free software; you can redistribute it and/or |
| 5 | 5 | # modify it under the terms of the Simplified BSD License (also |
| 6 | 6 | # known as the "2-Clause License" or "FreeBSD License".) |
| 7 | 7 | # |
| @@ -44,94 +44,104 @@ | ||
| 44 | 44 | # RESULT to the response text, and JR to a Tcl dict conversion of the |
| 45 | 45 | # response body. |
| 46 | 46 | # |
| 47 | 47 | # Returns "200" or "500". |
| 48 | 48 | proc fossil_json {args} { |
| 49 | - global RESULT JR | |
| 50 | - uplevel 1 fossil json {*}$args | |
| 51 | - set JR [::json::json2dict $RESULT] | |
| 52 | - return "200" | |
| 49 | + global RESULT JR | |
| 50 | + uplevel 1 fossil json {*}$args | |
| 51 | + set JR [::json::json2dict $RESULT] | |
| 52 | + return "200" | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | # Use the HTTP interface to fetch a JSON API URL. Sets the globals |
| 56 | 56 | # RESULT to the HTTP response body, and JR to a Tcl dict conversion of |
| 57 | 57 | # the response body. |
| 58 | 58 | # |
| 59 | 59 | # Returns the status code from the HTTP header. |
| 60 | 60 | proc fossil_http_json {url} { |
| 61 | - global RESULT JR | |
| 62 | - set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil" | |
| 63 | - set RESULT [fossil_maybe_answer $request http] | |
| 64 | - regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body | |
| 65 | - regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg | |
| 66 | - if {$status eq "200"} { | |
| 67 | - set JR [::json::json2dict $body] | |
| 68 | - } | |
| 69 | - return $status | |
| 61 | + global RESULT JR | |
| 62 | + set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil" | |
| 63 | + set RESULT [fossil_maybe_answer $request http] | |
| 64 | + regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body | |
| 65 | + regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg | |
| 66 | + if {$status eq "200"} { | |
| 67 | + set JR [::json::json2dict $body] | |
| 68 | + } | |
| 69 | + return $status | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | # Inspect the envelope part of a returned JSON structure to confirm |
| 73 | 73 | # that it has specific fields and that it lacks specific fields. |
| 74 | 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 | - } | |
| 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 | 85 | } |
| 86 | 86 | |
| 87 | 87 | # Inspect the envelope of a normal successful result |
| 88 | 88 | proc test_json_envelope_ok {testname} { |
| 89 | - test_json_envelope $testname [concat fossil timestamp command procTimeUs \ | |
| 90 | - procTimeMs payload] [concat resultCode resultText] | |
| 89 | + test_json_envelope $testname [concat fossil timestamp command procTimeUs \ | |
| 90 | + procTimeMs payload] [concat resultCode resultText] | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | # Inspect the payload of a successful result to confirm that it has |
| 94 | 94 | # specific fields and that it lacks specific fields. |
| 95 | 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 | -} | |
| 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 | |
| 107 | 109 | |
| 108 | 110 | # The JSON API generally assumes we have a respository, so let it have one. |
| 109 | 111 | repo_init |
| 110 | 112 | |
| 111 | 113 | # Check for basic envelope fields in the result with an error |
| 112 | 114 | fossil_json -expectError |
| 113 | 115 | test_json_envelope json-enverr [concat resultCode fossil timestamp \ |
| 114 | - resultText command procTimeUs procTimeMs] {} | |
| 116 | +resultText command procTimeUs procTimeMs] {} | |
| 115 | 117 | test json-enverr-rc-1 {[dict get $JR resultCode] eq "FOSSIL-3002"} |
| 116 | 118 | |
| 117 | 119 | |
| 118 | 120 | # Check for basic envelope fields in the result with a successful |
| 119 | 121 | # command |
| 120 | 122 | set HAIfields [concat manifestUuid manifestVersion manifestDate \ |
| 121 | - manifestYear releaseVersion releaseVersionNumber \ | |
| 122 | - resultCodeParanoiaLevel jsonApiVersion] | |
| 123 | +manifestYear releaseVersion releaseVersionNumber \ | |
| 124 | +resultCodeParanoiaLevel jsonApiVersion] | |
| 123 | 125 | |
| 124 | 126 | fossil_json HAI |
| 125 | 127 | test_json_envelope_ok json-HAI |
| 126 | 128 | test_json_payload json-HAI $HAIfields {} |
| 129 | +test json-HAI-api {[dict get $JR payload jsonApiVersion] >= 20120713} | |
| 127 | 130 | |
| 128 | 131 | # Check for basic envelope fields in a HTTP result with a successful |
| 129 | 132 | # command |
| 130 | 133 | fossil_http_json /json/HAI |
| 131 | 134 | test_json_envelope_ok json-http-HAI |
| 132 | 135 | test_json_payload json-http-HAI $HAIfields {} |
| 136 | +test json-http-HAI-api {[dict get $JR payload jsonApiVersion] >= 20120713} | |
| 137 | + | |
| 138 | + | |
| 139 | +fossil_json version | |
| 140 | +test_json_envelope_ok json-version | |
| 141 | +test_json_payload json-version $HAIfields {} | |
| 142 | +test json-version-api {[dict get $JR payload jsonApiVersion] >= 20120713} | |
| 133 | 143 | |
| 134 | 144 | #### ARTIFACT |
| 135 | 145 | |
| 136 | 146 | # sha1 of 0 bytes and a file to match in a commit |
| 137 | 147 | set UUID_empty da39a3ee5e6b4b0d3255bfef95601890afd80709 |
| @@ -142,11 +152,11 @@ | ||
| 142 | 152 | # json artifact (checkin) |
| 143 | 153 | fossil_json [concat artifact tip] |
| 144 | 154 | test_json_envelope_ok json-artifact |
| 145 | 155 | test json-artifact-checkin {[dict get $JR payload type] eq "checkin"} |
| 146 | 156 | test_json_payload json-artifact \ |
| 147 | - [concat type uuid isLeaf timestamp user comment parents tags files] {} | |
| 157 | +[concat type uuid isLeaf timestamp user comment parents tags files] {} | |
| 148 | 158 | |
| 149 | 159 | # json artifact (file) |
| 150 | 160 | fossil_json [concat artifact $UUID_empty] |
| 151 | 161 | test_json_envelope_ok json-artifact |
| 152 | 162 | test json-artifact-file {[dict get $JR payload type] eq "file"} |
| @@ -168,8 +178,9 @@ | ||
| 168 | 178 | #### TAGS |
| 169 | 179 | #### TICKETS |
| 170 | 180 | #### TICKET REPORTS |
| 171 | 181 | #### TIMELINE |
| 172 | 182 | #### USER MANAGEMENT |
| 173 | -#### VERSION AKA HAI | |
| 174 | 183 | #### WIKI |
| 175 | 184 | #### UNAVOIDABLE MISC |
| 185 | + | |
| 186 | + | |
| 176 | 187 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -1,7 +1,7 @@ | |
| 1 | # |
| 2 | # Copyright (c) 2011 D. Richard Hipp |
| 3 | # |
| 4 | # This program is free software; you can redistribute it and/or |
| 5 | # modify it under the terms of the Simplified BSD License (also |
| 6 | # known as the "2-Clause License" or "FreeBSD License".) |
| 7 | # |
| @@ -44,94 +44,104 @@ | |
| 44 | # RESULT to the response text, and JR to a Tcl dict conversion of the |
| 45 | # response body. |
| 46 | # |
| 47 | # Returns "200" or "500". |
| 48 | proc fossil_json {args} { |
| 49 | global RESULT JR |
| 50 | uplevel 1 fossil json {*}$args |
| 51 | set JR [::json::json2dict $RESULT] |
| 52 | return "200" |
| 53 | } |
| 54 | |
| 55 | # Use the HTTP interface to fetch a JSON API URL. Sets the globals |
| 56 | # RESULT to the HTTP response body, and JR to a Tcl dict conversion of |
| 57 | # the response body. |
| 58 | # |
| 59 | # Returns the status code from the HTTP header. |
| 60 | proc fossil_http_json {url} { |
| 61 | global RESULT JR |
| 62 | set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil" |
| 63 | set RESULT [fossil_maybe_answer $request http] |
| 64 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 65 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 66 | if {$status eq "200"} { |
| 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 | } |
| 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 | # The JSON API generally assumes we have a respository, so let it have one. |
| 109 | repo_init |
| 110 | |
| 111 | # Check for basic envelope fields in the result with an error |
| 112 | fossil_json -expectError |
| 113 | test_json_envelope json-enverr [concat resultCode fossil timestamp \ |
| 114 | resultText command procTimeUs procTimeMs] {} |
| 115 | test json-enverr-rc-1 {[dict get $JR resultCode] eq "FOSSIL-3002"} |
| 116 | |
| 117 | |
| 118 | # Check for basic envelope fields in the result with a successful |
| 119 | # command |
| 120 | set HAIfields [concat manifestUuid manifestVersion manifestDate \ |
| 121 | manifestYear releaseVersion releaseVersionNumber \ |
| 122 | resultCodeParanoiaLevel jsonApiVersion] |
| 123 | |
| 124 | fossil_json HAI |
| 125 | test_json_envelope_ok json-HAI |
| 126 | test_json_payload json-HAI $HAIfields {} |
| 127 | |
| 128 | # Check for basic envelope fields in a HTTP result with a successful |
| 129 | # command |
| 130 | fossil_http_json /json/HAI |
| 131 | test_json_envelope_ok json-http-HAI |
| 132 | test_json_payload json-http-HAI $HAIfields {} |
| 133 | |
| 134 | #### ARTIFACT |
| 135 | |
| 136 | # sha1 of 0 bytes and a file to match in a commit |
| 137 | set UUID_empty da39a3ee5e6b4b0d3255bfef95601890afd80709 |
| @@ -142,11 +152,11 @@ | |
| 142 | # json artifact (checkin) |
| 143 | fossil_json [concat artifact tip] |
| 144 | test_json_envelope_ok json-artifact |
| 145 | test json-artifact-checkin {[dict get $JR payload type] eq "checkin"} |
| 146 | test_json_payload json-artifact \ |
| 147 | [concat type uuid isLeaf timestamp user comment parents tags files] {} |
| 148 | |
| 149 | # json artifact (file) |
| 150 | fossil_json [concat artifact $UUID_empty] |
| 151 | test_json_envelope_ok json-artifact |
| 152 | test json-artifact-file {[dict get $JR payload type] eq "file"} |
| @@ -168,8 +178,9 @@ | |
| 168 | #### TAGS |
| 169 | #### TICKETS |
| 170 | #### TICKET REPORTS |
| 171 | #### TIMELINE |
| 172 | #### USER MANAGEMENT |
| 173 | #### VERSION AKA HAI |
| 174 | #### WIKI |
| 175 | #### UNAVOIDABLE MISC |
| 176 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -1,7 +1,7 @@ | |
| 1 | # |
| 2 | # Copyright (c) 2016 D. Richard Hipp |
| 3 | # |
| 4 | # This program is free software; you can redistribute it and/or |
| 5 | # modify it under the terms of the Simplified BSD License (also |
| 6 | # known as the "2-Clause License" or "FreeBSD License".) |
| 7 | # |
| @@ -44,94 +44,104 @@ | |
| 44 | # RESULT to the response text, and JR to a Tcl dict conversion of the |
| 45 | # response body. |
| 46 | # |
| 47 | # Returns "200" or "500". |
| 48 | proc fossil_json {args} { |
| 49 | global RESULT JR |
| 50 | uplevel 1 fossil json {*}$args |
| 51 | set JR [::json::json2dict $RESULT] |
| 52 | return "200" |
| 53 | } |
| 54 | |
| 55 | # Use the HTTP interface to fetch a JSON API URL. Sets the globals |
| 56 | # RESULT to the HTTP response body, and JR to a Tcl dict conversion of |
| 57 | # the response body. |
| 58 | # |
| 59 | # Returns the status code from the HTTP header. |
| 60 | proc fossil_http_json {url} { |
| 61 | global RESULT JR |
| 62 | set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil" |
| 63 | set RESULT [fossil_maybe_answer $request http] |
| 64 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 65 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 66 | if {$status eq "200"} { |
| 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 | } |
| 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. |
| 111 | repo_init |
| 112 | |
| 113 | # Check for basic envelope fields in the result with an error |
| 114 | fossil_json -expectError |
| 115 | test_json_envelope json-enverr [concat resultCode fossil timestamp \ |
| 116 | resultText command procTimeUs procTimeMs] {} |
| 117 | test json-enverr-rc-1 {[dict get $JR resultCode] eq "FOSSIL-3002"} |
| 118 | |
| 119 | |
| 120 | # Check for basic envelope fields in the result with a successful |
| 121 | # command |
| 122 | set HAIfields [concat manifestUuid manifestVersion manifestDate \ |
| 123 | manifestYear releaseVersion releaseVersionNumber \ |
| 124 | resultCodeParanoiaLevel jsonApiVersion] |
| 125 | |
| 126 | fossil_json HAI |
| 127 | test_json_envelope_ok json-HAI |
| 128 | test_json_payload json-HAI $HAIfields {} |
| 129 | test json-HAI-api {[dict get $JR payload jsonApiVersion] >= 20120713} |
| 130 | |
| 131 | # Check for basic envelope fields in a HTTP result with a successful |
| 132 | # command |
| 133 | fossil_http_json /json/HAI |
| 134 | test_json_envelope_ok json-http-HAI |
| 135 | test_json_payload json-http-HAI $HAIfields {} |
| 136 | test json-http-HAI-api {[dict get $JR payload jsonApiVersion] >= 20120713} |
| 137 | |
| 138 | |
| 139 | fossil_json version |
| 140 | test_json_envelope_ok json-version |
| 141 | test_json_payload json-version $HAIfields {} |
| 142 | test json-version-api {[dict get $JR payload jsonApiVersion] >= 20120713} |
| 143 | |
| 144 | #### ARTIFACT |
| 145 | |
| 146 | # sha1 of 0 bytes and a file to match in a commit |
| 147 | set UUID_empty da39a3ee5e6b4b0d3255bfef95601890afd80709 |
| @@ -142,11 +152,11 @@ | |
| 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"} |
| @@ -168,8 +178,9 @@ | |
| 178 | #### TAGS |
| 179 | #### TICKETS |
| 180 | #### TICKET REPORTS |
| 181 | #### TIMELINE |
| 182 | #### USER MANAGEMENT |
| 183 | #### WIKI |
| 184 | #### UNAVOIDABLE MISC |
| 185 | |
| 186 | |
| 187 |