tests: Move MustAbsPath function to testutils
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
@ -25,14 +25,14 @@ import (
|
|||||||
|
|
||||||
"go.etcd.io/etcd/client/pkg/v3/fileutil"
|
"go.etcd.io/etcd/client/pkg/v3/fileutil"
|
||||||
"go.etcd.io/etcd/pkg/v3/expect"
|
"go.etcd.io/etcd/pkg/v3/expect"
|
||||||
"go.etcd.io/etcd/tests/v3/framework/integration"
|
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
const noOutputLineCount = 2 // cov-enabled binaries emit PASS and coverage count lines
|
const noOutputLineCount = 2 // cov-enabled binaries emit PASS and coverage count lines
|
||||||
|
|
||||||
var (
|
var (
|
||||||
coverDir = integration.MustAbsPath(os.Getenv("COVERDIR"))
|
coverDir = testutils.MustAbsPath(os.Getenv("COVERDIR"))
|
||||||
)
|
)
|
||||||
|
|
||||||
func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string, name string) (*expect.ExpectProcess, error) {
|
func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string, name string) (*expect.ExpectProcess, error) {
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"go.etcd.io/etcd/tests/v3/framework/integration"
|
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -40,13 +40,13 @@ var (
|
|||||||
RevokedCertPath string
|
RevokedCertPath string
|
||||||
RevokedPrivateKeyPath string
|
RevokedPrivateKeyPath string
|
||||||
|
|
||||||
FixturesDir = integration.MustAbsPath("../fixtures")
|
FixturesDir = testutils.MustAbsPath("../fixtures")
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitFlags() {
|
func InitFlags() {
|
||||||
os.Setenv("ETCD_UNSUPPORTED_ARCH", runtime.GOARCH)
|
os.Setenv("ETCD_UNSUPPORTED_ARCH", runtime.GOARCH)
|
||||||
|
|
||||||
binDirDef := integration.MustAbsPath("../../bin")
|
binDirDef := testutils.MustAbsPath("../../bin")
|
||||||
certDirDef := FixturesDir
|
certDirDef := FixturesDir
|
||||||
|
|
||||||
flag.StringVar(&BinDir, "bin-dir", binDirDef, "The directory for store etcd and etcdctl binaries.")
|
flag.StringVar(&BinDir, "bin-dir", binDirDef, "The directory for store etcd and etcdctl binaries.")
|
||||||
|
@ -56,6 +56,7 @@ import (
|
|||||||
"go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc"
|
"go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc"
|
||||||
"go.etcd.io/etcd/server/v3/verify"
|
"go.etcd.io/etcd/server/v3/verify"
|
||||||
framecfg "go.etcd.io/etcd/tests/v3/framework/config"
|
framecfg "go.etcd.io/etcd/tests/v3/framework/config"
|
||||||
|
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
"go.uber.org/zap/zaptest"
|
"go.uber.org/zap/zaptest"
|
||||||
|
|
||||||
@ -87,44 +88,44 @@ var (
|
|||||||
UniqueCount = int32(0)
|
UniqueCount = int32(0)
|
||||||
|
|
||||||
TestTLSInfo = transport.TLSInfo{
|
TestTLSInfo = transport.TLSInfo{
|
||||||
KeyFile: MustAbsPath("../fixtures/server.key.insecure"),
|
KeyFile: testutils.MustAbsPath("../fixtures/server.key.insecure"),
|
||||||
CertFile: MustAbsPath("../fixtures/server.crt"),
|
CertFile: testutils.MustAbsPath("../fixtures/server.crt"),
|
||||||
TrustedCAFile: MustAbsPath("../fixtures/ca.crt"),
|
TrustedCAFile: testutils.MustAbsPath("../fixtures/ca.crt"),
|
||||||
ClientCertAuth: true,
|
ClientCertAuth: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
TestTLSInfoWithSpecificUsage = transport.TLSInfo{
|
TestTLSInfoWithSpecificUsage = transport.TLSInfo{
|
||||||
KeyFile: MustAbsPath("../fixtures/server-serverusage.key.insecure"),
|
KeyFile: testutils.MustAbsPath("../fixtures/server-serverusage.key.insecure"),
|
||||||
CertFile: MustAbsPath("../fixtures/server-serverusage.crt"),
|
CertFile: testutils.MustAbsPath("../fixtures/server-serverusage.crt"),
|
||||||
ClientKeyFile: MustAbsPath("../fixtures/client-clientusage.key.insecure"),
|
ClientKeyFile: testutils.MustAbsPath("../fixtures/client-clientusage.key.insecure"),
|
||||||
ClientCertFile: MustAbsPath("../fixtures/client-clientusage.crt"),
|
ClientCertFile: testutils.MustAbsPath("../fixtures/client-clientusage.crt"),
|
||||||
TrustedCAFile: MustAbsPath("../fixtures/ca.crt"),
|
TrustedCAFile: testutils.MustAbsPath("../fixtures/ca.crt"),
|
||||||
ClientCertAuth: true,
|
ClientCertAuth: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
TestTLSInfoIP = transport.TLSInfo{
|
TestTLSInfoIP = transport.TLSInfo{
|
||||||
KeyFile: MustAbsPath("../fixtures/server-ip.key.insecure"),
|
KeyFile: testutils.MustAbsPath("../fixtures/server-ip.key.insecure"),
|
||||||
CertFile: MustAbsPath("../fixtures/server-ip.crt"),
|
CertFile: testutils.MustAbsPath("../fixtures/server-ip.crt"),
|
||||||
TrustedCAFile: MustAbsPath("../fixtures/ca.crt"),
|
TrustedCAFile: testutils.MustAbsPath("../fixtures/ca.crt"),
|
||||||
ClientCertAuth: true,
|
ClientCertAuth: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
TestTLSInfoExpired = transport.TLSInfo{
|
TestTLSInfoExpired = transport.TLSInfo{
|
||||||
KeyFile: MustAbsPath("./fixtures-expired/server.key.insecure"),
|
KeyFile: testutils.MustAbsPath("./fixtures-expired/server.key.insecure"),
|
||||||
CertFile: MustAbsPath("./fixtures-expired/server.crt"),
|
CertFile: testutils.MustAbsPath("./fixtures-expired/server.crt"),
|
||||||
TrustedCAFile: MustAbsPath("./fixtures-expired/ca.crt"),
|
TrustedCAFile: testutils.MustAbsPath("./fixtures-expired/ca.crt"),
|
||||||
ClientCertAuth: true,
|
ClientCertAuth: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
TestTLSInfoExpiredIP = transport.TLSInfo{
|
TestTLSInfoExpiredIP = transport.TLSInfo{
|
||||||
KeyFile: MustAbsPath("./fixtures-expired/server-ip.key.insecure"),
|
KeyFile: testutils.MustAbsPath("./fixtures-expired/server-ip.key.insecure"),
|
||||||
CertFile: MustAbsPath("./fixtures-expired/server-ip.crt"),
|
CertFile: testutils.MustAbsPath("./fixtures-expired/server-ip.crt"),
|
||||||
TrustedCAFile: MustAbsPath("./fixtures-expired/ca.crt"),
|
TrustedCAFile: testutils.MustAbsPath("./fixtures-expired/ca.crt"),
|
||||||
ClientCertAuth: true,
|
ClientCertAuth: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultTokenJWT = fmt.Sprintf("jwt,pub-key=%s,priv-key=%s,sign-method=RS256,ttl=1s",
|
DefaultTokenJWT = fmt.Sprintf("jwt,pub-key=%s,priv-key=%s,sign-method=RS256,ttl=1s",
|
||||||
MustAbsPath("../fixtures/server.crt"), MustAbsPath("../fixtures/server.key.insecure"))
|
testutils.MustAbsPath("../fixtures/server.crt"), testutils.MustAbsPath("../fixtures/server.key.insecure"))
|
||||||
|
|
||||||
// UniqueNumber is used to generate unique port numbers
|
// UniqueNumber is used to generate unique port numbers
|
||||||
// Should only be accessed via atomic package methods.
|
// Should only be accessed via atomic package methods.
|
||||||
|
@ -16,7 +16,6 @@ package integration
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
grpc_logsettable "github.com/grpc-ecosystem/go-grpc-middleware/logging/settable"
|
grpc_logsettable "github.com/grpc-ecosystem/go-grpc-middleware/logging/settable"
|
||||||
@ -113,14 +112,6 @@ func assertInTestContext(t testutil.TB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func MustAbsPath(path string) string {
|
|
||||||
abs, err := filepath.Abs(path)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return abs
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEmbedConfig(t testing.TB, name string) *embed.Config {
|
func NewEmbedConfig(t testing.TB, name string) *embed.Config {
|
||||||
cfg := embed.NewConfig()
|
cfg := embed.NewConfig()
|
||||||
cfg.Name = name
|
cfg.Name = name
|
||||||
|
25
tests/framework/testutils/path.go
Normal file
25
tests/framework/testutils/path.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright 2022 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.
|
||||||
|
|
||||||
|
package testutils
|
||||||
|
|
||||||
|
import "path/filepath"
|
||||||
|
|
||||||
|
func MustAbsPath(path string) string {
|
||||||
|
abs, err := filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return abs
|
||||||
|
}
|
@ -25,22 +25,23 @@ import (
|
|||||||
"go.etcd.io/etcd/client/pkg/v3/transport"
|
"go.etcd.io/etcd/client/pkg/v3/transport"
|
||||||
"go.etcd.io/etcd/client/v3"
|
"go.etcd.io/etcd/client/v3"
|
||||||
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
|
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
|
||||||
|
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
||||||
clientv3test "go.etcd.io/etcd/tests/v3/integration/clientv3"
|
clientv3test "go.etcd.io/etcd/tests/v3/integration/clientv3"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testTLSInfo = transport.TLSInfo{
|
testTLSInfo = transport.TLSInfo{
|
||||||
KeyFile: integration2.MustAbsPath("../../../fixtures/server.key.insecure"),
|
KeyFile: testutils.MustAbsPath("../../../fixtures/server.key.insecure"),
|
||||||
CertFile: integration2.MustAbsPath("../../../fixtures/server.crt"),
|
CertFile: testutils.MustAbsPath("../../../fixtures/server.crt"),
|
||||||
TrustedCAFile: integration2.MustAbsPath("../../../fixtures/ca.crt"),
|
TrustedCAFile: testutils.MustAbsPath("../../../fixtures/ca.crt"),
|
||||||
ClientCertAuth: true,
|
ClientCertAuth: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
testTLSInfoExpired = transport.TLSInfo{
|
testTLSInfoExpired = transport.TLSInfo{
|
||||||
KeyFile: integration2.MustAbsPath("../../fixtures-expired/server.key.insecure"),
|
KeyFile: testutils.MustAbsPath("../../fixtures-expired/server.key.insecure"),
|
||||||
CertFile: integration2.MustAbsPath("../../fixtures-expired/server.crt"),
|
CertFile: testutils.MustAbsPath("../../fixtures-expired/server.crt"),
|
||||||
TrustedCAFile: integration2.MustAbsPath("../../fixtures-expired/ca.crt"),
|
TrustedCAFile: testutils.MustAbsPath("../../fixtures-expired/ca.crt"),
|
||||||
ClientCertAuth: true,
|
ClientCertAuth: true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -35,13 +35,14 @@ import (
|
|||||||
"go.etcd.io/etcd/client/v3"
|
"go.etcd.io/etcd/client/v3"
|
||||||
"go.etcd.io/etcd/server/v3/embed"
|
"go.etcd.io/etcd/server/v3/embed"
|
||||||
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
|
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
|
||||||
|
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testTLSInfo = transport.TLSInfo{
|
testTLSInfo = transport.TLSInfo{
|
||||||
KeyFile: integration2.MustAbsPath("../../fixtures/server.key.insecure"),
|
KeyFile: testutils.MustAbsPath("../../fixtures/server.key.insecure"),
|
||||||
CertFile: integration2.MustAbsPath("../../fixtures/server.crt"),
|
CertFile: testutils.MustAbsPath("../../fixtures/server.crt"),
|
||||||
TrustedCAFile: integration2.MustAbsPath("../../fixtures/ca.crt"),
|
TrustedCAFile: testutils.MustAbsPath("../../fixtures/ca.crt"),
|
||||||
ClientCertAuth: true,
|
ClientCertAuth: true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
"go.etcd.io/etcd/etcdutl/v3/snapshot"
|
"go.etcd.io/etcd/etcdutl/v3/snapshot"
|
||||||
"go.etcd.io/etcd/server/v3/embed"
|
"go.etcd.io/etcd/server/v3/embed"
|
||||||
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
|
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
|
||||||
|
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
"go.uber.org/zap/zaptest"
|
"go.uber.org/zap/zaptest"
|
||||||
)
|
)
|
||||||
@ -138,7 +139,7 @@ func TestSnapshotV3RestoreMulti(t *testing.T) {
|
|||||||
|
|
||||||
// TestCorruptedBackupFileCheck tests if we can correctly identify a corrupted backup file.
|
// TestCorruptedBackupFileCheck tests if we can correctly identify a corrupted backup file.
|
||||||
func TestCorruptedBackupFileCheck(t *testing.T) {
|
func TestCorruptedBackupFileCheck(t *testing.T) {
|
||||||
dbPath := integration2.MustAbsPath("testdata/corrupted_backup.db")
|
dbPath := testutils.MustAbsPath("testdata/corrupted_backup.db")
|
||||||
integration2.BeforeTest(t)
|
integration2.BeforeTest(t)
|
||||||
if _, err := os.Stat(dbPath); err != nil {
|
if _, err := os.Stat(dbPath); err != nil {
|
||||||
t.Fatalf("test file [%s] does not exist: %v", dbPath, err)
|
t.Fatalf("test file [%s] does not exist: %v", dbPath, err)
|
||||||
|
Reference in New Issue
Block a user