Skip to content

Commit

Permalink
Use JSON3 for tests instead of JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
bluesmoon committed Oct 13, 2023
1 parent fb31bad commit 1a6fd06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ authors = ["Philip Tellis <[email protected]>"]
version = "0.1.3"

[deps]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LibCURL = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
julia = "1.6"
JSON = "0.21.4"
Reexport = "1.2.2"
julia = "1.6"

[extras]
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Test", "JSON3"]
22 changes: 11 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CurlHTTP, Test, JSON
using CurlHTTP, Test, JSON3

gbVerbose = false

Expand All @@ -19,7 +19,7 @@ function test_GET()

@test CURLE_OK == res
@test 200 == http_status
data = JSON.parse(String(databuffer))
data = JSON3.read(databuffer, Dict{String, Any})
@test "https://postman-echo.com/get?foo=bar&baz=zod" == data["url"]
@test Dict("foo" => "bar", "baz" => "zod") == data["args"]
@test haskey(data["headers"], "x-custom-header")
Expand All @@ -39,7 +39,7 @@ function test_GET_debug()
@test CURLE_OK == res
@test 200 == http_status
databuffer = curl.userdata[:databuffer]
data = JSON.parse(String(databuffer))
data = JSON3.read(databuffer, Dict{String, Any})
@test "https://postman-echo.com/get?foo=bar&baz=zod" == data["url"]
@test Dict("foo" => "bar", "baz" => "zod") == data["args"]
@test "" == errormessage
Expand All @@ -61,7 +61,7 @@ function test_GET_reuse()
@test 200 == http_status
@test "" == errormessage
databuffer = curl.userdata[:databuffer]
data = JSON.parse(String(databuffer))
data = JSON3.read(databuffer, Dict{String, Any})
@test "https://postman-echo.com/get?foo=bar&baz=zod" == data["url"]
@test Dict("foo" => "bar", "baz" => "zod") == data["args"]
@test haskey(data["headers"], "x-custom-header")
Expand All @@ -74,7 +74,7 @@ function test_GET_reuse()
@test 200 == http_status
@test "" == errormessage
databuffer = curl.userdata[:databuffer]
data = JSON.parse(String(databuffer))
data = JSON3.read(databuffer, Dict{String, Any})
@test "https://postman-echo.com/get?foo=bear&baz=zeroed" == data["url"]
@test Dict("foo" => "bear", "baz" => "zeroed") == data["args"]
@test haskey(data["headers"], "x-custom-header")
Expand All @@ -95,7 +95,7 @@ function test_GET_useragent()
@test CURLE_OK == res
@test 200 == http_status
databuffer = curl.userdata[:databuffer]
data = JSON.parse(String(databuffer))
data = JSON3.read(databuffer, Dict{String, Any})
@test "https://postman-echo.com/get?foo=bar&baz=zod" == data["url"]
@test Dict("foo" => "bar", "baz" => "zod") == data["args"]
@test "CurlHTTP/0.1" == data["headers"]["user-agent"]
Expand All @@ -119,7 +119,7 @@ function test_DELETE()

@test CURLE_OK == res
@test 200 == http_status
data = JSON.parse(String(databuffer))
data = JSON3.read(databuffer, Dict{String, Any})
@test "https://postman-echo.com/delete?foo=bar&baz=zod" == data["url"]
@test Dict("foo" => "bar", "baz" => "zod") == data["args"]
@test isnothing(data["json"])
Expand Down Expand Up @@ -222,8 +222,8 @@ function test_writeCB()
@test CURLE_OK == res
@test 200 == http_status
@test 2 * length(requestBody) < length(databuffer) # We expect requestBody to be repeated twice in the response
data = JSON.parse(String(databuffer))
reqB = JSON.parse(requestBody)
data = JSON3.read(databuffer, Dict{String, Any})
reqB = JSON3.read(requestBody, Dict{String, Any})
@test reqB == data["data"] == data["json"]
@test "CurlHTTP Test" == data["headers"]["user-agent"]
@test "" == errormessage
Expand Down Expand Up @@ -304,8 +304,8 @@ function test_multi_writeCB()

@test 2 * length(r[:requestBody]) < length(r[:databuffer])

data = JSON.parse(String(r[:databuffer]))
reqB = JSON.parse(r[:requestBody])
data = JSON3.read(String(r[:databuffer]), Dict{String, Any})
reqB = JSON3.read(r[:requestBody], Dict{String, Any})
@test reqB == data["data"] == data["json"]

@test haskey(r, :errormessage)
Expand Down

0 comments on commit 1a6fd06

Please sign in to comment.