-
-
Save anonymous/7595f6db11d7202cb3fa12e64a862c61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"net" | |
"os" | |
"path/filepath" | |
) | |
func test(tmp string) error { | |
sockFile := filepath.Join(tmp, "unix.sock") | |
l, err := net.Listen("unix", sockFile) | |
if err != nil { | |
return err | |
} | |
// check that there is sock file after listen | |
if _, err := os.Stat(sockFile); err != nil { | |
return fmt.Errorf("file %s is not found", sockFile) | |
} | |
if err := l.Close(); err != nil { | |
return fmt.Errorf("first close %v", err) | |
} | |
// check that there is no sock file after close | |
if _, err := os.Stat(sockFile); err == nil { | |
return fmt.Errorf("file %s is found", sockFile) | |
} | |
l2, err := net.Listen("unix", sockFile) | |
if err != nil { | |
return err | |
} | |
defer l2.Close() | |
// close old listener again | |
l.Close() | |
// new unix-socket deleted | |
if _, err := os.Stat(sockFile); err != nil { | |
return fmt.Errorf("file %s is not found", sockFile) | |
} | |
return nil | |
} | |
func main() { | |
tmp, err := ioutil.TempDir("", "test-unix-sock-") | |
if err != nil { | |
panic(err) | |
} | |
defer os.RemoveAll(tmp) | |
if err := test(tmp); err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment