This file contains hidden or 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
| version: '3.4' | |
| services: | |
| test: | |
| image: imega/busted | |
| environment: | |
| - LUA_PATH=/app/?.lua | |
| command: busted /app | |
| volumes: | |
| - ./lib:/app/lib |
This file contains hidden or 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
| describe("app module", function () | |
| describe("run() function", function () | |
| local check_env_stub = stub() | |
| setup(function () | |
| package.preload["lib.check_env"] = function () | |
| return check_env_stub | |
| end | |
| end) | |
This file contains hidden or 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
| local check_env = require "lib.check_env" | |
| local sum = require "lib.sum" | |
| local app = {} | |
| app.run = function () | |
| if check_env() == true then | |
| return string.format("Result of 10 + 20 is %s", sum(10, 20)) | |
| else | |
| return nil |
This file contains hidden or 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
| describe("check_env module", function () | |
| local check_env = require "lib.check_env" | |
| before_each(function() | |
| stub(os, "getenv") | |
| end) | |
| after_each(function () | |
| os.getenv:revert() | |
| end) |
This file contains hidden or 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
| return function () | |
| if os.getenv("RUN_SUM") == "1" then | |
| return true | |
| else | |
| return false | |
| end | |
| end |
This file contains hidden or 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
| describe("sum module", function () | |
| it("should return the sum of two numbers", function () | |
| local sum = require "lib.sum" | |
| local result = sum(100, 200) | |
| assert.are.same(300, result) | |
| end) | |
| end) |
This file contains hidden or 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
| return function (a, b) | |
| return a + b | |
| end |
This file contains hidden or 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
| setFakeTime(); | |
| const startTimeMon = performance.now(); // set startTime with monotonic clock | |
| setImmediate(() => { | |
| correctTimeNTP(); // synchronise the clock | |
| }); | |
| await doSomething(); | |
| const endTimeMon = performance.now(); // set endTime with monotonic clock |
This file contains hidden or 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
| setFakeTime(); // set time to 1 min ahead of actual time | |
| const startTimeToD = Date.now(); // set startTime with time-of-day clock | |
| setImmediate(() => { | |
| correctTimeNTP(); // synchronise the clock | |
| }); | |
| await doSomething(); |
This file contains hidden or 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
| const start = Date.now() | |
| doSomething() | |
| const end = Date.now() | |
| const durationMs = end - start; |
NewerOlder