MCPcopy Index your code
hub / github.com/Shopify/toxiproxy / TestAddAndRemoveProxyFromCollection

Function TestAddAndRemoveProxyFromCollection

proxy_collection_test.go:80–120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func TestAddAndRemoveProxyFromCollection(t *testing.T) {
81 WithTCPProxy(t, func(conn net.Conn, response chan []byte, proxy *toxiproxy.Proxy) {
82 collection := toxiproxy.NewProxyCollection()
83
84 if _, err := collection.Get(proxy.Name); err == nil {
85 t.Error("Expected proxies to be empty")
86 }
87
88 err := collection.Add(proxy, false)
89 if err != nil {
90 t.Error("Expected to be able to add first proxy to collection")
91 }
92
93 if _, err := collection.Get(proxy.Name); err != nil {
94 t.Error("Expected proxy to be added to map")
95 }
96
97 msg := []byte("go away")
98
99 _, err = conn.Write(msg)
100 if err != nil {
101 t.Error("Failed writing to socket to shut down server")
102 }
103
104 conn.Close()
105
106 resp := <-response
107 if !bytes.Equal(resp, msg) {
108 t.Error("Server didn't read bytes from client")
109 }
110
111 err = collection.Remove(proxy.Name)
112 if err != nil {
113 t.Error("Expected to remove proxy from collection")
114 }
115
116 if _, err := collection.Get(proxy.Name); err == nil {
117 t.Error("Expected proxies to be empty")
118 }
119 })
120}

Callers

nothing calls this directly

Calls 7

GetMethod · 0.95
AddMethod · 0.95
RemoveMethod · 0.95
WithTCPProxyFunction · 0.85
WriteMethod · 0.80
ErrorMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…