MCPcopy Index your code
hub / github.com/koding/kite / TestMethod_Error

Function TestMethod_Error

method_test.go:134–168  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func TestMethod_Error(t *testing.T) {
135 k := New("testkite", "0.0.1")
136 k.Config.DisableAuthentication = true
137 k.Config.Port = 9999
138
139 var testError = errors.New("an error")
140
141 k.PreHandleFunc(func(r *Request) (interface{}, error) { return nil, testError })
142
143 // the following shouldn't do anything because the previous error breaks the chain
144 k.HandleFunc("foo", func(r *Request) (interface{}, error) {
145 return "handle", nil
146 })
147
148 k.PostHandleFunc(func(r *Request) (interface{}, error) { return "post1", nil })
149 k.PostHandleFunc(func(r *Request) (interface{}, error) { return "post2", nil })
150
151 go k.Run()
152 defer k.Close()
153 <-k.ServerReadyNotify()
154
155 c := New("exp", "0.0.1").NewClient("http://127.0.0.1:9999/kite")
156 if err := c.Dial(); err != nil {
157 t.Fatal(err)
158 }
159
160 _, err := c.TellWithTimeout("foo", 4*time.Second)
161 if err == nil {
162 t.Fatal("PreHandle returns an error, however error is non-nil.")
163 }
164
165 if !strings.HasPrefix(err.Error(), testError.Error()) {
166 t.Errorf("Error should be '%v', got '%v'", testError, err)
167 }
168}
169
170func TestMethod_Base(t *testing.T) {
171 k := New("testkite", "0.0.1")

Callers

nothing calls this directly

Calls 12

DialMethod · 0.95
TellWithTimeoutMethod · 0.95
HandleFuncMethod · 0.80
ServerReadyNotifyMethod · 0.80
NewClientMethod · 0.80
FatalMethod · 0.80
NewFunction · 0.70
ErrorMethod · 0.65
PreHandleFuncMethod · 0.45
PostHandleFuncMethod · 0.45
RunMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected