Skip to content

Commit

Permalink
test(nim): add ping api test
Browse files Browse the repository at this point in the history
  • Loading branch information
airscripts authored and Francesco Sardone committed Jan 11, 2023
1 parent 7b5e471 commit 502f509
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions nim/testament/tests/base/api.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import std/unittest
import std/asyncdispatch

from std/strformat import fmt

from std/httpclient import
request,
HttpGet,
AsyncResponse,
AsyncHttpClient,
newAsyncHttpClient

from ../constants as constants import
PORT,
PING_API,
HOSTNAME,
PROTOCOL,
STATUS_OK

const SERVER_ADDRESS: string =
fmt"{constants.PROTOCOL}://{constants.HOSTNAME}:{constants.PORT}"

suite "APIs Test Suite":
var client: AsyncHttpClient
var clientPtr: ptr AsyncHttpClient = client.addr

setup:
client = newAsyncHttpClient()

teardown:
reset(client)
dealloc clientPtr

test "Ping API":
proc ping() {.async.} =
let response: AsyncResponse = await client.request(
url=fmt"{SERVER_ADDRESS}{PING_API}",
httpMethod=HttpGet
)

check response.status == constants.STATUS_OK

waitFor(ping())

0 comments on commit 502f509

Please sign in to comment.