MCPcopy Create free account
hub / github.com/docker/go-plugins-helpers / TestHandler

Function TestHandler

volume/api_test.go:14–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestHandler(t *testing.T) {
15 p := &testPlugin{}
16 h := NewHandler(p)
17 l := sockets.NewInmemSocket("test", 0)
18 go h.Serve(l)
19 defer l.Close()
20
21 client := &http.Client{Transport: &http.Transport{
22 Dial: l.Dial,
23 }}
24
25 // Create
26 _, err := pluginRequest(client, createPath, &CreateRequest{Name: "foo"})
27 if err != nil {
28 t.Fatal(err)
29 }
30 if p.create != 1 {
31 t.Fatalf("expected create 1, got %d", p.create)
32 }
33
34 // Get
35 resp, err := pluginRequest(client, getPath, &GetRequest{Name: "foo"})
36 if err != nil {
37 t.Fatal(err)
38 }
39 var gResp *GetResponse
40 if err := json.NewDecoder(resp).Decode(&gResp); err != nil {
41 t.Fatal(err)
42 }
43 if gResp.Volume.Name != "foo" {
44 t.Fatalf("expected volume `foo`, got %v", gResp.Volume)
45 }
46 if p.get != 1 {
47 t.Fatalf("expected get 1, got %d", p.get)
48 }
49
50 // List
51 resp, err = pluginRequest(client, listPath, nil)
52 if err != nil {
53 t.Fatal(err)
54 }
55 var lResp *ListResponse
56 if err := json.NewDecoder(resp).Decode(&lResp); err != nil {
57 t.Fatal(err)
58 }
59 if len(lResp.Volumes) != 1 {
60 t.Fatalf("expected 1 volume, got %v", lResp.Volumes)
61 }
62 if lResp.Volumes[0].Name != "foo" {
63 t.Fatalf("expected volume `foo`, got %v", lResp.Volumes[0])
64 }
65 if p.list != 1 {
66 t.Fatalf("expected list 1, got %d", p.list)
67 }
68
69 // Path
70 if _, err := pluginRequest(client, hostVirtualPath, &PathRequest{Name: "foo"}); err != nil {
71 t.Fatal(err)

Callers

nothing calls this directly

Calls 3

ServeMethod · 0.95
NewHandlerFunction · 0.70
pluginRequestFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…