first commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package lexicomai
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParsePortAndEngine(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
exec string
|
||||
port int
|
||||
engine string
|
||||
}{
|
||||
{"uvicorn per-svc", `ExecStart={ path=/opt/pve/ups/bin/uvicorn ; argv[]=/opt/pve/ups/bin/uvicorn main:app --host 0.0.0.0 --port 6182 ; }`, 6182, "uvicorn"},
|
||||
{"ubicorn shared", `ExecStart={ path=/opt/pve/bin/uvicorn ; argv[]=/opt/pve/bin/uvicorn main:app --host 0.0.0.0 --port 6110 ; }`, 6110, "uvicorn"},
|
||||
{"gunicorn", `ExecStart={ path=/opt/pve/bin/gunicorn ; argv[]=/opt/pve/bin/gunicorn --bind 0.0.0.0:6170 ; }`, 6170, "gunicorn"},
|
||||
{"python api", `ExecStart={ path=/opt/pve/bin/python ; argv[]=/opt/pve/bin/python /opt/ses-sip-gateway-api/api.py ; }`, 0, "python"},
|
||||
{"bwrap", `ExecStart={ path=/usr/bin/bwrap ; argv[]=/usr/bin/bwrap --bind /opt/ses-sip/image / --tmpfs /tmp ; }`, 0, "bwrap"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
port, engine, _ := parsePortAndEngine(c.exec)
|
||||
if port != c.port {
|
||||
t.Errorf("port = %d, want %d", port, c.port)
|
||||
}
|
||||
if engine != c.engine {
|
||||
t.Errorf("engine = %q, want %q", engine, c.engine)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestVenvFromBinary(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"/opt/pve/ups/bin/uvicorn": "/opt/pve/ups",
|
||||
"/opt/pve/bin/uvicorn": "/opt/pve",
|
||||
"": "",
|
||||
}
|
||||
for in, want := range cases {
|
||||
if got := venvFromBinary(in); got != want {
|
||||
t.Errorf("venvFromBinary(%q) = %q, want %q", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestShellQuote(t *testing.T) {
|
||||
if got := shellQuote("a'b"); got != "'a'\\''b'" {
|
||||
t.Errorf("shellQuote(%q) = %q", "a'b", got)
|
||||
}
|
||||
if got := shellQuote("plain"); got != "'plain'" {
|
||||
t.Errorf("shellQuote(%q) = %q", "plain", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJSONString(t *testing.T) {
|
||||
body := `{"info":{"version":"7.005 release","title":"Call List Service"}}`
|
||||
if got := jsonString(body, "version"); got != "7.005 release" {
|
||||
t.Errorf("jsonString(version) = %q", got)
|
||||
}
|
||||
if got := jsonString(body, "title"); got != "Call List Service" {
|
||||
t.Errorf("jsonString(title) = %q", got)
|
||||
}
|
||||
if got := jsonString(body, "missing"); got != "" {
|
||||
t.Errorf("jsonString(missing) = %q, want empty", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user