mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Fix coverage tests
2 problems: - spawnCmdWithLogger was not implemented (when built with 'cov' tag) - the logic was depending on relative paths. We change it to absolute to be able to run in the test-specific temporary directories.
This commit is contained in:
@@ -19,31 +19,41 @@ package e2e
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"go.etcd.io/etcd/client/pkg/v3/fileutil"
|
||||
"go.etcd.io/etcd/pkg/v3/expect"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const noOutputLineCount = 2 // cov-enabled binaries emit PASS and coverage count lines
|
||||
|
||||
func spawnCmd(args []string) (*expect.ExpectProcess, error) {
|
||||
return spawnCmdWithLogger(zap.NewNop(), args)
|
||||
}
|
||||
|
||||
func spawnCmdWithLogger(lg *zap.Logger, args []string) (*expect.ExpectProcess, error) {
|
||||
cmd := args[0]
|
||||
env := make([]string, 0)
|
||||
switch cmd {
|
||||
case binPath:
|
||||
cmd = "../../bin/etcd_test"
|
||||
case ctlBinPath:
|
||||
cmd = "../../bin/etcdctl_test"
|
||||
case ctlBinPath + "3":
|
||||
cmd = "../../bin/etcdctl_test"
|
||||
switch {
|
||||
case strings.HasSuffix(cmd, "/etcd"):
|
||||
cmd = cmd + "_test"
|
||||
case strings.HasSuffix(cmd, "/etcdctl"):
|
||||
cmd = cmd + "_test"
|
||||
case strings.HasSuffix(cmd, "/etcdctl3"):
|
||||
cmd = ctlBinPath + "_test"
|
||||
env = append(env, "ETCDCTL_API=3")
|
||||
}
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
covArgs, err := getCovArgs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -52,7 +62,7 @@ func spawnCmd(args []string) (*expect.ExpectProcess, error) {
|
||||
// they must be included in ctl_cov_env.
|
||||
env = append(env, os.Environ()...)
|
||||
all_args := append(args[1:], covArgs...)
|
||||
log.Printf("Executing %v %v", cmd, all_args)
|
||||
lg.Info("spawning process", zap.Strings("args", all_args), zap.String("working-dir", wd))
|
||||
ep, err := expect.NewExpectWithEnv(cmd, all_args, env)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user