1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

pkg/authorization: Fix test failures on macOS

On macOS, unit tests were failing with

root@c4101a75c792:/go/src/github.com/docker/docker/pkg/authorization# go test .
--- FAIL: TestAuthZRequestPluginError (0.00s)
    authz_unix_test.go:295: listen unix authz-test-plugin.sock: bind: file name too long
--- FAIL: TestAuthZRequestPlugin (0.00s)
    authz_unix_test.go:295: listen unix authz-test-plugin.sock: bind: file name too long
--- FAIL: TestAuthZResponsePlugin (0.00s)
    authz_unix_test.go:295: listen unix authz-test-plugin.sock: bind: file name too long
time="2020-04-07T10:07:04Z" level=warning msg="Request body is larger than: '1048576' skipping body"
--- FAIL: TestMiddlewareWrapHandler (0.00s)
    authz_unix_test.go:295: listen unix authz-test-plugin.sock: bind: file name too long
FAIL
FAIL	github.com/docker/docker/pkg/authorization	0.120s

This change moves the socket creation from a working test directory to a tmp directory,
so the path is shorter.

Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
This commit is contained in:
Roman Mazur 2020-04-07 13:05:25 +03:00
parent a6a47d1a49
commit f2c432636b
No known key found for this signature in database
GPG key ID: 9459886EFE6EE2F6
2 changed files with 19 additions and 13 deletions

View file

@ -32,7 +32,7 @@ func TestAuthZRequestPluginError(t *testing.T) {
server.start() server.start()
defer server.stop() defer server.stop()
authZPlugin := createTestPlugin(t) authZPlugin := createTestPlugin(t, server.socketAddress())
request := Request{ request := Request{
User: "user", User: "user",
@ -63,7 +63,7 @@ func TestAuthZRequestPlugin(t *testing.T) {
server.start() server.start()
defer server.stop() defer server.stop()
authZPlugin := createTestPlugin(t) authZPlugin := createTestPlugin(t, server.socketAddress())
request := Request{ request := Request{
User: "user", User: "user",
@ -95,7 +95,7 @@ func TestAuthZResponsePlugin(t *testing.T) {
server.start() server.start()
defer server.stop() defer server.stop()
authZPlugin := createTestPlugin(t) authZPlugin := createTestPlugin(t, server.socketAddress())
request := Request{ request := Request{
User: "user", User: "user",
@ -262,13 +262,8 @@ func TestResponseModifierOverride(t *testing.T) {
} }
// createTestPlugin creates a new sample authorization plugin // createTestPlugin creates a new sample authorization plugin
func createTestPlugin(t *testing.T) *authorizationPlugin { func createTestPlugin(t *testing.T, socketAddress string) *authorizationPlugin {
pwd, err := os.Getwd() client, err := plugins.NewClient("unix:///"+socketAddress, &tlsconfig.Options{InsecureSkipVerify: true})
if err != nil {
t.Fatal(err)
}
client, err := plugins.NewClient("unix:///"+path.Join(pwd, pluginAddress), &tlsconfig.Options{InsecureSkipVerify: true})
if err != nil { if err != nil {
t.Fatalf("Failed to create client %v", err) t.Fatalf("Failed to create client %v", err)
} }
@ -285,12 +280,23 @@ type authZPluginTestServer struct {
// response stores the response sent from the plugin to the daemon // response stores the response sent from the plugin to the daemon
replayResponse Response replayResponse Response
server *httptest.Server server *httptest.Server
tmpDir string
}
func (t *authZPluginTestServer) socketAddress() string {
return path.Join(t.tmpDir, pluginAddress)
} }
// start starts the test server that implements the plugin // start starts the test server that implements the plugin
func (t *authZPluginTestServer) start() { func (t *authZPluginTestServer) start() {
var err error
t.tmpDir, err = ioutil.TempDir("", "authz")
if err != nil {
t.t.Fatal(err)
}
r := mux.NewRouter() r := mux.NewRouter()
l, err := net.Listen("unix", pluginAddress) l, err := net.Listen("unix", t.socketAddress())
if err != nil { if err != nil {
t.t.Fatal(err) t.t.Fatal(err)
} }
@ -311,7 +317,7 @@ func (t *authZPluginTestServer) start() {
// stop stops the test server that implements the plugin // stop stops the test server that implements the plugin
func (t *authZPluginTestServer) stop() { func (t *authZPluginTestServer) stop() {
t.server.Close() t.server.Close()
os.Remove(pluginAddress) _ = os.RemoveAll(t.tmpDir)
if t.listener != nil { if t.listener != nil {
t.listener.Close() t.listener.Close()
} }

View file

@ -18,7 +18,7 @@ func TestMiddlewareWrapHandler(t *testing.T) {
server.start() server.start()
defer server.stop() defer server.stop()
authZPlugin := createTestPlugin(t) authZPlugin := createTestPlugin(t, server.socketAddress())
pluginNames := []string{authZPlugin.name} pluginNames := []string{authZPlugin.name}
var pluginGetter plugingetter.PluginGetter var pluginGetter plugingetter.PluginGetter