← IaC Academy

Lua and tests · 19 / 23

Attach and run a Lua suite

Keep production code and tests separate, and run the actual subject locally.

YOUR TASK

Make this happen

3 steps
  1. Attach tests/pricing.test.lua using content.test.

  2. Make quote multiply quantity by unitPrice.

  3. Check solution to run the attached suite plus the academy’s independent checks.

Read the starter files

main.cococo

script "pricing" {
  name = "academy-pricing"
  role = "SCRIPT"
  content.test = file("tests/pricing.test.lua")
  content = file("scripts/pricing.lua")
}

scripts/pricing.lua

exports.quote = function(quantity: number, unitPrice: number): number
  return quantity + unitPrice
end

tests/pricing.test.lua

local t = require("test")
local subject = require("cococo.subject")

t.it("calculates a quote", function()
  local pricing = subject.load()
  t.expect(pricing.quote(4, 12)):eq(48)
end)