mirror of
https://github.com/fatedier/frp.git
synced 2026-01-11 22:23:12 +00:00
new e2e framework (#1835)
This commit is contained in:
59
test/e2e/framework/process.go
Normal file
59
test/e2e/framework/process.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package framework
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/fatedier/frp/test/e2e/pkg/process"
|
||||
flog "github.com/fatedier/frp/utils/log"
|
||||
)
|
||||
|
||||
func GenerateConfigFile(path string, content string) error {
|
||||
return ioutil.WriteFile(path, []byte(content), 0666)
|
||||
}
|
||||
|
||||
// RunProcesses run multiple processes from templates.
|
||||
// The first template should always be frps.
|
||||
func (f *Framework) RunProcesses(serverTemplates []string, clientTemplates []string) {
|
||||
templates := make([]string, 0, len(serverTemplates)+len(clientTemplates))
|
||||
for _, t := range serverTemplates {
|
||||
templates = append(templates, t)
|
||||
}
|
||||
for _, t := range clientTemplates {
|
||||
templates = append(templates, t)
|
||||
}
|
||||
outs, ports, err := f.RenderTemplates(templates)
|
||||
ExpectNoError(err)
|
||||
ExpectTrue(len(templates) > 0)
|
||||
|
||||
f.UsedPorts = ports
|
||||
|
||||
for i := range serverTemplates {
|
||||
path := filepath.Join(f.TempDirectory, fmt.Sprintf("frp-e2e-server-%d", i))
|
||||
err = ioutil.WriteFile(path, []byte(outs[i]), 0666)
|
||||
ExpectNoError(err)
|
||||
flog.Trace("[%s] %s", path, outs[i])
|
||||
p := process.New(TestContext.FRPServerPath, []string{"-c", path})
|
||||
f.serverConfPaths = append(f.serverConfPaths, path)
|
||||
f.serverProcesses = append(f.serverProcesses, p)
|
||||
err = p.Start()
|
||||
ExpectNoError(err)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
for i := range clientTemplates {
|
||||
index := i + len(serverTemplates)
|
||||
path := filepath.Join(f.TempDirectory, fmt.Sprintf("frp-e2e-client-%d", i))
|
||||
err = ioutil.WriteFile(path, []byte(outs[index]), 0666)
|
||||
ExpectNoError(err)
|
||||
flog.Trace("[%s] %s", path, outs[index])
|
||||
p := process.New(TestContext.FRPClientPath, []string{"-c", path})
|
||||
f.clientConfPaths = append(f.clientConfPaths, path)
|
||||
f.clientProcesses = append(f.clientProcesses, p)
|
||||
err = p.Start()
|
||||
ExpectNoError(err)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user