Skip to content

Commit

Permalink
Add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mblayman committed Jul 15, 2023
1 parent 3ad8b62 commit ab3372c
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 297 deletions.
2 changes: 1 addition & 1 deletion bin/t
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
luatest
luatest $@
78 changes: 0 additions & 78 deletions tests/application_test.lua

This file was deleted.

31 changes: 0 additions & 31 deletions tests/configuration_test.lua

This file was deleted.

19 changes: 0 additions & 19 deletions tests/fs_test.lua

This file was deleted.

85 changes: 0 additions & 85 deletions tests/main_test.lua

This file was deleted.

22 changes: 0 additions & 22 deletions tests/request_test.lua

This file was deleted.

61 changes: 0 additions & 61 deletions tests/response_test.lua

This file was deleted.

84 changes: 84 additions & 0 deletions tests/test_application.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
local assert = require "luassert"
local spy = require "luassert.spy"

local Application = require "atlas.application"
local Response = require "atlas.response"
local Route = require "atlas.route"
local asgi = require "atlas.test.asgi"

local tests = {}

-- Application constructs an instance
function tests.test_constructor()
local routes = {}
local app = Application(routes)

assert.equal(getmetatable(app), Application)
assert.is_not_nil(app.router)
end

-- Application is callable
function tests.test_callable()
local app = Application({})
local receive = function() end
local called = false
local send = function() called = true end

app(asgi.make_scope(), receive, send)

assert.is_true(called)
end

-- Application handles a full match
function tests.test_full_match()
local routes = {Route("/", function() return Response() end)}
local app = Application(routes)
local receive = function() end
local send = spy.new(function() end)

app(asgi.make_scope(), receive, send)

assert.spy(send).called_with({
type = "http.response.start",
status = 200,
headers = {{"content-type", "text/html"}},
})
end

-- Application handles a partial match
function tests.test_partial_match()
local routes = {Route("/", function() end)}
local app = Application(routes)
local scope = asgi.make_scope()
scope.method = "POST"
local receive = function() end
local send = spy.new(function() end)

app(scope, receive, send)

assert.spy(send).called_with({
type = "http.response.start",
status = 405,
headers = {{"content-type", "text/html"}},
})
end

-- Application handles a none match
function tests.test_none_match()
local routes = {Route("/asdf", function() end)}
local app = Application(routes)
local scope = asgi.make_scope()
scope.method = "POST"
local receive = function() end
local send = spy.new(function() end)

app(scope, receive, send)

assert.spy(send).called_with({
type = "http.response.start",
status = 404,
headers = {{"content-type", "text/html"}},
})
end

return tests

0 comments on commit ab3372c

Please sign in to comment.