-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add unit tests for server files * opt copied luaunit library out of stylua checking * verify ci fails on test failure * Remove intentionally broken test
- Loading branch information
1 parent
c65232a
commit ef74f4a
Showing
12 changed files
with
3,713 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Run unit tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
name: Run unit tests | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up lua | ||
uses: leafo/gh-actions-lua@v10 | ||
with: | ||
luaVersion: "5.1.5" | ||
|
||
- name: test | ||
run: | | ||
lua ./Scripts/DCS-BIOS/test/TestSuite.lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ | |
|
||
# opt-in test code | ||
!/Scripts/DCS-BIOS/test | ||
# opt-out copy-pasted test library code | ||
/Scripts/DCS-BIOS/test/ext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"recommendations": [ | ||
"johnnymorganz.stylua" | ||
"johnnymorganz.stylua", | ||
"tomblind.local-lua-debugger-vscode", | ||
"sumneko.lua" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Run unit tests", | ||
"type": "lua-local", | ||
"request": "launch", | ||
"program": { | ||
"lua": "lua5.1", | ||
"file": "./Scripts/DCS-BIOS/test/TestSuite.lua" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
local MockSocket = require("MockSocket") | ||
local ReadableConnection = require("ReadableConnection") | ||
local TCPConnection = require("TCPConnection") | ||
local TCPServer = require("TCPServer") | ||
local UDPListener = require("UDPListener") | ||
local UDPSender = require("UDPSender") | ||
local UDPServer = require("UDPServer") | ||
|
||
local lu = require("luaunit") | ||
|
||
-- Unit testing starts | ||
--- @class TestServer | ||
TestServer = {} | ||
|
||
function TestServer:testCreateReadableConnection() | ||
local listener = ReadableConnection:new("*", 0, MockSocket:new(), function() end) | ||
listener:appendToBuffer("foo") | ||
end | ||
|
||
function TestServer:testCreateUDPListener() | ||
local linesProcessed = {} | ||
local line1 = "line 1" | ||
local line2 = "line 2" | ||
local listener = UDPListener:new("*", 0, MockSocket:new(), function(val) | ||
table.insert(linesProcessed, val) | ||
end) | ||
listener:init() | ||
listener:appendToBuffer(line1 .. "\n" .. line2 .. "\n") -- add two lines of data to the buffer | ||
listener:receive() -- should process buffer line-by-line | ||
lu.assertEquals(linesProcessed[1], line1) | ||
lu.assertEquals(linesProcessed[2], line2) | ||
listener:close() | ||
end | ||
|
||
function TestServer:testCreateUDPSender() | ||
local sender = UDPSender:new("*", 0, MockSocket:new()) | ||
sender:init() | ||
sender:send("foo") | ||
sender:close() | ||
end | ||
|
||
function TestServer:testCreateUDPServer() | ||
local server = UDPServer:new("*", 0, "*", 0, MockSocket:new(), function() end) | ||
server:init() | ||
server:step() | ||
server:send("foo") | ||
server:close() | ||
end | ||
|
||
function TestServer:testCreateTCPConnection() | ||
local s = MockSocket:new() | ||
local connection = TCPConnection:new(s.bind("", 0), MockSocket:new(), function() end) | ||
connection:send("foo") | ||
connection:receive() | ||
connection:close() | ||
end | ||
|
||
function TestServer:testCreateTCPServer() | ||
local server = TCPServer:new("*", 0, MockSocket:new(), function() end) | ||
server:init() | ||
server:step() | ||
server:send("foo") | ||
server:close() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package.path = "./Scripts/DCS-BIOS/test/?.lua;" .. package.path | ||
package.path = "./Scripts/DCS-BIOS/test/ext/?.lua;" .. package.path | ||
package.path = "./Scripts/DCS-BIOS/test/io/?.lua;" .. package.path | ||
package.path = "./Scripts/DCS-BIOS/?.lua;" .. package.path | ||
package.path = "./Scripts/DCS-BIOS/lib/?.lua;" .. package.path | ||
package.path = "./Scripts/DCS-BIOS/lib/io/?.lua;" .. package.path | ||
package.path = "./Scripts/DCS-BIOS/lib/modules/?.lua;" .. package.path | ||
package.path = "./Scripts/DCS-BIOS/lib/modules/aircraft_modules/?.lua;" .. package.path | ||
package.path = "./Scripts/DCS-BIOS/lib/modules/common_modules/?.lua;" .. package.path | ||
package.path = "./Scripts/DCS-BIOS/lib/modules/documentation/?.lua;" .. package.path | ||
package.path = "./Scripts/DCS-BIOS/lib/modules/memory_map/?.lua;" .. package.path | ||
|
||
-- global functions that haven't been refactored yet | ||
BIOS = {} | ||
function BIOS.log(str) end -- noop | ||
|
||
require("ServerTest") -- unit tests for tcp/udp server code | ||
|
||
local lu = require("luaunit") | ||
os.exit(lu.LuaUnit:run()) |
Oops, something went wrong.