mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Fix TestauthTokenBundleOnOverwrite on OsX:
``` % (cd client/v3 && env go test -short -timeout=3m --race ./...) --- FAIL: TestAuthTokenBundleNoOverwrite (0.00s) client_test.go:210: listen unix /var/folders/t1/3m8z9xz93t9c3vpt7zyzjm6w00374n/T/TestAuthTokenBundleNoOverwrite3197524989/001/etcd-auth-test:0: bind: invalid argument FAIL FAIL go.etcd.io/etcd/client/v3 4.270s ``` The reason was that the path exceeded 108 chars (that is too much for socket). In the mitigation we first change chroot (working directory) to the tempDir... such the path is 'local'.
This commit is contained in:
parent
e4d34f21bc
commit
3b589fb3b2
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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user