mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #13872 from ptabor/20220402-osx-unit-test-pass
Fix TestauthTokenBundleOnOverwrite on OsX:
This commit is contained in:
commit
f85cd0296f
40
client/pkg/testutil/before.go
Normal file
40
client/pkg/testutil/before.go
Normal file
@ -0,0 +1,40 @@
|
||||
// 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 testutil
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// These are constants from "go.etcd.io/etcd/server/v3/verify",
|
||||
// but we don't want to take dependency.
|
||||
const ENV_VERIFY = "ETCD_VERIFY"
|
||||
const ENV_VERIFY_ALL_VALUE = "all"
|
||||
|
||||
func BeforeTest(t testing.TB) {
|
||||
RegisterLeakDetection(t)
|
||||
os.Setenv(ENV_VERIFY, ENV_VERIFY_ALL_VALUE)
|
||||
|
||||
path, err := os.Getwd()
|
||||
assert.NoError(t, err)
|
||||
tempDir := t.TempDir()
|
||||
assert.NoError(t, os.Chdir(tempDir))
|
||||
t.Logf("Changing working directory to: %s", tempDir)
|
||||
|
||||
t.Cleanup(func() { assert.NoError(t, os.Chdir(path)) })
|
||||
}
|
@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -204,8 +203,13 @@ func TestZapWithLogger(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuthTokenBundleNoOverwrite(t *testing.T) {
|
||||
// This call in particular changes working directory to the tmp dir of
|
||||
// the test. The `etcd-auth-test:0` can be created in local directory,
|
||||
// not exceeding the longest allowed path on OsX.
|
||||
testutil.BeforeTest(t)
|
||||
|
||||
// Create a mock AuthServer to handle Authenticate RPCs.
|
||||
lis, err := net.Listen("unix", filepath.Join(t.TempDir(), "etcd-auth-test:0"))
|
||||
lis, err := net.Listen("unix", "etcd-auth-test:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -15,24 +15,12 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.etcd.io/etcd/client/pkg/v3/testutil"
|
||||
"go.etcd.io/etcd/server/v3/verify"
|
||||
)
|
||||
|
||||
func BeforeTest(t testing.TB) {
|
||||
SkipInShortMode(t)
|
||||
testutil.RegisterLeakDetection(t)
|
||||
os.Setenv(verify.ENV_VERIFY, verify.ENV_VERIFY_ALL_VALUE)
|
||||
|
||||
path, err := os.Getwd()
|
||||
assert.NoError(t, err)
|
||||
tempDir := t.TempDir()
|
||||
assert.NoError(t, os.Chdir(tempDir))
|
||||
t.Logf("Changing working directory to: %s", tempDir)
|
||||
|
||||
t.Cleanup(func() { assert.NoError(t, os.Chdir(path)) })
|
||||
testutil.BeforeTest(t)
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
package clientv3_test
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
@ -44,6 +45,16 @@ func forUnitTestsRunInMockedContext(mocking func(), example func()) {
|
||||
// TestMain sets up an etcd cluster if running the examples.
|
||||
func TestMain(m *testing.M) {
|
||||
testutil.ExitInShortMode("Skipping: the tests require real cluster")
|
||||
|
||||
tempDir := os.TempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
err := os.Chdir(tempDir)
|
||||
if err != nil {
|
||||
log.Printf("Failed to change working dir to: %s: %v", tempDir, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
v := m.Run()
|
||||
lazyCluster.Terminate()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user