forked from vadv/gopher-lua-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
44 lines (36 loc) · 992 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package prometheus_client_test
import (
"log"
"github.com/alexjx/gopher-lua-libs/http"
prometheus "github.com/alexjx/gopher-lua-libs/prometheus/client"
"github.com/alexjx/gopher-lua-libs/time"
lua "github.com/yuin/gopher-lua"
)
// prometheus:start(string)
func ExampleStart() {
state := lua.NewState()
prometheus.Preload(state)
time.Preload(state)
http.Preload(state)
source := `
local prometheus = require("prometheus")
local time = require("time")
local http = require("http_client")
local pp = prometheus.register(":18080")
pp:start()
time.sleep(1)
local client = http.client({timeout=5})
local request = http.request("GET", "http://127.0.0.1:18080/")
local result = client:do_request(request)
print(result.code)
local request = http.request("GET", "http://127.0.0.1:18080/metrics")
local result = client:do_request(request)
print(result.code)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// 404
// 200
}