func TestLoggedHandlers(t *testing.T) { expectedHandlers := []string{"name1", "name2"} l := request.HandlerList{} loggedHandlers := []string{} l.AfterEachFn = request.HandlerListLogItem cfg := aws.Config{Logger: aws.LoggerFunc(func(args ...interface{}) { loggedHandlers = append(loggedHandlers, args[2].(string)) })} named1 := request.NamedHandler{Name: "name1", Fn: func(r *request.Request) {}} named2 := request.NamedHandler{Name: "name2", Fn: func(r *request.Request) {}} l.PushBackNamed(named1) l.PushBackNamed(named2) l.Run(&request.Request{Config: cfg}) assert.Equal(t, expectedHandlers, loggedHandlers) }
func TestStopHandlers(t *testing.T) { l := request.HandlerList{} stopAt := 1 l.AfterEachFn = func(item request.HandlerListRunItem) bool { return item.Index != stopAt } called := 0 l.PushBackNamed(request.NamedHandler{Name: "name1", Fn: func(r *request.Request) { called++ }}) l.PushBackNamed(request.NamedHandler{Name: "name2", Fn: func(r *request.Request) { called++ }}) l.PushBackNamed(request.NamedHandler{Name: "name3", Fn: func(r *request.Request) { assert.Fail(t, "third handler should not be called") }}) l.Run(&request.Request{}) assert.Equal(t, 2, called, "Expect only two handlers to be called") }