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.

Ross 2016-01-27 00:44 rberteig-json-test
Commit c4f8d88fd91a8925f832e1b58228cdf7f8aff3c1
1 file changed +53 -42
+53 -42
--- test/json.test
+++ test/json.test
@@ -1,7 +1,7 @@
11
#
2
-# Copyright (c) 2011 D. Richard Hipp
2
+# Copyright (c) 2016 D. Richard Hipp
33
#
44
# This program is free software; you can redistribute it and/or
55
# modify it under the terms of the Simplified BSD License (also
66
# known as the "2-Clause License" or "FreeBSD License".)
77
#
@@ -44,94 +44,104 @@
4444
# RESULT to the response text, and JR to a Tcl dict conversion of the
4545
# response body.
4646
#
4747
# Returns "200" or "500".
4848
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"
5353
}
5454
5555
# Use the HTTP interface to fetch a JSON API URL. Sets the globals
5656
# RESULT to the HTTP response body, and JR to a Tcl dict conversion of
5757
# the response body.
5858
#
5959
# Returns the status code from the HTTP header.
6060
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
7070
}
7171
7272
# Inspect the envelope part of a returned JSON structure to confirm
7373
# that it has specific fields and that it lacks specific fields.
7474
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
+ }
8585
}
8686
8787
# Inspect the envelope of a normal successful result
8888
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]
9191
}
9292
9393
# Inspect the payload of a successful result to confirm that it has
9494
# specific fields and that it lacks specific fields.
9595
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
107109
108110
# The JSON API generally assumes we have a respository, so let it have one.
109111
repo_init
110112
111113
# Check for basic envelope fields in the result with an error
112114
fossil_json -expectError
113115
test_json_envelope json-enverr [concat resultCode fossil timestamp \
114
- resultText command procTimeUs procTimeMs] {}
116
+resultText command procTimeUs procTimeMs] {}
115117
test json-enverr-rc-1 {[dict get $JR resultCode] eq "FOSSIL-3002"}
116118
117119
118120
# Check for basic envelope fields in the result with a successful
119121
# command
120122
set HAIfields [concat manifestUuid manifestVersion manifestDate \
121
- manifestYear releaseVersion releaseVersionNumber \
122
- resultCodeParanoiaLevel jsonApiVersion]
123
+manifestYear releaseVersion releaseVersionNumber \
124
+resultCodeParanoiaLevel jsonApiVersion]
123125
124126
fossil_json HAI
125127
test_json_envelope_ok json-HAI
126128
test_json_payload json-HAI $HAIfields {}
129
+test json-HAI-api {[dict get $JR payload jsonApiVersion] >= 20120713}
127130
128131
# Check for basic envelope fields in a HTTP result with a successful
129132
# command
130133
fossil_http_json /json/HAI
131134
test_json_envelope_ok json-http-HAI
132135
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}
133143
134144
#### ARTIFACT
135145
136146
# sha1 of 0 bytes and a file to match in a commit
137147
set UUID_empty da39a3ee5e6b4b0d3255bfef95601890afd80709
@@ -142,11 +152,11 @@
142152
# json artifact (checkin)
143153
fossil_json [concat artifact tip]
144154
test_json_envelope_ok json-artifact
145155
test json-artifact-checkin {[dict get $JR payload type] eq "checkin"}
146156
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] {}
148158
149159
# json artifact (file)
150160
fossil_json [concat artifact $UUID_empty]
151161
test_json_envelope_ok json-artifact
152162
test json-artifact-file {[dict get $JR payload type] eq "file"}
@@ -168,8 +178,9 @@
168178
#### TAGS
169179
#### TICKETS
170180
#### TICKET REPORTS
171181
#### TIMELINE
172182
#### USER MANAGEMENT
173
-#### VERSION AKA HAI
174183
#### WIKI
175184
#### UNAVOIDABLE MISC
185
+
186
+
176187
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button