Fossil

Check-in [c4f8d88f]
Login

Check-in [c4f8d88f]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rberteig-json-test
Files: files | file ages | folders
SHA1: c4f8d88fd91a8925f832e1b58228cdf7f8aff3c1
User & Date: Ross 2016-01-27 00:44:23.598
Context
2016-01-27
01:28
Merged from trunk to pick up test case edits made there, along with recent cosmetic fixes. ... (check-in: 4e0e141e user: rberteig tags: rberteig-json-test)
00:44
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. ... (check-in: c4f8d88f user: Ross tags: rberteig-json-test)
2016-01-26
02:45
Minor spacing fix. ... (check-in: 2ff6ceb9 user: mistachkin tags: rberteig-json-test)
Changes
Unified Diff Ignore Whitespace Patch
Changes to test/json.test.
1
2
3
4
5
6
7
8
9
#
# Copyright (c) 2011 D. Richard Hipp
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the Simplified BSD License (also
# known as the "2-Clause License" or "FreeBSD License".)
#
# This program is distributed in the hope that it will be useful,
# but without any warranty; without even the implied warranty of

|







1
2
3
4
5
6
7
8
9
#
# Copyright (c) 2016 D. Richard Hipp
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the Simplified BSD License (also
# known as the "2-Clause License" or "FreeBSD License".)
#
# This program is distributed in the hope that it will be useful,
# but without any warranty; without even the implied warranty of
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

# Use the CLI interface to execute a JSON command. Sets the global
# RESULT to the response text, and JR to a Tcl dict conversion of the
# response body.
#
# Returns "200" or "500".
proc fossil_json {args} {
    global RESULT JR
    uplevel 1 fossil json {*}$args
    set JR [::json::json2dict $RESULT]
    return "200"
}

# Use the HTTP interface to fetch a JSON API URL. Sets the globals
# RESULT to the HTTP response body, and JR to a Tcl dict conversion of
# the response body.
# 
# Returns the status code from the HTTP header.
proc fossil_http_json {url} {
    global RESULT JR
    set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil"
    set RESULT [fossil_maybe_answer $request http]
    regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body
    regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg
    if {$status eq "200"} {
	set JR [::json::json2dict $body]
    }
    return $status
}

# Inspect the envelope part of a returned JSON structure to confirm
# that it has specific fields and that it lacks specific fields.
proc test_json_envelope {testname okfields badfields} {
    global JR
    set i 1
    foreach f $okfields {
	test "$testname-$i" {[dict exists $JR $f]}
	incr i
    }
    foreach f $badfields {
	test "$testname-$i" {![dict exists $JR $f]}
	incr i
    }
}

# Inspect the envelope of a normal successful result
proc test_json_envelope_ok {testname} {
    test_json_envelope $testname [concat fossil timestamp command procTimeUs \
	procTimeMs payload] [concat resultCode resultText]
}

# Inspect the payload of a successful result to confirm that it has
# specific fields and that it lacks specific fields.
proc test_json_payload {testname okfields badfields} {
    global JR
    set i 1
    foreach f $okfields {
	test "$testname-P-$i" {[dict exists $JR payload $f]}
	incr i
    }
    foreach f $badfields {
	test "$testname-P-$i" {![dict exists $JR payload $f]}
	incr i
    }
}



# The JSON API generally assumes we have a respository, so let it have one.
repo_init

# Check for basic envelope fields in the result with an error
fossil_json -expectError
test_json_envelope json-enverr [concat resultCode fossil timestamp \
    resultText command procTimeUs procTimeMs] {}
test json-enverr-rc-1 {[dict get $JR resultCode] eq "FOSSIL-3002"}


# Check for basic envelope fields in the result with a successful
# command
set HAIfields [concat manifestUuid manifestVersion manifestDate \
    manifestYear releaseVersion releaseVersionNumber \
    resultCodeParanoiaLevel jsonApiVersion]

fossil_json HAI
test_json_envelope_ok json-HAI
test_json_payload json-HAI $HAIfields {}


# Check for basic envelope fields in a HTTP result with a successful
# command
fossil_http_json /json/HAI
test_json_envelope_ok json-http-HAI
test_json_payload json-http-HAI $HAIfields {}








#### ARTIFACT

# sha1 of 0 bytes and a file to match in a commit
set UUID_empty da39a3ee5e6b4b0d3255bfef95601890afd80709
write_file empty ""
fossil add empty
fossil ci -m "empty file"

# json artifact (checkin)
fossil_json [concat artifact tip]
test_json_envelope_ok json-artifact
test json-artifact-checkin {[dict get $JR payload type] eq "checkin"}
test_json_payload json-artifact \
    [concat type uuid isLeaf timestamp user comment parents tags files] {}

# json artifact (file)
fossil_json [concat artifact $UUID_empty]
test_json_envelope_ok json-artifact
test json-artifact-file {[dict get $JR payload type] eq "file"}
test_json_payload json-artifact [concat type uuid size checkins] {}








|
|
|
|








|
|
|
|
|
|
|
|
|





|
|
|
|
|
|
|
|
|
|




|
|





|
|
|
|
|
|
|
|
|
|

>
>







|






|
|




>






>
>
>
>
>
>
>














|







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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

# Use the CLI interface to execute a JSON command. Sets the global
# RESULT to the response text, and JR to a Tcl dict conversion of the
# response body.
#
# Returns "200" or "500".
proc fossil_json {args} {
  global RESULT JR
  uplevel 1 fossil json {*}$args
  set JR [::json::json2dict $RESULT]
  return "200"
}

# Use the HTTP interface to fetch a JSON API URL. Sets the globals
# RESULT to the HTTP response body, and JR to a Tcl dict conversion of
# the response body.
# 
# Returns the status code from the HTTP header.
proc fossil_http_json {url} {
  global RESULT JR
  set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil"
  set RESULT [fossil_maybe_answer $request http]
  regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body
  regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg
  if {$status eq "200"} {
    set JR [::json::json2dict $body]
  }
  return $status
}

# Inspect the envelope part of a returned JSON structure to confirm
# that it has specific fields and that it lacks specific fields.
proc test_json_envelope {testname okfields badfields} {
  global JR
  set i 1
  foreach f $okfields {
    test "$testname-$i" {[dict exists $JR $f]}
    incr i
  }
  foreach f $badfields {
    test "$testname-$i" {![dict exists $JR $f]}
    incr i
  }
}

# Inspect the envelope of a normal successful result
proc test_json_envelope_ok {testname} {
  test_json_envelope $testname [concat fossil timestamp command procTimeUs \
  procTimeMs payload] [concat resultCode resultText]
}

# Inspect the payload of a successful result to confirm that it has
# specific fields and that it lacks specific fields.
proc test_json_payload {testname okfields badfields} {
  global JR
  set i 1
  foreach f $okfields {
    test "$testname-P-$i" {[dict exists $JR payload $f]}
    incr i
  }
  foreach f $badfields {
    test "$testname-P-$i" {![dict exists $JR payload $f]}
    incr i
  }
}

#### VERSION AKA HAI

# The JSON API generally assumes we have a respository, so let it have one.
repo_init

# Check for basic envelope fields in the result with an error
fossil_json -expectError
test_json_envelope json-enverr [concat resultCode fossil timestamp \
resultText command procTimeUs procTimeMs] {}
test json-enverr-rc-1 {[dict get $JR resultCode] eq "FOSSIL-3002"}


# Check for basic envelope fields in the result with a successful
# command
set HAIfields [concat manifestUuid manifestVersion manifestDate \
manifestYear releaseVersion releaseVersionNumber \
resultCodeParanoiaLevel jsonApiVersion]

fossil_json HAI
test_json_envelope_ok json-HAI
test_json_payload json-HAI $HAIfields {}
test json-HAI-api {[dict get $JR payload jsonApiVersion] >= 20120713}

# Check for basic envelope fields in a HTTP result with a successful
# command
fossil_http_json /json/HAI
test_json_envelope_ok json-http-HAI
test_json_payload json-http-HAI $HAIfields {}
test json-http-HAI-api {[dict get $JR payload jsonApiVersion] >= 20120713}


fossil_json version
test_json_envelope_ok json-version
test_json_payload json-version $HAIfields {}
test json-version-api {[dict get $JR payload jsonApiVersion] >= 20120713}

#### ARTIFACT

# sha1 of 0 bytes and a file to match in a commit
set UUID_empty da39a3ee5e6b4b0d3255bfef95601890afd80709
write_file empty ""
fossil add empty
fossil ci -m "empty file"

# json artifact (checkin)
fossil_json [concat artifact tip]
test_json_envelope_ok json-artifact
test json-artifact-checkin {[dict get $JR payload type] eq "checkin"}
test_json_payload json-artifact \
[concat type uuid isLeaf timestamp user comment parents tags files] {}

# json artifact (file)
fossil_json [concat artifact $UUID_empty]
test_json_envelope_ok json-artifact
test json-artifact-file {[dict get $JR payload type] eq "file"}
test_json_payload json-artifact [concat type uuid size checkins] {}

166
167
168
169
170
171
172
173
174
175


#### STATS
#### STATUS
#### TAGS
#### TICKETS
#### TICKET REPORTS
#### TIMELINE
#### USER MANAGEMENT
#### VERSION AKA HAI
#### WIKI
#### UNAVOIDABLE MISC









<


>
>
176
177
178
179
180
181
182

183
184
185
186
#### STATS
#### STATUS
#### TAGS
#### TICKETS
#### TICKET REPORTS
#### TIMELINE
#### USER MANAGEMENT

#### WIKI
#### UNAVOIDABLE MISC