mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests/e2e,etcdctl,etcdmain: Fix go test --tags cov -v ./tests/e2e
This CL fixes: COVERDIR=./coverage PASSES="build_cov" && go test --tags cov -v ./tests/e2e and is part of the effort to make: COVERDIR=coverage PASSES="build_cov cov" ./test fully pass. The args passed to ./bin/etcd_test and ./bin/etcdctl_test binaries were mismatched. The protocol of passing the arguments using environment variables has been replaces with proper passing of flags. How the measurement of coverage by e2e tests works: 1. COVERDIR=./coverage PASSES="build_cov" are generating ./bin/etcd_test and ./bin/etcdctl_test binaries. 2. These binaries are tests (as coverage can be computed only for tests) [see ./main_test.go ./etcdctl/main_test.go], but this tests are running the main logic of the server and uppon termination (or SIGTERM signal) are writting proper .coverprofile files in the $COVERDIR folder. The binaries used to take arguments using env variables, but its not needed any longer. The binaries can consume any command line arguments that either test (so --test.fooo) or the original binary can consume. 3. The tests/e2e (when compiled with the --tags cov) are starting the _test binaries instead of the original binaries, such that the coverage is being collected.
This commit is contained in:
@@ -95,6 +95,19 @@ func init() {
|
||||
)
|
||||
}
|
||||
|
||||
func StartWithError() error {
|
||||
rootCmd.SetUsageFunc(usageFunc)
|
||||
// Make help just show the usage
|
||||
rootCmd.SetHelpTemplate(`{{.UsageString}}`)
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
func Start() {
|
||||
if err := StartWithError(); err != nil {
|
||||
command.ExitWithError(command.ExitError, err)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
cobra.EnablePrefixMatching = true
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright 2017 The etcd Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build cov
|
||||
|
||||
package ctlv3
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"go.etcd.io/etcd/v3/etcdctl/ctlv3/command"
|
||||
)
|
||||
|
||||
func Start() {
|
||||
// ETCDCTL_ARGS=etcdctl_test arg1 arg2...
|
||||
// SetArgs() takes arg1 arg2...
|
||||
rootCmd.SetArgs(strings.Split(os.Getenv("ETCDCTL_ARGS"), "\xe7\xcd")[1:])
|
||||
os.Unsetenv("ETCDCTL_ARGS")
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
command.ExitWithError(command.ExitError, err)
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
// Copyright 2017 The etcd Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build !cov
|
||||
|
||||
package ctlv3
|
||||
|
||||
import "go.etcd.io/etcd/v3/etcdctl/ctlv3/command"
|
||||
|
||||
func Start() {
|
||||
rootCmd.SetUsageFunc(usageFunc)
|
||||
// Make help just show the usage
|
||||
rootCmd.SetHelpTemplate(`{{.UsageString}}`)
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
command.ExitWithError(command.ExitError, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user