From d53d97aba080d4d471039fd0d8e280d606c779f2 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sat, 13 Jul 2019 14:06:13 +0100 Subject: [PATCH] dovecot: Test autodetection works with closed sockets We want to test that autodetection works with closed sockets, as we explicitly support that scenario: chasquid might be up before dovecot is, and we still want the detection to work. The code is written that way, but we had no tests for it until now, because we were blocked on the unix listeners supporting SetUnlinkOnClose, which appeared in Go 1.8. Now that the minimum Go version has been raised past that, we can implement the test. --- internal/dovecot/dovecot_test.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/internal/dovecot/dovecot_test.go b/internal/dovecot/dovecot_test.go index 0fc044d..2e71dd5 100644 --- a/internal/dovecot/dovecot_test.go +++ b/internal/dovecot/dovecot_test.go @@ -73,12 +73,22 @@ func TestAutodetect(t *testing.T) { userdb, client, a.userdbAddr, a.clientAddr) } - // TODO: Close the two sockets, and re-do the test from above: Autodetect - // should work fine against closed sockets. - // To implement this test, we should call SetUnlinkOnClose, but - // unfortunately that is only available in Go >= 1.8. - // We want to support Go 1.7 for a while as it is in Debian stable; once - // Debian stable moves on, we can implement this test easily. + // Close the two sockets, and re-do the test from above: Autodetect should + // work fine against closed sockets. + // We need to tell Go to keep the socket files around explicitly, as the + // default is to delete them since they were creeated by the net library. + uL.SetUnlinkOnClose(false) + uL.Close() + cL.SetUnlinkOnClose(false) + cL.Close() + + a = Autodetect("", "") + if a == nil { + t.Errorf("Autodetection failed (closed sockets)") + } else if a.userdbAddr != userdb || a.clientAddr != client { + t.Errorf("Expected autodetect to pick {%q, %q}, but got {%q, %q}", + userdb, client, a.userdbAddr, a.clientAddr) + } // Autodetect should pick the suggestions passed as parameters (if // possible). @@ -91,9 +101,6 @@ func TestAutodetect(t *testing.T) { t.Errorf("Expected autodetect to pick {%q, %q}, but got {%q, %q}", userdb, client, a.userdbAddr, a.clientAddr) } - - uL.Close() - cL.Close() } func TestReload(t *testing.T) {