-
Notifications
You must be signed in to change notification settings - Fork 565
/
client_windows_test.go
42 lines (36 loc) · 1.1 KB
/
client_windows_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2016 go-dockerclient authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package docker
import (
"fmt"
"net/http"
"net/http/httptest"
"sync"
winio "github.com/Microsoft/go-winio"
)
const (
nativeProtocol = namedPipeProtocol
nativeRealEndpoint = "npipe:////./pipe/docker_engine"
nativeBadEndpoint = "npipe:////./pipe/godockerclient_test_echo"
)
var (
// namedPipeCount is used to provide uniqueness in the named pipes generated
// by newNativeServer
namedPipeCount int
// namedPipesAllocateLock protects namedPipeCount
namedPipeAllocateLock sync.Mutex
)
func newNativeServer(handler http.Handler) (*httptest.Server, func(), error) {
namedPipeAllocateLock.Lock()
defer namedPipeAllocateLock.Unlock()
pipeName := fmt.Sprintf("//./pipe/godockerclient_test_%d", namedPipeCount)
namedPipeCount++
l, err := winio.ListenPipe(pipeName, &winio.PipeConfig{MessageMode: true})
if err != nil {
return nil, nil, err
}
srv := httptest.NewUnstartedServer(handler)
srv.Listener = l
return srv, func() {}, nil
}