Software /
code /
prosody
Annotate
spec/util_envload_spec.lua @ 13014:06453c564141
util.startup: Add prosody.started promise to easily execute code after startup
To avoid a race where server-started fires before the promise function body is
run (on next tick), I moved server-started to fire on the next tick, which
seems sensible anyway.
Errors are logged, I'm not sure if we ought to be doing something more here.
I'm sure we'll find out.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 01 Apr 2023 11:56:38 +0100 |
parent | 11489:37f49d0ad22c |
rev | line source |
---|---|
11489
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 describe("util.envload", function() |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local envload = require "util.envload"; |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 describe("envload()", function() |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 it("works", function() |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 local f, err = envload.envload("return 'hello'", "@test", {}); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 assert.is_function(f, err); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local ok, ret = pcall(f); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 assert.truthy(ok); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 assert.equal("hello", ret); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 end); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 it("lets you pass values in and out", function () |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local f, err = envload.envload("return thisglobal", "@test", { thisglobal = "yes, this one" }); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 assert.is_function(f, err); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local ok, ret = pcall(f); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 assert.truthy(ok); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 assert.equal("yes, this one", ret); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 end); |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 end) |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 -- TODO envloadfile() |
37f49d0ad22c
util.envload: Add basic test of envload()
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 end) |