diff --git a/tests/framework/e2e/etcd_spawn_cov.go b/tests/framework/e2e/etcd_spawn_cov.go index f8cdd194f..97102f08f 100644 --- a/tests/framework/e2e/etcd_spawn_cov.go +++ b/tests/framework/e2e/etcd_spawn_cov.go @@ -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) { diff --git a/tests/framework/e2e/flags.go b/tests/framework/e2e/flags.go index ce6d6dea6..a8607830c 100644 --- a/tests/framework/e2e/flags.go +++ b/tests/framework/e2e/flags.go @@ -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.") diff --git a/tests/framework/integration/cluster.go b/tests/framework/integration/cluster.go index 755941f41..f7c0e91a1 100644 --- a/tests/framework/integration/cluster.go +++ b/tests/framework/integration/cluster.go @@ -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. diff --git a/tests/framework/integration/testing.go b/tests/framework/integration/testing.go index 4c5c76c3e..e6d3e9016 100644 --- a/tests/framework/integration/testing.go +++ b/tests/framework/integration/testing.go @@ -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 diff --git a/tests/framework/testutils/path.go b/tests/framework/testutils/path.go new file mode 100644 index 000000000..3b9e65213 --- /dev/null +++ b/tests/framework/testutils/path.go @@ -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 +} diff --git a/tests/integration/clientv3/connectivity/dial_test.go b/tests/integration/clientv3/connectivity/dial_test.go index 7f6babe04..d6284d409 100644 --- a/tests/integration/clientv3/connectivity/dial_test.go +++ b/tests/integration/clientv3/connectivity/dial_test.go @@ -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, } ) diff --git a/tests/integration/embed/embed_test.go b/tests/integration/embed/embed_test.go index 3733684d2..6f4fb3d1b 100644 --- a/tests/integration/embed/embed_test.go +++ b/tests/integration/embed/embed_test.go @@ -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, } ) diff --git a/tests/integration/snapshot/v3_snapshot_test.go b/tests/integration/snapshot/v3_snapshot_test.go index ace338876..2198b8f57 100644 --- a/tests/integration/snapshot/v3_snapshot_test.go +++ b/tests/integration/snapshot/v3_snapshot_test.go @@ -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)