Merge pull request #40793 from roman-mazur/upstream-moby/fix-tests

pkg/authorization: Fix test failures on macOS
This commit is contained in:
Brian Goff 2020-04-09 11:48:24 -07:00 committed by GitHub
commit 36e80cb13b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 13 deletions

View file

@ -32,7 +32,7 @@ func TestAuthZRequestPluginError(t *testing.T) {
server.start()
defer server.stop()
authZPlugin := createTestPlugin(t)
authZPlugin := createTestPlugin(t, server.socketAddress())
request := Request{
User: "user",
@ -63,7 +63,7 @@ func TestAuthZRequestPlugin(t *testing.T) {
server.start()
defer server.stop()
authZPlugin := createTestPlugin(t)
authZPlugin := createTestPlugin(t, server.socketAddress())
request := Request{
User: "user",
@ -95,7 +95,7 @@ func TestAuthZResponsePlugin(t *testing.T) {
server.start()
defer server.stop()
authZPlugin := createTestPlugin(t)
authZPlugin := createTestPlugin(t, server.socketAddress())
request := Request{
User: "user",
@ -262,13 +262,8 @@ func TestResponseModifierOverride(t *testing.T) {
}
// createTestPlugin creates a new sample authorization plugin
func createTestPlugin(t *testing.T) *authorizationPlugin {
pwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
client, err := plugins.NewClient("unix:///"+path.Join(pwd, pluginAddress), &tlsconfig.Options{InsecureSkipVerify: true})
func createTestPlugin(t *testing.T, socketAddress string) *authorizationPlugin {
client, err := plugins.NewClient("unix:///"+socketAddress, &tlsconfig.Options{InsecureSkipVerify: true})
if err != nil {
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
replayResponse Response
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
func (t *authZPluginTestServer) start() {
var err error
t.tmpDir, err = ioutil.TempDir("", "authz")
if err != nil {
t.t.Fatal(err)
}
r := mux.NewRouter()
l, err := net.Listen("unix", pluginAddress)
l, err := net.Listen("unix", t.socketAddress())
if err != nil {
t.t.Fatal(err)
}
@ -311,7 +317,7 @@ func (t *authZPluginTestServer) start() {
// stop stops the test server that implements the plugin
func (t *authZPluginTestServer) stop() {
t.server.Close()
os.Remove(pluginAddress)
_ = os.RemoveAll(t.tmpDir)
if t.listener != nil {
t.listener.Close()
}

View file

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