github.com/lfch/etcd-io/tests/v3@v3.0.0-20221004140520-eac99acd3e9d/framework/e2e/etcd_spawn_nocov.go (about)

     1  // Copyright 2017 The etcd Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  //go:build !cov
    16  // +build !cov
    17  
    18  package e2e
    19  
    20  import (
    21  	"os"
    22  	"strings"
    23  
    24  	"go.uber.org/zap"
    25  
    26  	"github.com/lfch/etcd-io/pkg/v3/expect"
    27  )
    28  
    29  const noOutputLineCount = 0 // regular binaries emit no extra lines
    30  
    31  func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string, name string) (*expect.ExpectProcess, error) {
    32  	wd, err := os.Getwd()
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  	env := mergeEnvVariables(envVars)
    37  	if strings.HasSuffix(args[0], "/etcdctl3") {
    38  		env = append(env, "ETCDCTL_API=3")
    39  		lg.Info("spawning process with ETCDCTL_API=3",
    40  			zap.Strings("args", args),
    41  			zap.String("working-dir", wd),
    42  			zap.String("name", name),
    43  			zap.Strings("environment-variables", env))
    44  		return expect.NewExpectWithEnv(CtlBinPath, args[1:], env, name)
    45  	}
    46  	lg.Info("spawning process",
    47  		zap.Strings("args", args),
    48  		zap.String("working-dir", wd),
    49  		zap.String("name", name),
    50  		zap.Strings("environment-variables", env))
    51  	return expect.NewExpectWithEnv(args[0], args[1:], env, name)
    52  }