rewrite tests

This commit is contained in:
aler9
2021-03-13 16:57:37 +01:00
parent 9be2e5f4ed
commit cb6684d3cf
6 changed files with 1210 additions and 701 deletions

53
gortsplib_test.go Normal file
View File

@@ -0,0 +1,53 @@
package gortsplib
import (
"os"
"os/exec"
"strconv"
"time"
)
type container struct {
name string
}
func newContainer(image string, name string, args []string) (*container, error) {
c := &container{
name: name,
}
exec.Command("docker", "kill", "gortsplib-test-"+name).Run()
exec.Command("docker", "wait", "gortsplib-test-"+name).Run()
cmd := []string{"docker", "run",
"--network=host",
"--name=gortsplib-test-" + name,
"gortsplib-test-" + image}
cmd = append(cmd, args...)
ecmd := exec.Command(cmd[0], cmd[1:]...)
ecmd.Stdout = nil
ecmd.Stderr = os.Stderr
err := ecmd.Start()
if err != nil {
return nil, err
}
time.Sleep(1 * time.Second)
return c, nil
}
func (c *container) close() {
exec.Command("docker", "kill", "gortsplib-test-"+c.name).Run()
exec.Command("docker", "wait", "gortsplib-test-"+c.name).Run()
exec.Command("docker", "rm", "gortsplib-test-"+c.name).Run()
}
func (c *container) wait() int {
exec.Command("docker", "wait", "gortsplib-test-"+c.name).Run()
out, _ := exec.Command("docker", "inspect", "gortsplib-test-"+c.name,
"--format={{.State.ExitCode}}").Output()
code, _ := strconv.ParseInt(string(out[:len(out)-1]), 10, 64)
return int(code)
}