Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: logdog/client/butler/streamserver/namedPipe_posix_test.go

Issue 2737603003: Butler stream servers can generate client address. (Closed)
Patch Set: better comment Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 // +build darwin dragonfly freebsd linux netbsd openbsd
6
7 package streamserver
8
9 import (
10 "io/ioutil"
11 "os"
12 "path/filepath"
13 "strings"
14 "testing"
15
16 "github.com/luci/luci-go/logdog/client/butlerlib/streamclient"
17
18 "golang.org/x/net/context"
19
20 . "github.com/luci/luci-go/common/testing/assertions"
21 . "github.com/smartystreets/goconvey/convey"
22 )
23
24 func withTempDir(t *testing.T, fn func(string)) func() {
25 return func() {
26 tdir, err := ioutil.TempDir("", "butler_test")
27 if err != nil {
28 t.Fatalf("failed to create temporary directory: %s", err )
29 }
30 defer func() {
31 if err := os.RemoveAll(tdir); err != nil {
32 t.Errorf("failed to clean up temporary directory [%s]: %s", tdir, err)
33 }
34 }()
35 fn(tdir)
36 }
37 }
38
39 func TestUNIXDomainSocketServer(t *testing.T) {
40 t.Parallel()
41
42 Convey(`A UNIX domain socket server`, t, func() {
43 ctx := context.Background()
44
45 Convey(`Will refuse to create if there is an empty path.`, func( ) {
46 _, err := NewUNIXDomainSocketServer(ctx, "")
47 So(err, ShouldErrLike, "cannot have empty path")
48 })
49
50 Convey(`Will refuse to create if longer than maximum length.`, f unc() {
51 _, err := NewUNIXDomainSocketServer(ctx, strings.Repeat( "A", maxPOSIXNamedSocketLength+1))
52 So(err, ShouldErrLike, "path exceeds maximum length")
53 })
54
55 Convey(`When created and listening.`, withTempDir(t, func(tdir s tring) {
56 svr, err := NewUNIXDomainSocketServer(ctx, filepath.Join (tdir, "butler.sock"))
57 So(err, ShouldBeNil)
58
59 So(svr.Listen(), ShouldBeNil)
60 defer svr.Close()
61
62 client, err := streamclient.New(svr.Address())
63 So(err, ShouldBeNil)
64
65 testClientServer(t, svr, client)
66 }))
67 })
68 }
OLDNEW
« no previous file with comments | « logdog/client/butler/streamserver/namedPipe_posix.go ('k') | logdog/client/butler/streamserver/namedPipe_windows.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698