mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: Move MustAbsPath function to testutils
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
parent
bf6a1d7264
commit
07ca384753
@ -25,14 +25,14 @@ import (
|
||||
|
||||
"go.etcd.io/etcd/client/pkg/v3/fileutil"
|
||||
"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"
|
||||
)
|
||||
|
||||
const noOutputLineCount = 2 // cov-enabled binaries emit PASS and coverage count lines
|
||||
|
||||
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) {
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"go.etcd.io/etcd/tests/v3/framework/integration"
|
||||
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -40,13 +40,13 @@ var (
|
||||
RevokedCertPath string
|
||||
RevokedPrivateKeyPath string
|
||||
|
||||
FixturesDir = integration.MustAbsPath("../fixtures")
|
||||
FixturesDir = testutils.MustAbsPath("../fixtures")
|
||||
)
|
||||
|
||||
func InitFlags() {
|
||||
os.Setenv("ETCD_UNSUPPORTED_ARCH", runtime.GOARCH)
|
||||
|
||||
binDirDef := integration.MustAbsPath("../../bin")
|
||||
binDirDef := testutils.MustAbsPath("../../bin")
|
||||
certDirDef := FixturesDir
|
||||
|
||||
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/verify"
|
||||
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/zaptest"
|
||||
|
||||
@ -87,44 +88,44 @@ var (
|
||||
UniqueCount = int32(0)
|
||||
|
||||
TestTLSInfo = transport.TLSInfo{
|
||||
KeyFile: MustAbsPath("../fixtures/server.key.insecure"),
|
||||
CertFile: MustAbsPath("../fixtures/server.crt"),
|
||||
TrustedCAFile: MustAbsPath("../fixtures/ca.crt"),
|
||||
KeyFile: testutils.MustAbsPath("../fixtures/server.key.insecure"),
|
||||
CertFile: testutils.MustAbsPath("../fixtures/server.crt"),
|
||||
TrustedCAFile: testutils.MustAbsPath("../fixtures/ca.crt"),
|
||||
ClientCertAuth: true,
|
||||
}
|
||||
|
||||
TestTLSInfoWithSpecificUsage = transport.TLSInfo{
|
||||
KeyFile: MustAbsPath("../fixtures/server-serverusage.key.insecure"),
|
||||
CertFile: MustAbsPath("../fixtures/server-serverusage.crt"),
|
||||
ClientKeyFile: MustAbsPath("../fixtures/client-clientusage.key.insecure"),
|
||||
ClientCertFile: MustAbsPath("../fixtures/client-clientusage.crt"),
|
||||
TrustedCAFile: MustAbsPath("../fixtures/ca.crt"),
|
||||
KeyFile: testutils.MustAbsPath("../fixtures/server-serverusage.key.insecure"),
|
||||
CertFile: testutils.MustAbsPath("../fixtures/server-serverusage.crt"),
|
||||
ClientKeyFile: testutils.MustAbsPath("../fixtures/client-clientusage.key.insecure"),
|
||||
ClientCertFile: testutils.MustAbsPath("../fixtures/client-clientusage.crt"),
|
||||
TrustedCAFile: testutils.MustAbsPath("../fixtures/ca.crt"),
|
||||
ClientCertAuth: true,
|
||||
}
|
||||
|
||||
TestTLSInfoIP = transport.TLSInfo{
|
||||
KeyFile: MustAbsPath("../fixtures/server-ip.key.insecure"),
|
||||
CertFile: MustAbsPath("../fixtures/server-ip.crt"),
|
||||
TrustedCAFile: MustAbsPath("../fixtures/ca.crt"),
|
||||
KeyFile: testutils.MustAbsPath("../fixtures/server-ip.key.insecure"),
|
||||
CertFile: testutils.MustAbsPath("../fixtures/server-ip.crt"),
|
||||
TrustedCAFile: testutils.MustAbsPath("../fixtures/ca.crt"),
|
||||
ClientCertAuth: true,
|
||||
}
|
||||
|
||||
TestTLSInfoExpired = transport.TLSInfo{
|
||||
KeyFile: MustAbsPath("./fixtures-expired/server.key.insecure"),
|
||||
CertFile: MustAbsPath("./fixtures-expired/server.crt"),
|
||||
TrustedCAFile: MustAbsPath("./fixtures-expired/ca.crt"),
|
||||
KeyFile: testutils.MustAbsPath("./fixtures-expired/server.key.insecure"),
|
||||
CertFile: testutils.MustAbsPath("./fixtures-expired/server.crt"),
|
||||
TrustedCAFile: testutils.MustAbsPath("./fixtures-expired/ca.crt"),
|
||||
ClientCertAuth: true,
|
||||
}
|
||||
|
||||
TestTLSInfoExpiredIP = transport.TLSInfo{
|
||||
KeyFile: MustAbsPath("./fixtures-expired/server-ip.key.insecure"),
|
||||
CertFile: MustAbsPath("./fixtures-expired/server-ip.crt"),
|
||||
TrustedCAFile: MustAbsPath("./fixtures-expired/ca.crt"),
|
||||
KeyFile: testutils.MustAbsPath("./fixtures-expired/server-ip.key.insecure"),
|
||||
CertFile: testutils.MustAbsPath("./fixtures-expired/server-ip.crt"),
|
||||
TrustedCAFile: testutils.MustAbsPath("./fixtures-expired/ca.crt"),
|
||||
ClientCertAuth: true,
|
||||
}
|
||||
|
||||
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
|
||||
// Should only be accessed via atomic package methods.
|
||||
|
@ -16,7 +16,6 @@ package integration
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
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 {
|
||||
cfg := embed.NewConfig()
|
||||
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/v3"
|
||||
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"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var (
|
||||
testTLSInfo = transport.TLSInfo{
|
||||
KeyFile: integration2.MustAbsPath("../../../fixtures/server.key.insecure"),
|
||||
CertFile: integration2.MustAbsPath("../../../fixtures/server.crt"),
|
||||
TrustedCAFile: integration2.MustAbsPath("../../../fixtures/ca.crt"),
|
||||
KeyFile: testutils.MustAbsPath("../../../fixtures/server.key.insecure"),
|
||||
CertFile: testutils.MustAbsPath("../../../fixtures/server.crt"),
|
||||
TrustedCAFile: testutils.MustAbsPath("../../../fixtures/ca.crt"),
|
||||
ClientCertAuth: true,
|
||||
}
|
||||
|
||||
testTLSInfoExpired = transport.TLSInfo{
|
||||
KeyFile: integration2.MustAbsPath("../../fixtures-expired/server.key.insecure"),
|
||||
CertFile: integration2.MustAbsPath("../../fixtures-expired/server.crt"),
|
||||
TrustedCAFile: integration2.MustAbsPath("../../fixtures-expired/ca.crt"),
|
||||
KeyFile: testutils.MustAbsPath("../../fixtures-expired/server.key.insecure"),
|
||||
CertFile: testutils.MustAbsPath("../../fixtures-expired/server.crt"),
|
||||
TrustedCAFile: testutils.MustAbsPath("../../fixtures-expired/ca.crt"),
|
||||
ClientCertAuth: true,
|
||||
}
|
||||
)
|
||||
|
@ -35,13 +35,14 @@ import (
|
||||
"go.etcd.io/etcd/client/v3"
|
||||
"go.etcd.io/etcd/server/v3/embed"
|
||||
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
|
||||
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
||||
)
|
||||
|
||||
var (
|
||||
testTLSInfo = transport.TLSInfo{
|
||||
KeyFile: integration2.MustAbsPath("../../fixtures/server.key.insecure"),
|
||||
CertFile: integration2.MustAbsPath("../../fixtures/server.crt"),
|
||||
TrustedCAFile: integration2.MustAbsPath("../../fixtures/ca.crt"),
|
||||
KeyFile: testutils.MustAbsPath("../../fixtures/server.key.insecure"),
|
||||
CertFile: testutils.MustAbsPath("../../fixtures/server.crt"),
|
||||
TrustedCAFile: testutils.MustAbsPath("../../fixtures/ca.crt"),
|
||||
ClientCertAuth: true,
|
||||
}
|
||||
)
|
||||
|
@ -29,6 +29,7 @@ import (
|
||||
"go.etcd.io/etcd/etcdutl/v3/snapshot"
|
||||
"go.etcd.io/etcd/server/v3/embed"
|
||||
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/zaptest"
|
||||
)
|
||||
@ -138,7 +139,7 @@ func TestSnapshotV3RestoreMulti(t *testing.T) {
|
||||
|
||||
// TestCorruptedBackupFileCheck tests if we can correctly identify a corrupted backup file.
|
||||
func TestCorruptedBackupFileCheck(t *testing.T) {
|
||||
dbPath := integration2.MustAbsPath("testdata/corrupted_backup.db")
|
||||
dbPath := testutils.MustAbsPath("testdata/corrupted_backup.db")
|
||||
integration2.BeforeTest(t)
|
||||
if _, err := os.Stat(dbPath); err != nil {
|
||||
t.Fatalf("test file [%s] does not exist: %v", dbPath, err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user